diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttributeGenerationVisitor.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttributeGenerationVisitor.java index f031a2bee3..b9147941ff 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttributeGenerationVisitor.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttributeGenerationVisitor.java @@ -77,7 +77,7 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor6 annotationMirrors = typeMirror.getAnnotationMirrors(); - if ( !annotationMirrors.isEmpty() ) { - String typeName = typeMirror.toString(); - if ( typeName.startsWith( "(" ) && typeName.endsWith( ")" ) ) { - int seperator = typeName.indexOf( ":: " ); - if ( seperator != -1 ) { - return typeName.substring( seperator + 3, typeName.length() - 1 ) + "[]"; - } - } - } - } - if ( type.getKind().isPrimitive() ) { return PRIMITIVES.get( type.getKind() ); } return type.toString(); } + public static String toArrayTypeString(ArrayType type, Context context) { + // When an ArrayType is annotated with an annotation which uses TYPE_USE targets, + // we cannot simply take the TypeMirror returned by #getComponentType because it + // itself is an AnnotatedType. + // + // The simplest approach here to get the TypeMirror for both ArrayType use cases + // is to use the visitor to retrieve the underlying TypeMirror. + TypeMirror component = type.getComponentType().accept( + new SimpleTypeVisitor6() { + @Override + protected TypeMirror defaultAction(TypeMirror e, Void aVoid) { + return e; + } + }, + null + ); + + return extractClosestRealTypeAsString( component, context ) + "[]"; + } + public static TypeElement getSuperclassTypeElement(TypeElement element) { final TypeMirror superClass = element.getSuperclass(); //superclass of Object is of NoType which returns some other kind