Package gnu.bytecode
Class Type
java.lang.Object
gnu.bytecode.Type
- All Implemented Interfaces:
Type
- Direct Known Subclasses:
InlineCalls.LenientExpectedType
,ObjectType
,OccurrenceType
,PrimType
,XDataType
An abstract type as used by both gnu.bytecode and gnu.expr.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A marker class, used forType.neverReturnsType
. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ClassType
Deprecated.static final PrimType
static final PrimType
static final Method
static final PrimType
static final PrimType
static final PrimType
static final PrimType
static final Method
static final PrimType
static final PrimType
static final Method
static final ObjectType
static final PrimType
static final PrimType
static final Method
static final PrimType
static final PrimType
static final Method
static final ClassType
Deprecated.static final ClassType
static final ClassType
static final ClassType
static final ClassType
static final ClassType
static final ClassType
static final ClassType
static ClassType
static final ClassType
static final PrimType
static final PrimType
static final Method
static final Type
The return type of an expression that never returns, such as a throw.static final ObjectType
The magic type of null.static final ClassType
Deprecated.static final ClassType
static final ClassType
Deprecated.protected Class
static final PrimType
static final PrimType
static final ClassType
Deprecated.static final ClassType
static final Method
static final ObjectType
Deprecated.static final ObjectType
static final Type[]
static final PrimType
static final PrimType
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Object
coerceFromObject
(Object obj) Convert an object to a value of this Type.coerceToObject
(Object obj) Given a raw JVM value convert it to an object of this type.abstract int
Return a numeric code showing "subtype" relationship: 1: if other is a pure subtype of this; 0: if has the same values; -1: if this is a pure subtype of other; -2: if they have values in common but neither is a subtype of the other; -3: if the types have no values in common.void
emitCoerceFromObject
(CodeAttr code) Compile code to coerce/convert from Object to this type.void
emitCoerceToObject
(CodeAttr code) Compile code to convert a object of this type on the stack to Object.void
emitConvertFromPrimitive
(Type stackType, CodeAttr code) Convert from stackType (usually PrimType) to this type.void
emitIsInstance
(CodeAttr code) Return Java-level implementation type.getName()
Return JVM-level implementation type.If this is a type alias, get the aliased type.Get the java.lang.Class object for the representation type.final int
getSize()
int
static Type
Find an Type with the given name, or create a new one.int
hashCode()
int
isCompatibleWithValue
(Type valueType) If this is the target type, is a given source type compatible?static int
isCompatibleWithValue
(Type targetType, Type valueType) boolean
boolean
isInstance
(Object obj) boolean
static boolean
isMoreSpecific
(Type[] t1, Type[] t2) Return true iff t1[i].isSubtype(t2[i]) for all i.static boolean
final boolean
Return true if this is a "subtype" of other.static boolean
isValidJavaTypeName
(String name) final boolean
isVoid()
static Type
lookupType
(String name) static Type
lowestCommonSharedType
(Type t1, Type t2) static Type
lowestCommonSuperType
(Type t1, Type t2) Computes the common supertype Interfaces are not taken into account.static Type
static Type
Try to map java.lang.reflect.Type to gnu.bytecode.Type.static void
printSignature
(String sig, int off, int len, PrintWriter out) promote()
static void
registerTypeForClass
(Class clas, Type type) Register that the Type for class is type.protected void
protected void
void
setReflectClass
(Class rclass) protected void
setSignature
(String sig) static int
signatureLength
(String sig) static int
signatureLength
(String sig, int pos) Return the length of the signature starting at a given string position.static String
signatureToName
(String sig) Returns the Java-level type name from a given signature.static PrimType
signatureToPrimitive
(char sig) Returns the primitive type corresponding to a signature character.static Type
signatureToType
(String sig) Get a Type corresponding to the given signature string.static Type
signatureToType
(String sig, int off, int len) Get a Type corresponding to the given signature string.protected static int
swappedCompareResult
(int code) Change result from compare to compensate for argument swapping.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.reflect.Type
getTypeName
-
Field Details
-
byteType
-
shortType
-
intType
-
longType
-
floatType
-
doubleType
-
booleanType
-
charType
-
voidType
-
byte_type
-
short_type
-
int_type
-
long_type
-
float_type
-
double_type
-
boolean_type
-
char_type
-
void_type
-
neverReturnsType
The return type of an expression that never returns, such as a throw. -
javalangObjectType
-
objectType
-
javalangBooleanType
-
javalangCharacterType
-
javalangThrowableType
-
javalangannotationAnnotationType
-
typeArray0
-
toString_method
-
javalangNumberType
-
clone_method
-
intValue_method
-
longValue_method
-
floatValue_method
-
doubleValue_method
-
booleanValue_method
-
javalangClassType
-
javalanginvokeMethodHandleType
-
nullType
The magic type of null. -
errorType
-
javalangStringType
-
toStringType
-
pointer_type
Deprecated. -
string_type
Deprecated. -
tostring_type
Deprecated. -
java_lang_Class_type
Deprecated. -
boolean_ctype
Deprecated. -
throwable_type
-
number_type
Deprecated. -
reflectClass
-
-
Constructor Details
-
Type
protected Type() -
Type
-
-
Method Details
-
getImplementationType
Return Java-level implementation type. The type used to implement types not natively understood by the JVM or the Java language. Usually, the identity function. However, a language might handle union types or template types or type expressions calculated at run time. In that case return the type used at the Java level, and known at compile time. -
getRawType
Return JVM-level implementation type. -
getRealType
If this is a type alias, get the aliased type. This is semi-deprecated. -
isInterface
public boolean isInterface() -
isExisting
public boolean isExisting() -
lookupType
-
getType
Find an Type with the given name, or create a new one. Use this for "library classes", where you need the field/method types, but not one where you are about to generate code for.- Parameters:
name
- the name of the class (e..g. "java.lang.String").
-
registerTypeForClass
Register that the Type for class is type. -
make
Try to map java.lang.reflect.Type to gnu.bytecode.Type. If we can't handle that, resolve the Class instead. -
make
-
getSignature
-
setSignature
-
getGenericSignature
-
setGenericSignature
-
getMaybeGenericSignature
-
promote
-
promoteIfUnsigned
-
getSize
public final int getSize() -
getSizeInWords
public int getSizeInWords() -
isVoid
public final boolean isVoid() -
signatureToPrimitive
Returns the primitive type corresponding to a signature character.- Returns:
- a primitive type, or null if there is no such type.
-
signatureToType
Get a Type corresponding to the given signature string. -
signatureToType
Get a Type corresponding to the given signature string. -
printSignature
-
signatureLength
Return the length of the signature starting at a given string position. Returns -1 for an invalid signature. -
signatureLength
-
signatureToName
Returns the Java-level type name from a given signature. Returns null for an invalid signature. -
getName
-
setName
-
isValidJavaTypeName
-
isInstance
-
isSubtype
Return true if this is a "subtype" of other. -
isCompatibleWithValue
If this is the target type, is a given source type compatible?- Returns:
- -1 if not compatible; 0 if need to check at run-time; 1 if compatible; 2 if compatible and no conversion or cast needed. We also return 0 for some "narrowing" conversions even if we know they will always succeed, so as to make such conversions less preferred when doing method overloading.
-
isCompatibleWithValue
-
lowestCommonSuperType
Computes the common supertype Interfaces are not taken into account. This would be difficult, since interfaces allow multiple-inheritance. This means that there may exists multiple common supertypes to t1 and t2 that are not comparable.- Returns:
- the lowest type that is both above t1 and t2, or null if t1 and t2 have no common supertype.
-
compare
Return a numeric code showing "subtype" relationship: 1: if other is a pure subtype of this; 0: if has the same values; -1: if this is a pure subtype of other; -2: if they have values in common but neither is a subtype of the other; -3: if the types have no values in common. "Same values" is rather loose; by "A is a subtype of B" we mean that all instance of A can be "widened" to B. More formally, A.compare(B) returns: 1: all B values can be converted to A without a coercion failure (i.e. a ClassCastException or overflow or major loss of information), but not vice versa. 0: all A values can be converted to B without a coercion failure and vice versa; -1: all A values can be converted to B without a coercion failure but not vice versa; -2: there are (potentially) some A values that can be converted to B, and some B values can be converted to A; -3: there are no A values that can be converted to B, and neither are there any B values that can be converted to A. -
swappedCompareResult
protected static int swappedCompareResult(int code) Change result from compare to compensate for argument swapping. -
isMoreSpecific
Return true iff t1[i].isSubtype(t2[i]) for all i. -
isSame
-
emitIsInstance
-
coerceFromObject
Convert an object to a value of this Type. The result is actually of the implementation type, boxed as appropriate, so it is suitable for standard reflective operations, like the arguments to Field#set or Method#invoke. Throw a ClassCastException when this is not possible. -
coerceToObject
Given a raw JVM value convert it to an object of this type. I.e. the argument is an object of the type returned bygetRawType()
, boxed as needed. The result may be a language-specific (boxed) value. Generally a no-op. -
emitConvertFromPrimitive
Convert from stackType (usually PrimType) to this type. However, we might only convert part-way, to some object type. If converting to this type might fail at run-time, only convert to Object (as by emitCoerceToObject); a caller can usestackType.emitConvertFromObject
to convert the rest, but that might throw an exception. (This is a bit of a kludge.) -
emitCoerceToObject
Compile code to convert a object of this type on the stack to Object. -
emitCoerceFromObject
Compile code to coerce/convert from Object to this type. -
getReflectClass
Get the java.lang.Class object for the representation type. -
setReflectClass
-
toString
-
hashCode
public int hashCode()
-