mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8333749: Consolidate ConstantDesc conversion in java.base
Co-authored-by: Claes Redestad <redestad@openjdk.org> Reviewed-by: redestad, jvernee
This commit is contained in:
parent
a6fc2f839a
commit
8d2f9e57c3
13 changed files with 208 additions and 142 deletions
|
@ -32,20 +32,31 @@ import java.lang.constant.ClassDesc;
|
|||
import java.lang.constant.ConstantDescs;
|
||||
|
||||
public enum Wrapper {
|
||||
// wrapperType simple primitiveType simple char emptyArray format numericClass superClass classDescriptor
|
||||
BOOLEAN( Boolean.class, "Boolean", boolean.class, "boolean", 'Z', new boolean[0], Format.unsigned( 1), 0, 0, ConstantDescs.CD_boolean),
|
||||
// wrapperType simple primitiveType simple char emptyArray format numericClass superClass
|
||||
// basicClassDescriptor wrapperClassDescriptor
|
||||
BOOLEAN( Boolean.class, "Boolean", boolean.class, "boolean", 'Z', new boolean[0], Format.unsigned( 1), 0, 0,
|
||||
ConstantDescs.CD_boolean, ConstantDescs.CD_Boolean),
|
||||
// These must be in the order defined for widening primitive conversions in JLS 5.1.2
|
||||
// Avoid boxing integral types here to defer initialization of internal caches
|
||||
BYTE ( Byte.class, "Byte", byte.class, "byte", 'B', new byte[0], Format.signed( 8), BYTE_CLASS, BYTE_SUPERCLASSES, ConstantDescs.CD_byte),
|
||||
SHORT ( Short.class, "Short", short.class, "short", 'S', new short[0], Format.signed( 16), SHORT_CLASS, SHORT_SUPERCLASSES, ConstantDescs.CD_short),
|
||||
CHAR (Character.class, "Character", char.class, "char", 'C', new char[0], Format.unsigned(16), CHAR_CLASS, CHAR_SUPERCLASSES, ConstantDescs.CD_char),
|
||||
INT ( Integer.class, "Integer", int.class, "int", 'I', new int[0], Format.signed( 32), INT_CLASS, INT_SUPERCLASSES, ConstantDescs.CD_int),
|
||||
LONG ( Long.class, "Long", long.class, "long", 'J', new long[0], Format.signed( 64), LONG_CLASS, LONG_SUPERCLASSES, ConstantDescs.CD_long),
|
||||
FLOAT ( Float.class, "Float", float.class, "float", 'F', new float[0], Format.floating(32), FLOAT_CLASS, FLOAT_SUPERCLASSES, ConstantDescs.CD_float),
|
||||
DOUBLE ( Double.class, "Double", double.class, "double", 'D', new double[0], Format.floating(64), DOUBLE_CLASS, DOUBLE_CLASS, ConstantDescs.CD_double),
|
||||
OBJECT ( Object.class, "Object", Object.class, "Object", 'L', new Object[0], Format.other( 1), 0, 0, ConstantDescs.CD_Object),
|
||||
BYTE ( Byte.class, "Byte", byte.class, "byte", 'B', new byte[0], Format.signed( 8), BYTE_CLASS, BYTE_SUPERCLASSES,
|
||||
ConstantDescs.CD_byte, ConstantDescs.CD_Byte),
|
||||
SHORT ( Short.class, "Short", short.class, "short", 'S', new short[0], Format.signed( 16), SHORT_CLASS, SHORT_SUPERCLASSES,
|
||||
ConstantDescs.CD_short, ConstantDescs.CD_Short),
|
||||
CHAR (Character.class, "Character", char.class, "char", 'C', new char[0], Format.unsigned(16), CHAR_CLASS, CHAR_SUPERCLASSES,
|
||||
ConstantDescs.CD_char, ConstantDescs.CD_Character),
|
||||
INT ( Integer.class, "Integer", int.class, "int", 'I', new int[0], Format.signed( 32), INT_CLASS, INT_SUPERCLASSES,
|
||||
ConstantDescs.CD_int, ConstantDescs.CD_Integer),
|
||||
LONG ( Long.class, "Long", long.class, "long", 'J', new long[0], Format.signed( 64), LONG_CLASS, LONG_SUPERCLASSES,
|
||||
ConstantDescs.CD_long, ConstantDescs.CD_Long),
|
||||
FLOAT ( Float.class, "Float", float.class, "float", 'F', new float[0], Format.floating(32), FLOAT_CLASS, FLOAT_SUPERCLASSES,
|
||||
ConstantDescs.CD_float, ConstantDescs.CD_Float),
|
||||
DOUBLE ( Double.class, "Double", double.class, "double", 'D', new double[0], Format.floating(64), DOUBLE_CLASS, DOUBLE_CLASS,
|
||||
ConstantDescs.CD_double, ConstantDescs.CD_Double),
|
||||
OBJECT ( Object.class, "Object", Object.class, "Object", 'L', new Object[0], Format.other( 1), 0, 0,
|
||||
ConstantDescs.CD_Object, ConstantDescs.CD_Object),
|
||||
// VOID must be the last type, since it is "assignable" from any other type:
|
||||
VOID ( Void.class, "Void", void.class, "void", 'V', null, Format.other( 0), 0, 0, ConstantDescs.CD_void),
|
||||
VOID ( Void.class, "Void", void.class, "void", 'V', null, Format.other( 0), 0, 0,
|
||||
ConstantDescs.CD_void, ConstantDescs.CD_Void),
|
||||
;
|
||||
|
||||
public static final int COUNT = 10;
|
||||
|
@ -60,18 +71,20 @@ public enum Wrapper {
|
|||
private final int superClasses;
|
||||
private final String wrapperSimpleName;
|
||||
private final String primitiveSimpleName;
|
||||
private final ClassDesc classDesc;
|
||||
private final ClassDesc basicClassDesc;
|
||||
private final ClassDesc wrapperClassDesc;
|
||||
|
||||
private Wrapper(Class<?> wtype,
|
||||
String wtypeName,
|
||||
Class<?> ptype,
|
||||
String ptypeName,
|
||||
char tchar,
|
||||
Object emptyArray,
|
||||
int format,
|
||||
int numericClass,
|
||||
int superClasses,
|
||||
ClassDesc classDesc) {
|
||||
Wrapper(Class<?> wtype,
|
||||
String wtypeName,
|
||||
Class<?> ptype,
|
||||
String ptypeName,
|
||||
char tchar,
|
||||
Object emptyArray,
|
||||
int format,
|
||||
int numericClass,
|
||||
int superClasses,
|
||||
ClassDesc basicClassDesc,
|
||||
ClassDesc wrapperClassDesc) {
|
||||
this.wrapperType = wtype;
|
||||
this.primitiveType = ptype;
|
||||
this.basicTypeChar = tchar;
|
||||
|
@ -82,7 +95,8 @@ public enum Wrapper {
|
|||
this.superClasses = superClasses;
|
||||
this.wrapperSimpleName = wtypeName;
|
||||
this.primitiveSimpleName = ptypeName;
|
||||
this.classDesc = classDesc;
|
||||
this.basicClassDesc = basicClassDesc;
|
||||
this.wrapperClassDesc = wrapperClassDesc;
|
||||
}
|
||||
|
||||
/** For debugging, give the details of this wrapper. */
|
||||
|
@ -390,7 +404,10 @@ public enum Wrapper {
|
|||
}
|
||||
|
||||
/** A nominal descriptor of the wrapped type */
|
||||
public ClassDesc classDescriptor() { return classDesc; }
|
||||
public ClassDesc basicClassDescriptor() { return basicClassDesc; }
|
||||
|
||||
/** A nominal descriptor of the wrapper type */
|
||||
public ClassDesc wrapperClassDescriptor() { return wrapperClassDesc; }
|
||||
|
||||
/** What is the primitive type wrapped by this wrapper? */
|
||||
public Class<?> primitiveType() { return primitiveType; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue