Class TypeInfo


  • public class TypeInfo
    extends Object
    A JVM field descriptor with its slot size and primitive/array classification, compared by descriptor.
    • 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 type
        dimensions - 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object