diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/util/TypeUtils.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/util/TypeUtils.java index 64465a4166..7fcca11741 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/util/TypeUtils.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/util/TypeUtils.java @@ -41,20 +41,30 @@ import org.hibernate.jpamodelgen.MetaModelGenerationException; public final class TypeUtils { public static final String DEFAULT_ANNOTATION_PARAMETER_NAME = "value"; + private static final Map PRIMITIVE_WRAPPERS = new HashMap(); private static final Map PRIMITIVES = new HashMap(); static { - PRIMITIVES.put( TypeKind.CHAR, "Character" ); + PRIMITIVE_WRAPPERS.put( TypeKind.CHAR, "Character" ); - PRIMITIVES.put( TypeKind.BYTE, "Byte" ); - PRIMITIVES.put( TypeKind.SHORT, "Short" ); - PRIMITIVES.put( TypeKind.INT, "Integer" ); - PRIMITIVES.put( TypeKind.LONG, "Long" ); + PRIMITIVE_WRAPPERS.put( TypeKind.BYTE, "Byte" ); + PRIMITIVE_WRAPPERS.put( TypeKind.SHORT, "Short" ); + PRIMITIVE_WRAPPERS.put( TypeKind.INT, "Integer" ); + PRIMITIVE_WRAPPERS.put( TypeKind.LONG, "Long" ); - PRIMITIVES.put( TypeKind.BOOLEAN, "Boolean" ); + PRIMITIVE_WRAPPERS.put( TypeKind.BOOLEAN, "Boolean" ); - PRIMITIVES.put( TypeKind.FLOAT, "Float" ); - PRIMITIVES.put( TypeKind.DOUBLE, "Double" ); + PRIMITIVE_WRAPPERS.put( TypeKind.FLOAT, "Float" ); + PRIMITIVE_WRAPPERS.put( TypeKind.DOUBLE, "Double" ); + + PRIMITIVES.put( TypeKind.CHAR, "char" ); + PRIMITIVES.put( TypeKind.BYTE, "byte" ); + PRIMITIVES.put( TypeKind.SHORT, "short" ); + PRIMITIVES.put( TypeKind.INT, "int" ); + PRIMITIVES.put( TypeKind.LONG, "long" ); + PRIMITIVES.put( TypeKind.BOOLEAN, "boolean" ); + PRIMITIVES.put( TypeKind.FLOAT, "float" ); + PRIMITIVES.put( TypeKind.DOUBLE, "double" ); } private TypeUtils() { @@ -62,19 +72,24 @@ public final class TypeUtils { public static String toTypeString(TypeMirror type) { if ( type.getKind().isPrimitive() ) { - return PRIMITIVES.get( type.getKind() ); + return PRIMITIVE_WRAPPERS.get( type.getKind() ); } return type.toString(); } public static String toArrayTypeString(ArrayType type, Context context) { + TypeMirror componentType = type.getComponentType(); + if ( componentType.getKind().isPrimitive() ) { + return PRIMITIVES.get( componentType.getKind() ) + "[]"; + } + // 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( + TypeMirror component = componentType.accept( new SimpleTypeVisitor6() { @Override protected TypeMirror defaultAction(TypeMirror e, Void aVoid) {