HHH-12011 - Fix JDK9 compatibility with TYPE_USE on array primitive-based fields.

This commit is contained in:
Chris Cranford 2018-05-13 15:14:33 -04:00
parent 9f293b113b
commit f8ffbd03ff
1 changed files with 25 additions and 10 deletions

View File

@ -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<TypeKind, String> PRIMITIVE_WRAPPERS = new HashMap<TypeKind, String>();
private static final Map<TypeKind, String> PRIMITIVES = new HashMap<TypeKind, String>();
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<TypeMirror, Void>() {
@Override
protected TypeMirror defaultAction(TypeMirror e, Void aVoid) {