@@ -231,16 +231,12 @@ private <Y> DomainType<Y> determineSimpleType(ValueContext typeContext) {
231231 }
232232
233233 public static <Y > DomainType <Y > determineSimpleType (ValueContext typeContext , MetadataContext context ) {
234- switch ( typeContext .getValueClassification () ) {
235- case BASIC :
236- return basicDomainType ( typeContext , context );
237- case ENTITY :
238- return entityDomainType ( typeContext , context );
239- case EMBEDDABLE :
240- return embeddableDomainType ( typeContext , context );
241- default :
242- throw new AssertionFailure ( "Unknown type : " + typeContext .getValueClassification () );
243- }
234+ return switch ( typeContext .getValueClassification () ) {
235+ case BASIC -> basicDomainType ( typeContext , context );
236+ case ENTITY -> entityDomainType (typeContext , context );
237+ case EMBEDDABLE -> embeddableDomainType ( typeContext , context );
238+ default -> throw new AssertionFailure ( "Unknown type : " + typeContext .getValueClassification () );
239+ };
244240 }
245241
246242 private static <Y > EmbeddableDomainType <Y > embeddableDomainType (ValueContext typeContext , MetadataContext context ) {
@@ -339,8 +335,7 @@ private static <Y> EmbeddableTypeImpl<Y> dynamicEmbeddableType(MetadataContext c
339335
340336 private static <Y > DomainType <Y > entityDomainType (ValueContext typeContext , MetadataContext context ) {
341337 final org .hibernate .type .Type type = typeContext .getHibernateValue ().getType ();
342- if ( type instanceof EntityType ) {
343- final EntityType entityType = (EntityType ) type ;
338+ if ( type instanceof EntityType entityType ) {
344339 final IdentifiableDomainType <Y > domainType =
345340 context .locateIdentifiableType ( entityType .getAssociatedEntityName () );
346341 if ( domainType == null ) {
@@ -378,11 +373,11 @@ private static <Y> DomainType<Y> basicDomainType(ValueContext typeContext, Metad
378373 }
379374 else {
380375 final org .hibernate .type .Type type = hibernateValue .getType ();
381- if ( type instanceof BasicPluralType <?, ?> ) {
382- final JavaType <?> javaTypeDescriptor = ( ( BasicPluralType <?, ?>) type ). getElementType ()
383- . getJavaTypeDescriptor ();
384- if ( javaTypeDescriptor instanceof EmbeddableAggregateJavaType <?> ) {
385- final AggregateColumn aggregateColumn = (AggregateColumn ) hibernateValue .getColumns ().get ( 0 );
376+ if ( type instanceof BasicPluralType <?, ?> pluralType ) {
377+ if ( pluralType . getElementType (). getJavaTypeDescriptor ()
378+ instanceof EmbeddableAggregateJavaType <?> ) {
379+ final AggregateColumn aggregateColumn =
380+ (AggregateColumn ) hibernateValue .getColumns ().get ( 0 );
386381 classEmbeddableType ( context , aggregateColumn .getComponent () );
387382 }
388383 }
@@ -483,18 +478,15 @@ else if ( type instanceof EntityType ) {
483478 }
484479 else if ( type instanceof CollectionType ) {
485480 // collection
486- if ( value instanceof Collection ) {
487- final Collection collValue = (Collection ) value ;
488- final Value elementValue = collValue .getElement ();
489- final org .hibernate .type .Type elementType = elementValue .getType ();
481+ if ( value instanceof Collection collection ) {
482+ final org .hibernate .type .Type elementType = collection .getElement ().getType ();
490483 final boolean isManyToMany = isManyToMany ( member );
491-
492484 return new PluralAttributeMetadataImpl <>(
493485 propertyMapping ,
494486 attributeContext .getOwnerType (),
495487 member ,
496- collectionClassification ( elementType , elementValue , isManyToMany ),
497- elementClassification ( elementType , elementValue , isManyToMany ),
488+ collectionClassification ( elementType , isManyToMany ),
489+ elementClassification ( elementType , isManyToMany ),
498490 indexClassification ( value ),
499491 context
500492 );
@@ -544,9 +536,8 @@ else if ( type instanceof ComponentType ) {
544536 }
545537
546538 private static AttributeClassification indexClassification (Value value ) {
547- if ( value instanceof Map ) {
548- final Value keyValue = ( (Map ) value ).getIndex ();
549- return keyClassification ( keyValue .getType (), keyValue );
539+ if ( value instanceof Map map ) {
540+ return keyClassification ( map .getIndex ().getType () );
550541 }
551542 else if ( value instanceof List ) {
552543 return AttributeClassification .BASIC ;
@@ -557,7 +548,7 @@ else if ( value instanceof List ) {
557548 }
558549
559550 private static AttributeClassification elementClassification (
560- org .hibernate .type .Type elementType , Value elementValue , boolean isManyToMany ) {
551+ org .hibernate .type .Type elementType , boolean isManyToMany ) {
561552 // First, determine the type of the elements and use that to help determine the
562553 // collection type
563554 if ( elementType instanceof AnyType ) {
@@ -577,7 +568,7 @@ else if ( elementType instanceof EntityType ) {
577568 }
578569
579570 private static AttributeClassification collectionClassification (
580- org .hibernate .type .Type elementType , Value elementValue , boolean isManyToMany ) {
571+ org .hibernate .type .Type elementType , boolean isManyToMany ) {
581572 if ( elementType instanceof EntityType ) {
582573 return isManyToMany ?
583574 AttributeClassification .MANY_TO_MANY :
@@ -588,7 +579,7 @@ private static AttributeClassification collectionClassification(
588579 }
589580 }
590581
591- private static AttributeClassification keyClassification (org .hibernate .type .Type keyType , Value keyValue ) {
582+ private static AttributeClassification keyClassification (org .hibernate .type .Type keyType ) {
592583 if ( keyType instanceof AnyType ) {
593584 return AttributeClassification .ANY ;
594585 }
@@ -604,47 +595,48 @@ else if ( keyType instanceof EntityType ) {
604595 }
605596
606597 public static AttributeClassification determineSingularAssociationClassification (Member member ) {
607- if ( member instanceof Field ) {
608- return ( ( Field ) member ) .getAnnotation ( OneToOne .class ) != null
598+ if ( member instanceof Field field ) {
599+ return field .getAnnotation ( OneToOne .class ) != null
609600 ? AttributeClassification .ONE_TO_ONE
610601 : AttributeClassification .MANY_TO_ONE ;
611602 }
612603 else if ( member instanceof MapMember ) {
613604 return AttributeClassification .MANY_TO_ONE ; // curious to see how this works for non-annotated methods
614605 }
615- else {
616- return ( ( Method ) member ) .getAnnotation ( OneToOne .class ) != null
606+ else if ( member instanceof Method method ) {
607+ return method .getAnnotation ( OneToOne .class ) != null
617608 ? AttributeClassification .ONE_TO_ONE
618609 : AttributeClassification .MANY_TO_ONE ;
619610 }
611+ else {
612+ throw new AssertionFailure ( "Unexpected member type" );
613+ }
620614 }
621615
622616 public static ParameterizedType getSignatureType (Member member ) {
623617 final java .lang .reflect .Type type ;
624- if ( member instanceof Field ) {
625- type = ( ( Field ) member ) .getGenericType ();
618+ if ( member instanceof Field field ) {
619+ type = field .getGenericType ();
626620 }
627- else if ( member instanceof Method ) {
628- type = ( ( Method ) member ) .getGenericReturnType ();
621+ else if ( member instanceof Method method ) {
622+ type = method .getGenericReturnType ();
629623 }
630- else {
631- type = ( (MapMember ) member ).getType ();
632- }
633- //this is a raw type
634- if ( type instanceof Class ) {
635- return null ;
624+ else if ( member instanceof MapMember mapMember ) {
625+ type = mapMember .getType ();
636626 }
637627 else {
638- return ( ParameterizedType ) type ;
628+ throw new AssertionFailure ( "Unexpected member type" ) ;
639629 }
630+ //this is a raw type
631+ return type instanceof Class ? null : (ParameterizedType ) type ;
640632 }
641633
642634 public static boolean isManyToMany (Member member ) {
643- if ( member instanceof Field ) {
644- return ( ( Field ) member ) .getAnnotation ( ManyToMany .class ) != null ;
635+ if ( member instanceof Field field ) {
636+ return field .getAnnotation ( ManyToMany .class ) != null ;
645637 }
646- else if ( member instanceof Method ) {
647- return ( ( Method ) member ) .getAnnotation ( ManyToMany .class ) != null ;
638+ else if ( member instanceof Method method ) {
639+ return method .getAnnotation ( ManyToMany .class ) != null ;
648640 }
649641 else {
650642 return false ;
0 commit comments