Class Descriptor

java.lang.Object
org.codehaus.janino.Descriptor

public final class Descriptor extends Object
Helper class that defines useful methods for handling "field descriptors" (JVMS 4.3.2) and "method descriptors" (JVMS 4.3.3).

Typical descriptors are:

  • I Integer
  • [I Array of integer
  • Lpkg1/pkg2/Clazz; Class
  • Lpkg1/pkg2/Outer$Inner; Member class
  • Field Details

  • Constructor Details

    • Descriptor

      private Descriptor()
  • Method Details

    • isReference

      public static boolean isReference(String d)
      Returns:
      Whether this Descriptor describes a reference (i.e. non-primitive) type
    • isClassOrInterfaceReference

      public static boolean isClassOrInterfaceReference(String d)
      Returns:
      Whether this Descriptor describes a class or an interface (and not an array or a primitive type)
    • isArrayReference

      public static boolean isArrayReference(String d)
      Returns:
      Whether this Descriptor describes an array type
    • getComponentDescriptor

      public static String getComponentDescriptor(String d)
      Returns:
      The descriptor of the component of the array type d
      Throws:
      InternalCompilerException - d does not describe an array type
    • size

      public static short size(String d)
      Returns:
      The number of slots (1 or two) that a value of the type described by d occupies on the operand stack or in the local variable array, or 0 iff d describes the type VOID
    • hasSize1

      public static boolean hasSize1(String d)
      Returns:
      true iff d describes a primitive type except LONG and DOUBLE, or a reference type
    • hasSize2

      public static boolean hasSize2(String d)
      Returns:
      true iff d LONG or DOUBLE
    • toString

      public static String toString(String d)
      Pretty-prints the given descriptor.
      Parameters:
      d - A valid field or method descriptor
    • toString

      private static int toString(String d, int idx, StringBuilder sb)
    • fromClassName

      public static String fromClassName(String className)
      Converts a class name as defined by "Class.getName()" into a descriptor.
    • fromInternalForm

      public static String fromInternalForm(String internalForm)
      Converts a class name in the "internal form" as described in JVMS 4.2 into a descriptor.

      Also implements the encoding of array types as described in JVMS 4.4.1.

    • toClassName

      public static String toClassName(String d)
      Converts a field descriptor into a class name as defined by Class.getName().
    • toInternalForm

      public static String toInternalForm(String d)
      Converts a descriptor into the "internal form" as defined by JVMS 4.2.
    • isPrimitive

      public static boolean isPrimitive(String d)
      Returns:
      Whether d describes a primitive type or VOID
    • isPrimitiveNumeric

      public static boolean isPrimitiveNumeric(String d)
      Returns:
      Whether d describes a primitive type except boolean and void
    • getPackageName

      @Nullable public static String getPackageName(String d)
      Returns the package name of a class or interface reference descriptor, or null iff the class or interface is declared in the default package.
    • areInSamePackage

      public static boolean areInSamePackage(String d1, String d2)
      Checks whether two reference types are declared in the same package.