48
48
49
49
import static jakarta .persistence .AccessType .FIELD ;
50
50
import static java .util .Collections .emptyList ;
51
+ import static java .util .Objects .requireNonNull ;
51
52
import static org .hibernate .processor .util .StringUtil .classNameFromFullyQualifiedName ;
52
53
import static org .hibernate .processor .util .StringUtil .determineFullyQualifiedClassName ;
53
54
import static org .hibernate .processor .util .StringUtil .isFullyQualified ;
@@ -74,7 +75,7 @@ public class XmlMetaEntity implements Metamodel {
74
75
75
76
private @ Nullable JaxbAttributesContainerImpl attributes ;
76
77
private @ Nullable JaxbEmbeddableAttributesContainerImpl embeddableAttributes ;
77
- private AccessTypeInformation accessTypeInfo ;
78
+ private @ Nullable AccessTypeInformation accessTypeInfo ;
78
79
79
80
/**
80
81
* Whether the members of this type have already been initialized or not.
@@ -90,7 +91,7 @@ public class XmlMetaEntity implements Metamodel {
90
91
private boolean initialized ;
91
92
92
93
XmlMetaEntity (JaxbEntityImpl ormEntity , String defaultPackageName , TypeElement element , Context context ) {
93
- this ( ormEntity .getClazz (), defaultPackageName , element , context , ormEntity .isMetadataComplete () );
94
+ this ( requireNonNull ( ormEntity .getClazz () ), defaultPackageName , element , context , ormEntity .isMetadataComplete () );
94
95
this .attributes = ormEntity .getAttributes ();
95
96
this .embeddableAttributes = null ;
96
97
}
@@ -104,7 +105,7 @@ static XmlMetaEntity create(JaxbEntityImpl ormEntity, String defaultPackageName,
104
105
105
106
XmlMetaEntity (JaxbMappedSuperclassImpl mappedSuperclass , String defaultPackageName , TypeElement element , Context context ) {
106
107
this (
107
- mappedSuperclass .getClazz (),
108
+ requireNonNull ( mappedSuperclass .getClazz () ),
108
109
defaultPackageName ,
109
110
element ,
110
111
context ,
@@ -115,12 +116,12 @@ static XmlMetaEntity create(JaxbEntityImpl ormEntity, String defaultPackageName,
115
116
}
116
117
117
118
XmlMetaEntity (JaxbEmbeddableImpl embeddable , String defaultPackageName , TypeElement element , Context context ) {
118
- this ( embeddable .getClazz (), defaultPackageName , element , context , embeddable .isMetadataComplete () );
119
+ this ( requireNonNull ( embeddable .getClazz () ), defaultPackageName , element , context , embeddable .isMetadataComplete () );
119
120
this .attributes = null ;
120
121
this .embeddableAttributes = embeddable .getAttributes ();
121
122
}
122
123
123
- private XmlMetaEntity (String clazz , String defaultPackageName , TypeElement element , Context context , Boolean metaComplete ) {
124
+ private XmlMetaEntity (String clazz , String defaultPackageName , TypeElement element , Context context , @ Nullable Boolean metaComplete ) {
124
125
this .defaultPackageName = defaultPackageName ;
125
126
String className = clazz ;
126
127
String pkg = defaultPackageName ;
@@ -210,11 +211,14 @@ public String toString() {
210
211
return sb .toString ();
211
212
}
212
213
213
- private static boolean initIsMetaComplete (Context context , Boolean metadataComplete ) {
214
+ private static boolean initIsMetaComplete (Context context , @ Nullable Boolean metadataComplete ) {
214
215
return context .isFullyXmlConfigured () || Boolean .TRUE .equals ( metadataComplete );
215
216
}
216
217
217
- private @ Nullable String @ Nullable [] getCollectionTypes (String propertyName , String explicitTargetEntity , @ Nullable String explicitMapKeyClass , ElementKind expectedElementKind ) {
218
+ private @ Nullable String @ Nullable [] getCollectionTypes (String propertyName ,
219
+ @ Nullable String explicitTargetEntity ,
220
+ @ Nullable String explicitMapKeyClass ,
221
+ ElementKind expectedElementKind ) {
218
222
for ( Element elem : element .getEnclosedElements () ) {
219
223
if ( !expectedElementKind .equals ( elem .getKind () ) ) {
220
224
continue ;
@@ -251,7 +255,10 @@ else if ( elem.asType() instanceof ExecutableType ) {
251
255
return type ;
252
256
}
253
257
254
- private @ Nullable String [] determineTypes (String propertyName , String explicitTargetEntity , @ Nullable String explicitMapKeyClass , DeclaredType type ) {
258
+ private @ Nullable String [] determineTypes (String propertyName ,
259
+ @ Nullable String explicitTargetEntity ,
260
+ @ Nullable String explicitMapKeyClass ,
261
+ DeclaredType type ) {
255
262
@ Nullable String [] types = new String [3 ];
256
263
determineTargetType ( type , propertyName , explicitTargetEntity , types );
257
264
if ( determineCollectionType ( type , types ).equals ( Constants .MAP_ATTRIBUTE ) ) {
@@ -273,7 +280,10 @@ private String determineCollectionType(DeclaredType type, @Nullable String[] typ
273
280
return NullnessUtil .castNonNull ( types [1 ] = Constants .COLLECTIONS .get ( type .asElement ().toString () ) );
274
281
}
275
282
276
- private void determineTargetType (DeclaredType type , String propertyName , String explicitTargetEntity , @ Nullable String [] types ) {
283
+ private void determineTargetType (DeclaredType type ,
284
+ String propertyName ,
285
+ @ Nullable String explicitTargetEntity ,
286
+ @ Nullable String [] types ) {
277
287
List <? extends TypeMirror > typeArguments = type .getTypeArguments ();
278
288
279
289
if ( typeArguments .isEmpty () && explicitTargetEntity == null ) {
@@ -362,7 +372,7 @@ private void determineTargetType(DeclaredType type, String propertyName, String
362
372
context .logMessage (
363
373
Diagnostic .Kind .WARNING ,
364
374
"Unable to determine type for property " + propertyName + " of class " + getQualifiedName ()
365
- + " using access type " + accessTypeInfo .getDefaultAccessType ()
375
+ + " using access type " + requireNonNull ( accessTypeInfo ) .getDefaultAccessType ()
366
376
);
367
377
return null ;
368
378
}
@@ -498,15 +508,15 @@ private void parseEmbedded(JaxbEmbeddedImpl embedded) {
498
508
}
499
509
}
500
510
501
- private String determineExplicitTargetEntity (String targetClass ) {
502
- String explicitTargetClass = targetClass ;
503
- if ( explicitTargetClass != null ) {
511
+ private @ Nullable String determineExplicitTargetEntity (@ Nullable String targetClass ) {
512
+ String explicitTargetClass = null ;
513
+ if ( targetClass != null ) {
504
514
explicitTargetClass = determineFullyQualifiedClassName ( defaultPackageName , targetClass );
505
515
}
506
516
return explicitTargetClass ;
507
517
}
508
518
509
- private @ Nullable String determineExplicitMapKeyClass (JaxbMapKeyClassImpl mapKeyClass ) {
519
+ private @ Nullable String determineExplicitMapKeyClass (@ Nullable JaxbMapKeyClassImpl mapKeyClass ) {
510
520
String explicitMapKey = null ;
511
521
if ( mapKeyClass != null ) {
512
522
explicitMapKey = determineFullyQualifiedClassName ( defaultPackageName , mapKeyClass .getClazz () );
@@ -616,9 +626,9 @@ private void logMetaModelException(String name, MetaModelGenerationException e)
616
626
);
617
627
}
618
628
619
- private ElementKind getElementKind (AccessType accessType ) {
629
+ private ElementKind getElementKind (@ Nullable AccessType accessType ) {
620
630
// if no explicit access type was specified in xml we use the entity access type
621
- if ( accessType == null ) {
631
+ if ( accessType == null && accessTypeInfo != null ) {
622
632
return getElementKindForAccessType ( accessTypeInfo .getAccessType () );
623
633
}
624
634
return FIELD .equals ( accessType ) ? ElementKind .FIELD : ElementKind .METHOD ;
0 commit comments