public class SignatureAttribute extends Attribute
Classfiles need to carry generic type information in a backwards compatible way. This is accomplished by introducing a new "Signature" attribute for classes, methods and fields. The structure of this attribute is as follows:
"Signature" (u4 attr-length, u2 signature-index)When used as an attribute of a method or field, a signature gives the full (possibly generic) type of that method or field. When used as a class attribute, a signature indicates the type parameters of the class, followed by its supertype, followed by all its interfaces.
The type syntax in signatures is extended to parameterized types and type variables. There is also a new signature syntax for formal type parameters. The syntax extensions for signature strings are as follows:
MethodOrFieldSignature ::= TypeSignature ClassSignature ::= ParameterPartOpt super_TypeSignature interface_TypeSignatures TypeSignatures ::= TypeSignatures TypeSignature | TypeSignature ::= ... | ClassTypeSignature | MethodTypeSignature | TypeVariableSignature ClassTypeSignature ::= 'L' Ident TypeArgumentsOpt ';' | ClassTypeSignature '.' Ident ';' TypeArgumentsOpt MethodTypeSignature ::= TypeArgumentsOpt '(' TypeSignatures ')' TypeSignature ThrowsSignatureListOpt ThrowsSignatureList ::= ThrowsSignature ThrowsSignatureList | ThrowsSignature ThrowsSignature ::= '^' TypeSignature TypeVariableSignature ::= 'T' Ident ';' TypeArguments ::= '<' TypeSignature TypeSignatures '>' ParameterPart ::= '<' ParameterSignature ParameterSignatures '>' ParameterSignatures ::= ParameterSignatures ParameterSignature | ParameterSignature ::= Ident ':' bound_TypeSignature
Constructor and Description |
---|
SignatureAttribute() |
SignatureAttribute(String signature) |
Modifier and Type | Method and Description |
---|---|
protected Attribute |
read(ClassReader cr,
int off,
int len,
char[] buf,
int codeOff,
Label[] labels)
Reads a
type attribute. |
String |
toString() |
protected ByteVector |
write(ClassWriter cw,
byte[] code,
int len,
int maxStack,
int maxLocals)
Returns the byte array form of this attribute.
|
public String signature
public SignatureAttribute()
public SignatureAttribute(String signature)
protected Attribute read(ClassReader cr, int off, int len, char[] buf, int codeOff, Label[] labels)
Attribute
type
attribute. This method must return a new
Attribute
object, of type type
, corresponding to the
len bytes starting at the given offset, in the given class reader.read
in class Attribute
cr
- the class that contains the attribute to be read.off
- index of the first byte of the attribute's content in cr.b
. The 6 attribute header bytes, containing the type
and the length of the attribute, are not taken into account here.len
- the length of the attribute's content.buf
- buffer to be used to call readUTF8
,
readClass
or readConst
.codeOff
- index of the first byte of code's attribute content in
cr.b
, or -1 if the attribute to be read is not a
code attribute. The 6 attribute header bytes, containing the type and
the length of the attribute, are not taken into account here.labels
- the labels of the method's code, or null if the
attribute to be read is not a code attribute.Attribute
object corresponding to the given
bytes.protected ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals)
Attribute
write
in class Attribute
cw
- the class to which this attribute must be added. This parameter
can be used to add to the constant pool of this class the items that
corresponds to this attribute.code
- the bytecode of the method corresponding to this code
attribute, or null if this attribute is not a code
attributes.len
- the length of the bytecode of the method corresponding to this
code attribute, or null if this attribute is not a code
attribute.maxStack
- the maximum stack size of the method corresponding to this
code attribute, or -1 if this attribute is not a code attribute.maxLocals
- the maximum number of local variables of the method
corresponding to this code attribute, or -1 if this attribute is not
a code attribute.Copyright © 2023. All rights reserved.