fix bug where type annotations got generated onto Class literals

needed for Jakarta Data TCK

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-03-29 15:56:33 +01:00
parent 3370dc81bc
commit 74c026b27d
2 changed files with 37 additions and 2 deletions

View File

@ -2120,6 +2120,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
method.getSimpleName().toString(),
processedQuery,
returnType == null ? null : returnType.toString(),
returnType == null ? null : returnTypeClass( returnType ),
containerTypeName,
paramNames,
paramTypes,
@ -2137,6 +2138,36 @@ public class AnnotationMetaEntity extends AnnotationMeta {
}
}
private static String returnTypeClass(TypeMirror returnType) {
switch (returnType.getKind()) {
case DECLARED:
DeclaredType declaredType = (DeclaredType) returnType;
final TypeElement typeElement = (TypeElement) declaredType.asElement();
return typeElement.getQualifiedName().toString();
case INT:
return "int";
case LONG:
return "long";
case SHORT:
return "short";
case BYTE:
return "byte";
case BOOLEAN:
return "boolean";
case FLOAT:
return "float";
case DOUBLE:
return "double";
case CHAR:
return "char";
case ARRAY:
final ArrayType arrayType = (ArrayType) returnType;
return returnTypeClass( arrayType.getComponentType() ) + "[]";
default:
return returnType.toString();
}
}
private @Nullable String implicitEntityName(@Nullable DeclaredType resultType) {
if ( resultType != null && hasAnnotation(resultType.asElement(), ENTITY) ) {
final AnnotationMirror annotation =

View File

@ -23,6 +23,7 @@ import static org.hibernate.processor.util.StringUtil.getUpperUnderscoreCaseFrom
*/
public class QueryMethod extends AbstractQueryMethod {
private final String queryString;
private final @Nullable String returnTypeClass;
private final @Nullable String containerType;
private final boolean isUpdate;
private final boolean isNative;
@ -35,6 +36,8 @@ public class QueryMethod extends AbstractQueryMethod {
@Nullable
String returnTypeName,
@Nullable
String returnTypeClass,
@Nullable
String containerType,
List<String> paramNames,
List<String> paramTypes,
@ -54,6 +57,7 @@ public class QueryMethod extends AbstractQueryMethod {
addNonnullAnnotation,
dataRepository );
this.queryString = queryString;
this.returnTypeClass = returnTypeClass;
this.containerType = containerType;
this.isUpdate = isUpdate;
this.isNative = isNative;
@ -117,10 +121,10 @@ public class QueryMethod extends AbstractQueryMethod {
.append(createQueryMethod())
.append("(")
.append(getConstantName());
if ( returnTypeName != null && !isUpdate ) {
if ( returnTypeClass != null && !isUpdate ) {
declaration
.append(", ")
.append(annotationMetaEntity.importType(returnTypeName))
.append(annotationMetaEntity.importType(returnTypeClass))
.append(".class");
}
declaration.append(")\n");