Package com.tonic.parser.util
Class TypeInfo
- java.lang.Object
-
- com.tonic.parser.util.TypeInfo
-
public class TypeInfo extends Object
A JVM field descriptor with its slot size and primitive/array classification, compared by descriptor.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)static TypeInfoforArrayType(TypeInfo elementType, int dimensions)Builds an array type by prefixing an element descriptor with the requested dimensions.static TypeInfoforClassName(String className)Wraps an internal class name into an object type descriptor.intgetArrayDimensions()StringgetClassName()StringgetDescriptor()TypeInfogetElementType()Strips one array dimension off this type.StringgetInternalName()intgetSize()inthashCode()booleanisArray()booleanisPrimitive()booleanisReference()booleanisVoid()booleanisWide()static TypeInfoof(String descriptor)Parses a field descriptor, returning the shared instance for primitives.StringtoString()
-
-
-
Field Detail
-
VOID
public static final TypeInfo VOID
-
BOOLEAN
public static final TypeInfo BOOLEAN
-
BYTE
public static final TypeInfo BYTE
-
CHAR
public static final TypeInfo CHAR
-
SHORT
public static final TypeInfo SHORT
-
INT
public static final TypeInfo INT
-
FLOAT
public static final TypeInfo FLOAT
-
LONG
public static final TypeInfo LONG
-
DOUBLE
public static final TypeInfo DOUBLE
-
-
Method Detail
-
of
public static TypeInfo of(String descriptor)
Parses a field descriptor, returning the shared instance for primitives.- Parameters:
descriptor- a JVM field descriptor- Returns:
- the matching type
- Throws:
IllegalArgumentException- if the descriptor is null, empty, or starts with an unknown tag
-
forClassName
public static TypeInfo forClassName(String className)
Wraps an internal class name into an object type descriptor.- Parameters:
className- the internal class name, without the leading 'L' or trailing ';'- Returns:
- the object type
- Throws:
IllegalArgumentException- if the name is null or empty
-
forArrayType
public static TypeInfo forArrayType(TypeInfo elementType, int dimensions)
Builds an array type by prefixing an element descriptor with the requested dimensions.- Parameters:
elementType- the element typedimensions- how many '[' to prepend- Returns:
- the array type
-
getDescriptor
public String getDescriptor()
- Returns:
- the descriptor
-
getSize
public int getSize()
- Returns:
- the size
-
isPrimitive
public boolean isPrimitive()
- Returns:
- whether primitive
-
isArray
public boolean isArray()
- Returns:
- whether array
-
isVoid
public boolean isVoid()
- Returns:
- true if this is the void type
-
isWide
public boolean isWide()
- Returns:
- true if this is a long or double, which occupy two local slots
-
isReference
public boolean isReference()
- Returns:
- true if values of this type occupy a reference slot
-
getClassName
public String getClassName()
- Returns:
- the class name for object types, the raw descriptor for arrays, or null for primitives
-
getInternalName
public String getInternalName()
- Returns:
- the slash-separated internal name for object types, or the raw descriptor for arrays and primitives
-
getElementType
public TypeInfo getElementType()
Strips one array dimension off this type.- Returns:
- the component type, or null if this is not an array
-
getArrayDimensions
public int getArrayDimensions()
- Returns:
- the number of leading '[' in the descriptor, or 0 if this is not an array
-
-