Top Description Fields Constructors Methods
net.bytebuddy.jar.asm

public Class TypeReference

extends Object
Class Inheritance

A reference to a type appearing in a class, field or method declaration, or on an instruction. Such a reference designates the part of the class where the referenced type is appearing (e.g. an 'extends', 'implements' or 'throws' clause, a 'new' instruction, a 'catch' clause, a type cast, a local variable declaration, etc).
Author
Eric Bruneton

Field Summary

Modifier and TypeField and Description
public static final int
CAST

The sort of type references that target the type declared in an explicit or implicit cast instruction.

public static final int
CLASS_EXTENDS

The sort of type references that target the super class of a class or one of the interfaces it implements.

public static final int
CLASS_TYPE_PARAMETER

The sort of type references that target a type parameter of a generic class.

public static final int
CLASS_TYPE_PARAMETER_BOUND

The sort of type references that target a bound of a type parameter of a generic class.

public static final int
CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT

The sort of type references that target a type parameter of a generic constructor in a constructor call.

public static final int
CONSTRUCTOR_REFERENCE

The sort of type references that target the receiver type of a constructor reference.

public static final int
CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT

The sort of type references that target a type parameter of a generic constructor in a constructor reference.

public static final int
EXCEPTION_PARAMETER

The sort of type references that target the type of the exception of a 'catch' clause in a method.

public static final int
FIELD

The sort of type references that target the type of a field.

public static final int
INSTANCEOF

The sort of type references that target the type declared in an 'instanceof' instruction.

public static final int
LOCAL_VARIABLE

The sort of type references that target the type of a local variable in a method.

public static final int
METHOD_FORMAL_PARAMETER

The sort of type references that target the type of a formal parameter of a method.

public static final int
METHOD_INVOCATION_TYPE_ARGUMENT

The sort of type references that target a type parameter of a generic method in a method call.

public static final int
METHOD_RECEIVER

The sort of type references that target the receiver type of a method.

public static final int
METHOD_REFERENCE

The sort of type references that target the receiver type of a method reference.

public static final int
METHOD_REFERENCE_TYPE_ARGUMENT

The sort of type references that target a type parameter of a generic method in a method reference.

public static final int
METHOD_RETURN

The sort of type references that target the return type of a method.

public static final int
METHOD_TYPE_PARAMETER

The sort of type references that target a type parameter of a generic method.

public static final int
METHOD_TYPE_PARAMETER_BOUND

The sort of type references that target a bound of a type parameter of a generic method.

public static final int
NEW

The sort of type references that target the type of the object created by a 'new' instruction.

public static final int
RESOURCE_VARIABLE

The sort of type references that target the type of a resource variable in a method.

private final int
targetTypeAndInfo

The target_type and target_info structures - as defined in the Java Virtual Machine Specification (JVMS) - corresponding to this type reference.

public static final int
THROWS

The sort of type references that target the type of an exception declared in the throws clause of a method.

Constructor Summary

AccessConstructor and Description
public
TypeReference(final int
the int encoded value of the type reference, as received in a visit method related to type annotations, such as ClassVisitor#visitTypeAnnotation.
typeRef
)

Constructs a new TypeReference.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the index of an exception in the 'throws' clause of a method.
getExceptionIndex
()

Returns the index of the exception, in a 'throws' clause of a method, whose type is referenced by this type reference.

public int

Returns:

a formal parameter index.
getFormalParameterIndex
()

Returns the index of the formal parameter whose type is referenced by this type reference.

public int
public int

Returns:

the index of an interface in the 'implements' clause of a class, or -1 if this type reference references the type of the super class.
getSuperTypeIndex
()

Returns the index of the "super type" of a class that is referenced by this type reference.

public int

Returns:

the index of an exception in the 'throws' clause of a method.
getTryCatchBlockIndex
()

Returns the index of the try catch block (using the order in which they are visited with visitTryCatchBlock), whose 'catch' type is referenced by this type reference.

public int

Returns:

a type parameter index.
getTypeArgumentIndex
()

Returns the index of the type argument referenced by this type reference.

public int

Returns:

a type parameter bound index.
getTypeParameterBoundIndex
()

Returns the index of the type parameter bound, within the type parameter getTypeParameterIndex, referenced by this type reference.

public int

Returns:

a type parameter index.
getTypeParameterIndex
()

Returns the index of the type parameter referenced by this type reference.

public int

Returns:

the int encoded value of this type reference.
getValue
()

Returns the int encoded value of this type reference, suitable for use in visit methods related to type annotations, like visitTypeAnnotation.

public static TypeReference

Returns:

