Class TypeDescriptor


  • public class TypeDescriptor
    extends Object
    An immutable JVM field or method descriptor, classified by a sort constant.
    • 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 type
        dimensions - 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 type
        params - 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object