7575import static org .hibernate .grammars .hql .HqlLexer .IDENTIFIER ;
7676import static org .hibernate .grammars .hql .HqlLexer .ORDER ;
7777import static org .hibernate .grammars .hql .HqlLexer .WHERE ;
78- import static org .hibernate .internal .util .StringHelper .isEmpty ;
7978import static org .hibernate .internal .util .StringHelper .qualify ;
8079import static org .hibernate .processor .annotation .AbstractQueryMethod .isSessionParameter ;
8180import static org .hibernate .processor .annotation .AbstractQueryMethod .isSpecialParam ;
8988import static org .hibernate .processor .util .TypeUtils .findMappedSuperClass ;
9089import static org .hibernate .processor .util .TypeUtils .getAnnotationMirror ;
9190import static org .hibernate .processor .util .TypeUtils .getAnnotationValue ;
92- import static org .hibernate .processor .util .TypeUtils .getAnnotationValueRef ;
9391import static org .hibernate .processor .util .TypeUtils .hasAnnotation ;
9492import static org .hibernate .processor .util .TypeUtils .primitiveClassMatchesKind ;
9593import static org .hibernate .processor .util .TypeUtils .propertyName ;
@@ -500,9 +498,12 @@ private void addDefaultConstructor() {
500498 private @ Nullable String dataStore () {
501499 final AnnotationMirror repo = getAnnotationMirror ( element , JD_REPOSITORY );
502500 if ( repo != null ) {
503- final String dataStore = (String ) getAnnotationValue ( repo , "dataStore" );
504- if ( dataStore != null && !dataStore .isEmpty () ) {
505- return dataStore ;
501+ final AnnotationValue dataStoreValue = getAnnotationValue ( repo , "dataStore" );
502+ if (dataStoreValue != null ) {
503+ final String dataStore = dataStoreValue .getValue ().toString ();
504+ if ( !dataStore .isEmpty () ) {
505+ return dataStore ;
506+ }
506507 }
507508 }
508509 return null ;
@@ -866,13 +867,13 @@ private static TypeMirror attributeType(Element memberOfClass) {
866867 }
867868
868869 private void validateToOneAssociation (Element memberOfClass , AnnotationMirror annotation , TypeMirror type ) {
869- final TypeMirror target = ( TypeMirror ) getAnnotationValue (annotation , "targetEntity" );
870- validateAssociation (memberOfClass , annotation , target == null ? type : target );
870+ final AnnotationValue target = getAnnotationValue (annotation , "targetEntity" );
871+ validateAssociation (memberOfClass , annotation , target == null ? type : ( TypeMirror ) target . getValue () );
871872 }
872873
873874 private void validateToManyAssociation (Element memberOfClass , AnnotationMirror annotation , TypeMirror type ) {
874- final TypeMirror target = ( TypeMirror ) getAnnotationValue (annotation , "targetEntity" );
875- validateAssociation (memberOfClass , annotation , target == null ? elementType (type ) : target );
875+ final AnnotationValue target = getAnnotationValue (annotation , "targetEntity" );
876+ validateAssociation (memberOfClass , annotation , target == null ? elementType (type ) : ( TypeMirror ) target . getValue () );
876877 }
877878
878879 private void validateAssociation (Element memberOfClass , AnnotationMirror annotation , @ Nullable TypeMirror typeMirror ) {
@@ -888,8 +889,9 @@ private void validateAssociation(Element memberOfClass, AnnotationMirror annotat
888889 final DeclaredType assocDeclaredType = (DeclaredType ) typeMirror ;
889890 final TypeElement assocTypeElement = (TypeElement ) assocDeclaredType .asElement ();
890891 if ( hasAnnotation (assocTypeElement , ENTITY ) ) {
891- final String mappedBy = (String ) getAnnotationValue (annotation , "mappedBy" );
892- validateBidirectionalMapping (memberOfClass , annotation , mappedBy , assocTypeElement );
892+ final AnnotationValue mappedBy = getAnnotationValue (annotation , "mappedBy" );
893+ final String propertyName = mappedBy == null ? null : mappedBy .getValue ().toString ();
894+ validateBidirectionalMapping (memberOfClass , annotation , propertyName , assocTypeElement );
893895 }
894896 else {
895897 message (memberOfClass , "type '" + assocTypeElement .getSimpleName ()
@@ -916,7 +918,7 @@ private void validateBidirectionalMapping(
916918 return ;
917919 }
918920 final AnnotationValue annotationVal =
919- castNonNull (getAnnotationValueRef (annotation , "mappedBy" ));
921+ castNonNull (getAnnotationValue (annotation , "mappedBy" ));
920922 for ( Element member : context .getElementUtils ().getAllMembers (assocTypeElement ) ) {
921923 if ( propertyName (this , member ).contentEquals (mappedBy ) ) {
922924 validateBackRef (memberOfClass , annotation , assocTypeElement , member , annotationVal );
@@ -1517,7 +1519,7 @@ private List<OrderBy> orderByList(ExecutableElement method, TypeElement entityTy
15171519 final List <OrderBy > result = new ArrayList <>();
15181520 @ SuppressWarnings ("unchecked" )
15191521 final List <AnnotationValue > list = (List <AnnotationValue >)
1520- castNonNull ( getAnnotationValue ( orderByList , "value" ) );
1522+ castNonNull ( getAnnotationValue ( orderByList , "value" ) ). getValue () ;
15211523 for ( AnnotationValue element : list ) {
15221524 result .add ( orderByExpression ( castNonNull ( (AnnotationMirror ) element .getValue () ), entityType , method ) );
15231525 }
@@ -1532,14 +1534,14 @@ private List<OrderBy> orderByList(ExecutableElement method, TypeElement entityTy
15321534 }
15331535
15341536 private OrderBy orderByExpression (AnnotationMirror orderBy , TypeElement entityType , ExecutableElement method ) {
1535- final String fieldName = ( String ) castNonNull ( getAnnotationValue (orderBy , "value" ) );
1537+ final String fieldName = castNonNull ( getAnnotationValue (orderBy , "value" ) ). getValue (). toString ( );
15361538 if ( fieldName .equals ("<error>" ) ) {
15371539 throw new ProcessLaterException ();
15381540 }
1539- final Boolean descendingOrNull = ( Boolean ) getAnnotationValue (orderBy , "descending" );
1540- final Boolean ignoreCaseOrNull = ( Boolean ) getAnnotationValue (orderBy , "ignoreCase" );
1541- final boolean descending = descendingOrNull != null && descendingOrNull ;
1542- final boolean ignoreCase = ignoreCaseOrNull != null && ignoreCaseOrNull ;
1541+ final AnnotationValue descendingOrNull = getAnnotationValue (orderBy , "descending" );
1542+ final AnnotationValue ignoreCaseOrNull = getAnnotationValue (orderBy , "ignoreCase" );
1543+ final boolean descending = descendingOrNull != null && ( Boolean ) descendingOrNull . getValue () ;
1544+ final boolean ignoreCase = ignoreCaseOrNull != null && ( Boolean ) ignoreCaseOrNull . getValue () ;
15431545 final String path = fieldName
15441546 .replace ('$' , '.' )
15451547 .replace ('_' , '.' ); //Jakarta Data allows _ here
@@ -1632,14 +1634,14 @@ private static List<String> enabledFetchProfiles(ExecutableElement method) {
16321634 return emptyList ();
16331635 }
16341636 else {
1635- final Object enabledFetchProfiles =
1637+ final AnnotationValue enabledFetchProfiles =
16361638 getAnnotationValue ( findAnnotation , "enabledFetchProfiles" );
16371639 if ( enabledFetchProfiles == null ) {
16381640 return emptyList ();
16391641 }
16401642 else {
16411643 @ SuppressWarnings ("unchecked" )
1642- final List <AnnotationValue > annotationValues = (List <AnnotationValue >) enabledFetchProfiles ;
1644+ final List <AnnotationValue > annotationValues = (List <AnnotationValue >) enabledFetchProfiles . getValue () ;
16431645 final List <String > result = annotationValues .stream ().map (AnnotationValue ::toString ).collect (toList ());
16441646 if ( result .stream ().anyMatch ("<error>" ::equals ) ) {
16451647 throw new ProcessLaterException ();
@@ -1859,9 +1861,9 @@ else if ( containsAnnotation( member, NATURAL_ID ) ) {
18591861 else {
18601862 final AnnotationMirror idClass = getAnnotationMirror ( entityType , ID_CLASS );
18611863 if ( idClass != null ) {
1862- final Object value = getAnnotationValue ( idClass , "value" );
1863- if ( value instanceof TypeMirror ) {
1864- if ( context .getTypeUtils ().isSameType ( param .asType (), (TypeMirror ) value ) ) {
1864+ final AnnotationValue value = getAnnotationValue ( idClass , "value" );
1865+ if ( value != null ) {
1866+ if ( context .getTypeUtils ().isSameType ( param .asType (), (TypeMirror ) value . getValue () ) ) {
18651867 return FieldType .ID ;
18661868 }
18671869 }
@@ -2060,7 +2062,7 @@ private void addQueryMethod(
20602062 AnnotationMirror mirror ,
20612063 boolean isNative ) {
20622064
2063- final AnnotationValue value = getAnnotationValueRef ( mirror , "value" );
2065+ final AnnotationValue value = getAnnotationValue ( mirror , "value" );
20642066 if ( value != null ) {
20652067 final Object query = value .getValue ();
20662068 if ( query instanceof String ) {
@@ -2142,8 +2144,7 @@ private void addQueryMethod(
21422144 if ( annotation == null ) {
21432145 throw new AssertionFailure ("@Entity annotation should not be missing" );
21442146 }
2145- final String name = (String ) getAnnotationValue (annotation , "name" );
2146- return isEmpty (name ) ? resultType .asElement ().getSimpleName ().toString () : name ;
2147+ return entityName (resultType , annotation );
21472148 }
21482149 else if ( primaryEntity != null ) {
21492150 return primaryEntity .getSimpleName ().toString ();
@@ -2153,6 +2154,17 @@ else if ( primaryEntity != null ) {
21532154 }
21542155 }
21552156
2157+ private static String entityName (DeclaredType resultType , AnnotationMirror annotation ) {
2158+ final AnnotationValue name = getAnnotationValue (annotation , "name" );
2159+ if (name != null ) {
2160+ final String explicitName = name .getValue ().toString ();
2161+ if ( !explicitName .isEmpty () ) {
2162+ return explicitName ;
2163+ }
2164+ }
2165+ return resultType .asElement ().getSimpleName ().toString ();
2166+ }
2167+
21562168 private static String addFromClauseIfNecessary (String hql , @ Nullable String entityType ) {
21572169 if ( entityType == null ) {
21582170 return hql ;
@@ -2468,8 +2480,7 @@ private boolean checkReturnedEntity(EntityDomainType<?> model, TypeMirror return
24682480 final TypeElement typeElement = (TypeElement ) declaredType .asElement ();
24692481 final AnnotationMirror mirror = getAnnotationMirror (typeElement , ENTITY );
24702482 if ( mirror != null ) {
2471- final Object value = getAnnotationValue ( mirror , "name" );
2472- final String entityName = value instanceof String ? (String ) value : typeElement .getSimpleName ().toString ();
2483+ final String entityName = entityName (declaredType , mirror );
24732484 return model .getHibernateEntityName ().equals ( entityName );
24742485 }
24752486 }
@@ -2622,7 +2633,9 @@ private static String parameterName(VariableElement parameter) {
26222633 final AnnotationMirror by = getAnnotationMirror ( parameter , "jakarta.data.repository.By" );
26232634 final AnnotationMirror param = getAnnotationMirror ( parameter , "jakarta.data.repository.Param" );
26242635 if ( by != null ) {
2625- final String name = (String ) castNonNull (getAnnotationValue (by , "value" ));
2636+ final String name =
2637+ castNonNull (getAnnotationValue (by , "value" ))
2638+ .getValue ().toString ();
26262639 if ( name .contains ("<error>" ) ) {
26272640 throw new ProcessLaterException ();
26282641 }
@@ -2631,7 +2644,9 @@ private static String parameterName(VariableElement parameter) {
26312644 .replace ('_' , '.' );
26322645 }
26332646 else if ( param != null ) {
2634- final String name = (String ) castNonNull (getAnnotationValue (param , "value" ));
2647+ final String name =
2648+ castNonNull (getAnnotationValue (param , "value" ))
2649+ .getValue ().toString ();
26352650 if ( name .contains ("<error>" ) ) {
26362651 throw new ProcessLaterException ();
26372652 }
@@ -2669,7 +2684,8 @@ private static boolean isNullable(Element member) {
26692684 if ( name .contentEquals (Constants .BASIC )
26702685 || name .contentEquals (Constants .MANY_TO_ONE )
26712686 || name .contentEquals (Constants .ONE_TO_ONE )) {
2672- if ( FALSE .equals ( getAnnotationValue (mirror , "optional" ) ) ) {
2687+ AnnotationValue optional = getAnnotationValue (mirror , "optional" );
2688+ if ( optional != null && optional .getValue ().equals (FALSE ) ) {
26732689 nullable = false ;
26742690 }
26752691 }
0 commit comments