a reference to the type of the given exception.
newExceptionReference
(final int
the index of an exception in a 'throws' clause of a method.
exceptionIndex
)

Returns a reference to the type of an exception, in a 'throws' clause of a method.

public static TypeReference

Returns:

a reference to the type of the given method formal parameter.
newFormalParameterReference
(final int
the formal parameter index.
paramIndex
)

Returns a reference to the type of a formal parameter of a method.

public static TypeReference

Returns:

a reference to the given super type of a class.
newSuperTypeReference
(final int
the index of an interface in the 'implements' clause of a class, or -1 to reference the super class of the class.
itfIndex
)

Returns a reference to the super class or to an interface of the 'implements' clause of a class.

public static TypeReference

Returns:

a reference to the type of the given exception.
newTryCatchReference
(final int
the index of a try catch block (using the order in which they are visited with visitTryCatchBlock).
tryCatchBlockIndex
)

Returns a reference to the type of the exception declared in a 'catch' clause of a method.

public static TypeReference

Returns:

a reference to the type of the given type argument.
newTypeArgumentReference
(final int sort, final int
the type argument index.
argIndex
)

Returns a reference to the type of a type argument in a constructor or method call or reference.

public static TypeReference

Returns:

a reference to the given generic class or method type parameter bound.
newTypeParameterBoundReference
(final int sort, final int
the type parameter index.
paramIndex
,
final int
the type bound index within the above type parameters.
boundIndex
)

Returns a reference to a type parameter bound of a generic class or method.

public static TypeReference

Returns:

a reference to the given generic class or method type parameter.
newTypeParameterReference
(final int sort, final int
the type parameter index.
paramIndex
)

Returns a reference to a type parameter of a generic class or method.

public static TypeReference

Returns:

a type reference of the given sort.
newTypeReference
(final int sort)

Returns a type reference of the given sort.

pack-priv static void
putTarget(final int
a target_type and a target_info structures encoded as in targetTypeAndInfo. LOCAL_VARIABLE and RESOURCE_VARIABLE target types are not supported.
targetTypeAndInfo
,
final ByteVector
where the type reference must be put.
output
)

Puts the given target_type and target_info JVMS structures into the given ByteVector.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CASTback to summary
public static final int CAST

The sort of type references that target the type declared in an explicit or implicit cast instruction. See getSort.

CLASS_EXTENDSback to summary
public static final int CLASS_EXTENDS

The sort of type references that target the super class of a class or one of the interfaces it implements. See getSort.

CLASS_TYPE_PARAMETERback to summary
public static final int CLASS_TYPE_PARAMETER

The sort of type references that target a type parameter of a generic class. See getSort.

CLASS_TYPE_PARAMETER_BOUNDback to summary
public static final int CLASS_TYPE_PARAMETER_BOUND

The sort of type references that target a bound of a type parameter of a generic class. See getSort.

CONSTRUCTOR_INVOCATION_TYPE_ARGUMENTback to summary
public static final int CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT

The sort of type references that target a type parameter of a generic constructor in a constructor call. See getSort.

CONSTRUCTOR_REFERENCEback to summary
public static final int CONSTRUCTOR_REFERENCE

The sort of type references that target the receiver type of a constructor reference. See getSort.

CONSTRUCTOR_REFERENCE_TYPE_ARGUMENTback to summary
public static final int CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT

The sort of type references that target a type parameter of a generic constructor in a constructor reference. See getSort.

EXCEPTION_PARAMETERback to summary
public static final int EXCEPTION_PARAMETER

The sort of type references that target the type of the exception of a 'catch' clause in a method. See getSort.

FIELDback to summary
public static final int FIELD

The sort of type references that target the type of a field. See getSort.

INSTANCEOFback to summary
public static final int INSTANCEOF

The sort of type references that target the type declared in an 'instanceof' instruction. See getSort.

LOCAL_VARIABLEback to summary
public static final int LOCAL_VARIABLE

The sort of type references that target the type of a local variable in a method. See getSort.

METHOD_FORMAL_PARAMETERback to summary
public static final int METHOD_FORMAL_PARAMETER

The sort of type references that target the type of a formal parameter of a method. See getSort.

METHOD_INVOCATION_TYPE_ARGUMENTback to summary
public static final int METHOD_INVOCATION_TYPE_ARGUMENT

The sort of type references that target a type parameter of a generic method in a method call. See getSort.

METHOD_RECEIVERback to summary
public static final int METHOD_RECEIVER

The sort of type references that target the receiver type of a method. See getSort.

METHOD_REFERENCEback to summary
public static final int METHOD_REFERENCE

