Package org.codehaus.janino

# 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 Summary

Fields
Modifier and Type
Field
Description
`static final String`
`BOOLEAN`
The field descriptor for the primitive type BOOLEAN.
`static final String`
`BYTE`
The field descriptor for the primitive type BYTE.
`static final String`
`CHAR`
The field descriptor for the primitive type CHAR.
`static final String`
`DOUBLE`
The field descriptor for the primitive type DOUBLE.
`static final String`
`FLOAT`
The field descriptor for the primitive type FLOAT.
`static final String`
`INT`
The field descriptor for the primitive type INT.
`static final String`
`JAVA_IO_SERIALIZABLE`
The field descriptor for the interface `Serializable`.
`static final String`
`JAVA_LANG_ANNOTATION_RETENTION`
The field descriptor for the annotation `Retention`.
`static final String`
`JAVA_LANG_ASSERTIONERROR`
The field descriptor for the class `AssertionError`.
`static final String`
`JAVA_LANG_BOOLEAN`
The field descriptor for the class `Boolean`.
`static final String`
`JAVA_LANG_BYTE`
The field descriptor for the class `Byte`.
`static final String`
`JAVA_LANG_CHARACTER`
The field descriptor for the class `Character`.
`static final String`
`JAVA_LANG_CLASS`
The field descriptor for the class `Class`.
`static final String`
`JAVA_LANG_CLONEABLE`
The field descriptor for the interface `Cloneable`.
`static final String`
`JAVA_LANG_DOUBLE`
The field descriptor for the class `Double`.
`static final String`
`JAVA_LANG_ENUM`
The field descriptor for the class `Enum`.
`static final String`
`JAVA_LANG_ERROR`
The field descriptor for the class `Error`.
`static final String`
`JAVA_LANG_EXCEPTION`
The field descriptor for the class `Exception`.
`static final String`
`JAVA_LANG_FLOAT`
The field descriptor for the class `Float`.
`static final String`
`JAVA_LANG_INTEGER`
The field descriptor for the class `Integer`.
`static final String`
`JAVA_LANG_ITERABLE`
The field descriptor for the interface `Iterable`.
`static final String`
`JAVA_LANG_LONG`
The field descriptor for the class `Long`.
`static final String`
`JAVA_LANG_OBJECT`
The field descriptor for the class `Object`.
`static final String`
`JAVA_LANG_OVERRIDE`
The field descriptor for the annotation `Override`.
`static final String`
`JAVA_LANG_RUNTIMEEXCEPTION`
The field descriptor for the class `RuntimeException`.
`static final String`
`JAVA_LANG_SHORT`
The field descriptor for the class `Short`.
`static final String`
`JAVA_LANG_STRING`
The field descriptor for the class `String`.
`static final String`
`JAVA_LANG_STRINGBUILDER`
The field descriptor for the class `StringBuilder`.
`static final String`
`JAVA_LANG_SYSTEM`
The field descriptor for the class `System`.
`static final String`
`JAVA_LANG_THROWABLE`
The field descriptor for the class `Throwable`.
`static final String`
`JAVA_LANG_VOID`
The field descriptor for the class `Void`.
`static final String`
`JAVA_UTIL_ITERATOR`
The field descriptor for the interface `Iterator`.
`static final String`
`LONG`
The field descriptor for the primitive type LONG.
`static final String`
`SHORT`
The field descriptor for the primitive type SHORT.
`static final String`
`VOID`
The field descriptor for the type `void`.

## Method Summary

