HHH-12011 - Fix JDK9 compatibility with TYPE_USE on array primitive-based fields.
(cherry picked from commit f8ffbd0
)
This commit is contained in:
parent
4ebfd43ed0
commit
5fd63433c9
|
@ -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<String, String> PRIMITIVES = new HashMap<String, String>();
|
||||
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( "char", "Character" );
|
||||
PRIMITIVE_WRAPPERS.put( TypeKind.CHAR, "Character" );
|
||||
|
||||
PRIMITIVES.put( "byte", "Byte" );
|
||||
PRIMITIVES.put( "short", "Short" );
|
||||
PRIMITIVES.put( "int", "Integer" );
|
||||
PRIMITIVES.put( "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( "boolean", "Boolean" );
|
||||
PRIMITIVE_WRAPPERS.put( TypeKind.BOOLEAN, "Boolean" );
|
||||
|
||||
PRIMITIVES.put( "float", "Float" );
|
||||
PRIMITIVES.put( "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.toString() );
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue