Skip to content

Commit

Permalink
TypeDetails Object should be resolved if type Kind is CLASS
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 authored and sebersole committed Mar 25, 2024
1 parent 0c9041d commit 38bbaef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
23 changes: 23 additions & 0 deletions src/main/java/org/hibernate/models/internal/IsBoundTypeSwitch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* SPDX-License-Identifier: Apache-2.0
* Copyright: Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.models.internal;

import java.util.Objects;

import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassTypeDetails;
import org.hibernate.models.spi.SourceModelBuildingContext;

public class IsBoundTypeSwitch extends IsResolvedTypeSwitch{
public static final IsBoundTypeSwitch IS_BOUND_SWITCH = new IsBoundTypeSwitch();

@Override
public Boolean caseClass(ClassTypeDetails classType, SourceModelBuildingContext buildingContext) {
// not completely kosher, but works for our needs
return !Objects.equals( classType.getClassDetails(), ClassDetails.OBJECT_CLASS_DETAILS );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.hibernate.models.spi.VoidTypeDetails;
import org.hibernate.models.spi.WildcardTypeDetails;

import static org.hibernate.models.internal.IsBoundTypeSwitch.IS_BOUND_SWITCH;

/**
* TypeDetailsSwitch implementation checking whether a type is resolved (all of its bounds are known)
*
Expand All @@ -31,17 +33,12 @@
public class IsResolvedTypeSwitch implements TypeDetailsSwitch<Boolean> {
public static final IsResolvedTypeSwitch IS_RESOLVED_SWITCH = new IsResolvedTypeSwitch();

public static boolean isBound(TypeDetails typeDetails, SourceModelBuildingContext buildingContext) {
return TypeDetailsSwitch.switchType( typeDetails, IS_RESOLVED_SWITCH, buildingContext );
private static boolean isBound(TypeDetails typeDetails, SourceModelBuildingContext buildingContext) {
return TypeDetailsSwitch.switchType( typeDetails, IS_BOUND_SWITCH, buildingContext );
}

@Override
public Boolean caseClass(ClassTypeDetails classType, SourceModelBuildingContext buildingContext) {
// not completely kosher, but works for our needs
//noinspection RedundantIfStatement
if ( Objects.equals( classType.getClassDetails(), ClassDetails.OBJECT_CLASS_DETAILS ) ) {
return false;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void testParameterizedHierarchy(Index index) {
assertThat( bound.asClassType().getClassDetails().toJavaClass() ).isEqualTo( Object.class );

final ClassBasedTypeDetails resolvedClassType = idField.resolveRelativeClassType( rootClassDetails );
assertThat( idField.getType().isResolved() ).isFalse();
assertThat( resolvedClassType.getClassDetails().toJavaClass() ).isEqualTo( Object.class );
assertThat( resolvedClassType.isResolved() ).isFalse();
}

{
Expand Down

0 comments on commit 38bbaef

Please sign in to comment.