Modifier and Type
Method
Description
`static boolean`
`areInSamePackage(String d1, String d2)`
Checks whether two reference types are declared in the same package.
`static String`
`fromClassName(String className)`
Converts a class name as defined by "Class.getName()" into a descriptor.
`static String`
`fromInternalForm(String internalForm)`
Converts a class name in the "internal form" as described in JVMS 4.2 into a descriptor.
`static String`
`getComponentDescriptor(String d)`
`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.
`static boolean`
`hasSize1(String d)`
`static boolean`
`hasSize2(String d)`
`static boolean`
`isArrayReference(String d)`
`static boolean`
`isClassOrInterfaceReference(String d)`
`static boolean`
`isPrimitive(String d)`
`static boolean`
`isPrimitiveNumeric(String d)`
`static boolean`
`isReference(String d)`
`static short`
`size(String d)`
`static String`
`toClassName(String d)`
Converts a field descriptor into a class name as defined by `Class.getName()`.
`static String`
`toInternalForm(String d)`
Converts a descriptor into the "internal form" as defined by JVMS 4.2.
`static String`
`toString(String d)`
Pretty-prints the given descriptor.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### VOID

public static final String VOID
The field descriptor for the type `void`.

See Also:
  - Constant Field Values

### BYTE

public static final String BYTE
The field descriptor for the primitive type BYTE.

See Also:
  - Constant Field Values

### CHAR

public static final String CHAR
The field descriptor for the primitive type CHAR.

See Also:
  - Constant Field Values

### DOUBLE

public static final String DOUBLE
The field descriptor for the primitive type DOUBLE.

See Also:
  - Constant Field Values

### FLOAT

public static final String FLOAT
The field descriptor for the primitive type FLOAT.

See Also:
  - Constant Field Values

### INT

public static final String INT
The field descriptor for the primitive type INT.

See Also:
  - Constant Field Values

### LONG

public static final String LONG
The field descriptor for the primitive type LONG.

See Also:
  - Constant Field Values

### SHORT

public static final String SHORT
The field descriptor for the primitive type SHORT.

See Also:
  - Constant Field Values

### BOOLEAN

public static final String BOOLEAN
The field descriptor for the primitive type BOOLEAN.

See Also:
  - Constant Field Values

### JAVA_LANG_ANNOTATION_RETENTION

public static final String JAVA_LANG_ANNOTATION_RETENTION
The field descriptor for the annotation `Retention`.

See Also:
  - Constant Field Values

### JAVA_LANG_OVERRIDE

public static final String JAVA_LANG_OVERRIDE
The field descriptor for the annotation `Override`.

See Also:
  - Constant Field Values

### JAVA_LANG_ASSERTIONERROR

public static final String JAVA_LANG_ASSERTIONERROR
The field descriptor for the class `AssertionError`.

See Also:
  - Constant Field Values

### JAVA_LANG_BOOLEAN

public static final String JAVA_LANG_BOOLEAN
The field descriptor for the class `Boolean`.

See Also:
  - Constant Field Values

### JAVA_LANG_BYTE

public static final String JAVA_LANG_BYTE
The field descriptor for the class `Byte`.

See Also:
  - Constant Field Values

### JAVA_LANG_CHARACTER

public static final String JAVA_LANG_CHARACTER
The field descriptor for the class `Character`.

See Also:
  - Constant Field Values

### JAVA_LANG_CLASS

public static final String JAVA_LANG_CLASS
The field descriptor for the class `Class`.

See Also:
  - Constant Field Values

### JAVA_LANG_DOUBLE

public static final String JAVA_LANG_DOUBLE
The field descriptor for the class `Double`.

See Also:
  - Constant Field Values

### JAVA_LANG_ENUM

public static final String JAVA_LANG_ENUM
The field descriptor for the class `Enum`.

See Also:
  - Constant Field Values

### JAVA_LANG_ERROR

public static final String JAVA_LANG_ERROR
The field descriptor for the class `Error`.

See Also:
  - Constant Field Values

### JAVA_LANG_EXCEPTION

public static final String JAVA_LANG_EXCEPTION
The field descriptor for the class `Exception`.

See Also:
  - Constant Field Values

### JAVA_LANG_FLOAT

public static final String JAVA_LANG_FLOAT
The field descriptor for the class `Float`.

See Also:
  - Constant Field Values

### JAVA_LANG_INTEGER

public static final String JAVA_LANG_INTEGER
The field descriptor for the class `Integer`.

See Also:
  - Constant Field Values

### JAVA_LANG_LONG

public static final String JAVA_LANG_LONG
The field descriptor for the class `Long`.

See Also:
  - Constant Field Values

### JAVA_LANG_OBJECT

public static final String JAVA_LANG_OBJECT
The field descriptor for the class `Object`.

See Also:
  - Constant Field Values

### JAVA_LANG_RUNTIMEEXCEPTION

public static final String JAVA_LANG_RUNTIMEEXCEPTION
The field descriptor for the class `RuntimeException`.

See Also:
  - Constant Field Values

### JAVA_LANG_SHORT

public static final String JAVA_LANG_SHORT
The field descriptor for the class `Short`.

See Also:
  - Constant Field Values

### JAVA_LANG_STRING

public static final String JAVA_LANG_STRING
The field descriptor for the class `String`.

See Also:
  - Constant Field Values

### JAVA_LANG_STRINGBUILDER

public static final String JAVA_LANG_STRINGBUILDER
The field descriptor for the class `StringBuilder`.

See Also:
  - Constant Field Values

### JAVA_LANG_SYSTEM

public static final String JAVA_LANG_SYSTEM
The field descriptor for the class `System`.

See Also:
  - Constant Field Values

### JAVA_LANG_THROWABLE

public static final String JAVA_LANG_THROWABLE
The field descriptor for the class `Throwable`.

See Also:
  - Constant Field Values

### JAVA_LANG_VOID

public static final String JAVA_LANG_VOID
The field descriptor for the class `Void`.

See Also:
  - Constant Field Values

### JAVA_IO_SERIALIZABLE

public static final String JAVA_IO_SERIALIZABLE
The field descriptor for the interface `Serializable`.

See Also:
  - Constant Field Values

### JAVA_LANG_CLONEABLE

public static final String JAVA_LANG_CLONEABLE
The field descriptor for the interface `Cloneable`.

See Also:
  - Constant Field Values

### JAVA_LANG_ITERABLE

public static final String JAVA_LANG_ITERABLE
The field descriptor for the interface `Iterable`.

See Also:
  - Constant Field Values

### JAVA_UTIL_ITERATOR

public static final String JAVA_UTIL_ITERATOR
The field descriptor for the interface `Iterator`.

See Also:
  - Constant Field Values

## 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

### 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.