Skip to content

Commit c863838

Browse files
committed
fix some warnings
1 parent ec0f78d commit c863838

File tree

4 files changed

+52
-66
lines changed

4 files changed

+52
-66
lines changed

hibernate-core/src/main/java/org/hibernate/graph/internal/AbstractGraph.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,21 @@ public <Y> AttributeNodeImplementor<Y> getAttributeNode(Attribute<? super J, Y>
112112

113113
@Override
114114
public void visitAttributeNodes(Consumer<AttributeNodeImplementor<?>> consumer) {
115-
if ( attrNodeMap == null ) {
116-
return;
115+
if ( attrNodeMap != null ) {
116+
attrNodeMap.forEach( (attribute, nodeImplementor) -> consumer.accept( nodeImplementor ) );
117117
}
118-
attrNodeMap.forEach( (persistentAttribute, attributeNodeImplementor) -> {
119-
consumer.accept( attributeNodeImplementor );
120-
} );
121118
}
122119

123120
@Override
124121
public List<AttributeNode<?>> getAttributeNodeList() {
125122
if ( attrNodeMap == null ) {
126123
return emptyList();
127124
}
128-
final List<AttributeNode<?>> result = new ArrayList<>();
129-
visitAttributeNodes( result::add );
130-
return result;
125+
else {
126+
final List<AttributeNode<?>> result = new ArrayList<>();
127+
visitAttributeNodes( result::add );
128+
return result;
129+
}
131130
}
132131

133132
@Override
@@ -209,8 +208,8 @@ public void addAttributeNodes(String... attributeNames) {
209208
}
210209
}
211210

212-
@Override
213-
public void addAttributeNodes(Attribute<? super J, ?>... attributes) {
211+
@Override @SafeVarargs
212+
public final void addAttributeNodes(Attribute<? super J, ?>... attributes) {
214213
for ( int i = 0; i < attributes.length; i++ ) {
215214
addAttributeNode( attributes[i] );
216215
}

hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,10 @@ public AbstractIdentifiableType(
7474
}
7575

7676
@Override
77-
protected InFlightAccessImpl createInFlightAccess() {
77+
protected InFlightAccess<J> createInFlightAccess() {
7878
return new InFlightAccessImpl( super.createInFlightAccess() );
7979
}
8080

81-
@Override
82-
public InFlightAccessImpl getInFlightAccess() {
83-
return (InFlightAccessImpl) super.getInFlightAccess();
84-
}
85-
8681
@Override
8782
public SqmPathSource<?> getIdentifierDescriptor() {
8883
return identifierDescriptor;

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public void processJpa(
599599
Collection<NamedEntityGraphDefinition> namedEntityGraphDefinitions,
600600
RuntimeModelCreationContext runtimeModelCreationContext) {
601601
bootMetamodel.getImports()
602-
.forEach( ( k, v ) -> this.nameToImportMap.put( k, new ImportInfo<>( v, null ) ) );
602+
.forEach( (key, value) -> this.nameToImportMap.put( key, new ImportInfo<>( value, null ) ) );
603603
this.entityProxyInterfaceMap.putAll( entityProxyInterfaceMap );
604604

605605
final MetadataContext context = new MetadataContext(

0 commit comments

Comments
 (0)