From 06136ba5ecc134ebaf64b7974ea4a65dd28418c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20=C3=89pardaud?= Date: Fri, 1 Dec 2023 17:27:21 +0100 Subject: [PATCH] Make sure ununi does not throw given a Uni --- .../annotation/AnnotationMetaEntity.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java index 07e51f5923..51175a48aa 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java @@ -521,9 +521,9 @@ public class AnnotationMetaEntity extends AnnotationMeta { */ private static boolean isSessionGetter(ExecutableElement method) { if ( method.getParameters().isEmpty() ) { - final TypeMirror type = method.getReturnType(); + final TypeMirror type = ununi( method.getReturnType() ); if ( type.getKind() == TypeKind.DECLARED ) { - final DeclaredType declaredType = ununi( (DeclaredType) type ); + final DeclaredType declaredType = (DeclaredType) type; final Element element = declaredType.asElement(); if ( element.getKind() == ElementKind.INTERFACE ) { final Name name = ((TypeElement) element).getQualifiedName(); @@ -628,13 +628,13 @@ public class AnnotationMetaEntity extends AnnotationMeta { } private void addQueryMethod(ExecutableElement method) { - final TypeMirror returnType = method.getReturnType(); + final TypeMirror returnType = ununi( method.getReturnType() ); final TypeKind kind = returnType.getKind(); if ( kind == TypeKind.VOID || kind == TypeKind.ARRAY || kind.isPrimitive() ) { addQueryMethod( method, returnType, null ); } else if ( kind == TypeKind.DECLARED ) { - final DeclaredType declaredType = ununi( (DeclaredType) returnType ); + final DeclaredType declaredType = (DeclaredType) returnType; final TypeElement typeElement = (TypeElement) declaredType.asElement(); final List typeArguments = declaredType.getTypeArguments(); switch ( typeArguments.size() ) { @@ -711,11 +711,16 @@ public class AnnotationMetaEntity extends AnnotationMeta { } } - private static DeclaredType ununi(DeclaredType returnType) { - final TypeElement typeElement = (TypeElement) returnType.asElement(); - return typeElement.getQualifiedName().contentEquals(Constants.UNI) - ? (DeclaredType) returnType.getTypeArguments().get(0) - : returnType; + private static TypeMirror ununi(TypeMirror returnType) { + if ( returnType.getKind() != TypeKind.DECLARED ) { + return returnType; + } + DeclaredType declaredType = (DeclaredType) returnType; + final TypeElement typeElement = (TypeElement) declaredType.asElement(); + if ( typeElement.getQualifiedName().contentEquals( Constants.UNI ) ) { + returnType = declaredType.getTypeArguments().get(0); + } + return returnType; } private static boolean isLegalRawResultType(String containerTypeName) { @@ -853,6 +858,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { ExecutableElement method, @Nullable TypeMirror returnType, @Nullable TypeElement containerType) { + returnType = returnType != null ? ununi( returnType ) : null; if ( returnType == null ) { context.message( method, "missing return type", @@ -881,7 +887,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { } } else if ( returnType.getKind() == TypeKind.DECLARED ) { - final DeclaredType declaredType = ununi( (DeclaredType) returnType ); + final DeclaredType declaredType = (DeclaredType) returnType; final TypeElement entity = (TypeElement) declaredType.asElement(); if ( !containsAnnotation( entity, Constants.ENTITY ) ) { context.message( method,