The sort of type references that target the receiver type of a method reference. See getSort.

METHOD_REFERENCE_TYPE_ARGUMENTback to summary
public static final int METHOD_REFERENCE_TYPE_ARGUMENT

The sort of type references that target a type parameter of a generic method in a method reference. See getSort.

METHOD_RETURNback to summary
public static final int METHOD_RETURN

The sort of type references that target the return type of a method. See getSort.

METHOD_TYPE_PARAMETERback to summary
public static final int METHOD_TYPE_PARAMETER

The sort of type references that target a type parameter of a generic method. See getSort.

METHOD_TYPE_PARAMETER_BOUNDback to summary
public static final int METHOD_TYPE_PARAMETER_BOUND

The sort of type references that target a bound of a type parameter of a generic method. See getSort.

NEWback to summary
public static final int NEW

The sort of type references that target the type of the object created by a 'new' instruction. See getSort.

RESOURCE_VARIABLEback to summary
public static final int RESOURCE_VARIABLE

The sort of type references that target the type of a resource variable in a method. See getSort.

targetTypeAndInfoback to summary
private final int targetTypeAndInfo

The target_type and target_info structures - as defined in the Java Virtual Machine Specification (JVMS) - corresponding to this type reference. target_type uses one byte, and all the target_info union fields use up to 3 bytes (except localvar_target, handled with the specific method MethodVisitor#visitLocalVariableAnnotation). Thus, both structures can be stored in an int.

This int field stores target_type (called the TypeReference 'sort' in the public API of this class) in its most significant byte, followed by the target_info fields. Depending on target_type, 1, 2 or even 3 least significant bytes of this field are unused. target_info fields which reference bytecode offsets are set to 0 (these offsets are ignored in ClassReader, and recomputed in MethodWriter).

See Also
JVMS 4.7.20, JVMS 4.7.20.1
THROWSback to summary
public static final int THROWS

The sort of type references that target the type of an exception declared in the throws clause of a method. See getSort.

Constructor Detail

TypeReferenceback to summary
public TypeReference(final int typeRef)

Constructs a new TypeReference.

Parameters
typeRef:int

the int encoded value of the type reference, as received in a visit method related to type annotations, such as ClassVisitor#visitTypeAnnotation.

Method Detail

getExceptionIndexback to summary
public int getExceptionIndex()

Returns the index of the exception, in a 'throws' clause of a method, whose type is referenced by this type reference. This method must only be used for type references whose sort is THROWS.

Returns:int

the index of an exception in the 'throws' clause of a method.

getFormalParameterIndexback to summary
public int getFormalParameterIndex()

Returns the index of the formal parameter whose type is referenced by this type reference. This method must only be used for type references whose sort is METHOD_FORMAL_PARAMETER.

Returns:int

a formal parameter index.

getSortback to summary
public int getSort()

Returns the sort of this type reference.

Returns:int

one of CLASS_TYPE_PARAMETER, METHOD_TYPE_PARAMETER, CLASS_EXTENDS, CLASS_TYPE_PARAMETER_BOUND, METHOD_TYPE_PARAMETER_BOUND, FIELD, METHOD_RETURN, METHOD_RECEIVER, METHOD_FORMAL_PARAMETER, THROWS, LOCAL_VARIABLE, RESOURCE_VARIABLE, EXCEPTION_PARAMETER, INSTANCEOF, NEW, CONSTRUCTOR_REFERENCE, METHOD_REFERENCE, CAST, CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, METHOD_INVOCATION_TYPE_ARGUMENT, CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, or METHOD_REFERENCE_TYPE_ARGUMENT.

getSuperTypeIndexback to summary
public int getSuperTypeIndex()

Returns the index of the "super type" of a class that is referenced by this type reference. This method must only be used for type references whose sort is CLASS_EXTENDS.

Returns:int

the index of an interface in the 'implements' clause of a class, or -1 if this type reference references the type of the super class.

getTryCatchBlockIndexback to summary
public int getTryCatchBlockIndex()

Returns the index of the try catch block (using the order in which they are visited with visitTryCatchBlock), whose 'catch' type is referenced by this type reference. This method must only be used for type references whose sort is EXCEPTION_PARAMETER .

Returns:int

the index of an exception in the 'throws' clause of a method.

getTypeArgumentIndexback to summary
public int getTypeArgumentIndex()

Returns the index of the type argument referenced by this type reference. This method must only be used for type references whose sort is CAST, CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, METHOD_INVOCATION_TYPE_ARGUMENT, CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, or METHOD_REFERENCE_TYPE_ARGUMENT.

Returns:int

a type parameter index.

getTypeParameterBoundIndexback to summary
public int getTypeParameterBoundIndex()

Returns the index of the type parameter bound, within the type parameter getTypeParameterIndex, referenced by this type reference. This method must only be used for type references whose sort is CLASS_TYPE_PARAMETER_BOUND or METHOD_TYPE_PARAMETER_BOUND.

Returns:int

a type parameter bound index.

getTypeParameterIndexback to summary
public int getTypeParameterIndex()

Returns the index of the type parameter referenced by this type reference. This method must only be used for type references whose sort is CLASS_TYPE_PARAMETER, METHOD_TYPE_PARAMETER, CLASS_TYPE_PARAMETER_BOUND or METHOD_TYPE_PARAMETER_BOUND.

Returns:int

a type parameter index.

getValueback to summary
public int getValue()

Returns the int encoded value of this type reference, suitable for use in visit methods related to type annotations, like visitTypeAnnotation.

Returns:int

the int encoded value of this type reference.

newExceptionReferenceback to summary
public static TypeReference newExceptionReference(final int exceptionIndex)

Returns a reference to the type of an exception, in a 'throws' clause of a method.

Parameters
exceptionIndex:int

the index of an exception in a 'throws' clause of a method.

Returns:TypeReference

a reference to the type of the given exception.

newFormalParameterReferenceback to summary
public static TypeReference newFormalParameterReference(final int paramIndex)

Returns a reference to the type of a formal parameter of a method.

Parameters
paramIndex:int

the formal parameter index.

Returns:TypeReference

a reference to the type of the given method formal parameter.

newSuperTypeReferenceback to summary
public static TypeReference newSuperTypeReference(final int itfIndex)

Returns a reference to the super class or to an interface of the 'implements' clause of a class.

Parameters
itfIndex:int

the index of an interface in the 'implements' clause of a class, or -1 to reference the super class of the class.

Returns:TypeReference

a reference to the given super type of a class.

newTryCatchReferenceback to summary
public static TypeReference newTryCatchReference(final int tryCatchBlockIndex)

Returns a reference to the type of the exception declared in a 'catch' clause of a method.

Parameters
tryCatchBlockIndex:int

the index of a try catch block (using the order in which they are visited with visitTryCatchBlock).

Returns:TypeReference

a reference to the type of the given exception.

newTypeArgumentReferenceback to summary
public static TypeReference newTypeArgumentReference(final int sort, final int argIndex)

Returns a reference to the type of a type argument in a constructor or method call or reference.

Parameters
sort:int

one of CAST, CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, METHOD_INVOCATION_TYPE_ARGUMENT, CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, or METHOD_REFERENCE_TYPE_ARGUMENT.

argIndex:int

the type argument index.

Returns:TypeReference

a reference to the type of the given type argument.

newTypeParameterBoundReferenceback to summary
public static TypeReference newTypeParameterBoundReference(final int sort, final int paramIndex, final int boundIndex)

Returns a reference to a type parameter bound of a generic class or method.

Parameters
sort:int

one of CLASS_TYPE_PARAMETER or METHOD_TYPE_PARAMETER.

paramIndex:int

the type parameter index.

boundIndex:int

the type bound index within the above type parameters.

Returns:TypeReference

a reference to the given generic class or method type parameter bound.

newTypeParameterReferenceback to summary
public static TypeReference newTypeParameterReference(final int sort, final int paramIndex)

Returns a reference to a type parameter of a generic class or method.

Parameters
sort:int

one of CLASS_TYPE_PARAMETER or METHOD_TYPE_PARAMETER.

paramIndex:int

the type parameter index.

Returns:TypeReference

a reference to the given generic class or method type parameter.

newTypeReferenceback to summary
public static TypeReference newTypeReference(final int sort)

Returns a type reference of the given sort.

Parameters
sort:int

one of FIELD, METHOD_RETURN, METHOD_RECEIVER, LOCAL_VARIABLE, RESOURCE_VARIABLE, INSTANCEOF, NEW, CONSTRUCTOR_REFERENCE, or METHOD_REFERENCE.

Returns:TypeReference

a type reference of the given sort.

putTargetback to summary
pack-priv static void putTarget(final int targetTypeAndInfo, final ByteVector output)

Puts the given target_type and target_info JVMS structures into the given ByteVector.

Parameters
targetTypeAndInfo:int

a target_type and a target_info structures encoded as in targetTypeAndInfo. LOCAL_VARIABLE and RESOURCE_VARIABLE target types are not supported.

output:ByteVector

where the type reference must be put.