Package com.tonic.type
Class TypeDescriptor
- java.lang.Object
-
- com.tonic.type.TypeDescriptor
-
public class TypeDescriptor extends Object
An immutable JVM field or method descriptor, classified by a sort constant.
-
-
Field Summary
Fields Modifier and Type Field Description static intARRAYstatic intBOOLEANstatic TypeDescriptorBOOLEAN_TYPEstatic intBYTEstatic TypeDescriptorBYTE_TYPEstatic intCHARstatic TypeDescriptorCHAR_TYPEstatic intDOUBLEstatic TypeDescriptorDOUBLE_TYPEstatic intFLOATstatic TypeDescriptorFLOAT_TYPEstatic intINTstatic TypeDescriptorINT_TYPEstatic intLONGstatic TypeDescriptorLONG_TYPEstatic intMETHODstatic intOBJECTstatic intSHORTstatic TypeDescriptorSHORT_TYPEstatic intVOIDstatic TypeDescriptorVOID_TYPE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)static TypeDescriptorforArray(TypeDescriptor element, int dimensions)Wraps a type in array brackets.static TypeDescriptorforClass(String internalName)Wraps an internal class name as an object descriptor.static TypeDescriptorforMethod(TypeDescriptor returnType, TypeDescriptor... params)Builds a method descriptor from its parameter and return types.intgetArgumentsSize()TypeDescriptor[]getArgumentTypes()StringgetClassName()StringgetDescriptor()intgetDimensions()TypeDescriptorgetElementType()StringgetInternalName()Unwraps the slash-separated class name, descending through array dimensions.intgetLoadOpcode()Picks the local-load opcode that matches this type.intgetReturnOpcode()Picks the return opcode that matches this type.TypeDescriptorgetReturnType()intgetSize()intgetSort()intgetStoreOpcode()Picks the local-store opcode that matches this type.inthashCode()booleanisArray()booleanisMethod()booleanisObject()booleanisPrimitive()static TypeDescriptorparse(String descriptor)Parses a field or method descriptor, returning a shared instance for primitives.StringtoString()
-
-
-
Field Detail
-
VOID
public static final int VOID
- See Also:
- Constant Field Values
-
BOOLEAN
public static final int BOOLEAN
- See Also:
- Constant Field Values
-
CHAR
public static final int CHAR
- See Also:
- Constant Field Values
-
BYTE
public static final int BYTE
- See Also:
- Constant Field Values
-
SHORT
public static final int SHORT
- See Also:
- Constant Field Values
-
INT
public static final int INT
- See Also:
- Constant Field Values
-
FLOAT
public static final int FLOAT
- See Also:
- Constant Field Values
-
LONG
public static final int LONG
- See Also:
- Constant Field Values
-
DOUBLE
public static final int DOUBLE
- See Also:
- Constant Field Values
-
ARRAY
public static final int ARRAY
- See Also:
- Constant Field Values
-
OBJECT
public static final int OBJECT
- See Also:
- Constant Field Values
-
METHOD
public static final int METHOD
- See Also:
- Constant Field Values
-
VOID_TYPE
public static final TypeDescriptor VOID_TYPE
-
BOOLEAN_TYPE
public static final TypeDescriptor BOOLEAN_TYPE
-
BYTE_TYPE
public static final TypeDescriptor BYTE_TYPE
-
CHAR_TYPE
public static final TypeDescriptor CHAR_TYPE
-
SHORT_TYPE
public static final TypeDescriptor SHORT_TYPE
-
INT_TYPE
public static final TypeDescriptor INT_TYPE
-
LONG_TYPE
public static final TypeDescriptor LONG_TYPE
-
FLOAT_TYPE
public static final TypeDescriptor FLOAT_TYPE
-
DOUBLE_TYPE
public static final TypeDescriptor DOUBLE_TYPE
-
-
Method Detail
-
forClass
public static TypeDescriptor forClass(String internalName)
Wraps an internal class name as an object descriptor.- Parameters:
internalName- the slash-separated class name- Returns:
- the object descriptor
-
forArray
public static TypeDescriptor forArray(TypeDescriptor element, int dimensions)
Wraps a type in array brackets.- Parameters:
element- the element typedimensions- how many bracket levels to add- Returns:
- the array descriptor
-
forMethod
public static TypeDescriptor forMethod(TypeDescriptor returnType, TypeDescriptor... params)
Builds a method descriptor from its parameter and return types.- Parameters:
returnType- the return typeparams- the parameter types in declaration order- Returns:
- the method descriptor
-
parse
public static TypeDescriptor parse(String descriptor)
Parses a field or method descriptor, returning a shared instance for primitives.- Parameters:
descriptor- the descriptor text- Returns:
- the parsed type
- Throws:
IllegalArgumentException- if the descriptor is null, empty, or starts with an unknown tag
-
getSort
public int getSort()
- Returns:
- the sort
-
isPrimitive
public boolean isPrimitive()
- Returns:
- true if this is void or a primitive type
-
isArray
public boolean isArray()
- Returns:
- true if this is an array type
-
isObject
public boolean isObject()
- Returns:
- true if this is a non-array reference type
-
isMethod
public boolean isMethod()
- Returns:
- true if this is a method descriptor
-
getInternalName
public String getInternalName()
Unwraps the slash-separated class name, descending through array dimensions.- Returns:
- the internal name, or null for primitives, method descriptors and primitive arrays
-
getClassName
public String getClassName()
- Returns:
- the dotted class name, or null when there is no class to name
-
getDimensions
public int getDimensions()
- Returns:
- the array dimension count, or 0 if this is not an array
-
getElementType
public TypeDescriptor getElementType()
- Returns:
- the type left after stripping every array dimension, or null if this is not an array
-
getReturnType
public TypeDescriptor getReturnType()
- Returns:
- the return type, or null if this is not a method descriptor
-
getArgumentTypes
public TypeDescriptor[] getArgumentTypes()
- Returns:
- the parameter types in declaration order, empty if this is not a method descriptor
-
getArgumentsSize
public int getArgumentsSize()
- Returns:
- the total slot count of the parameters, counting long and double twice, or 0 if this is not a method descriptor
-
getDescriptor
public String getDescriptor()
- Returns:
- the descriptor
-
getSize
public int getSize()
- Returns:
- the number of JVM stack or local slots this type occupies - 2 for long and double, 0 for void, else 1
-
getLoadOpcode
public int getLoadOpcode()
Picks the local-load opcode that matches this type.- Returns:
- ILOAD, LLOAD, FLOAD, DLOAD or ALOAD
- Throws:
IllegalStateException- if the type is void or a method descriptor
-
getStoreOpcode
public int getStoreOpcode()
Picks the local-store opcode that matches this type.- Returns:
- ISTORE, LSTORE, FSTORE, DSTORE or ASTORE
- Throws:
IllegalStateException- if the type is void or a method descriptor
-
getReturnOpcode
public int getReturnOpcode()
Picks the return opcode that matches this type.- Returns:
- RETURN, IRETURN, LRETURN, FRETURN, DRETURN or ARETURN
- Throws:
IllegalStateException- if this is a method descriptor
-
-