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

public Class Attribute

extends Object
Class Inheritance
Known Direct Subclasses
net.bytebuddy.jar.asm.commons.ModuleHashesAttribute

A non standard class, field, method or Code attribute, as defined in the Java Virtual Machine Specification (JVMS).
Authors
Eric Bruneton, Eugene Kuleshov
See Also
JVMS 4.7, JVMS 4.7.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Attribute.Set

A set of attribute prototypes (attributes with the same type are considered equal).

Field Summary

Modifier and TypeField and Description
private byte[]
content

The raw content of this attribute, only used for unknown attributes (see isUnknown()).

pack-priv Attribute
nextAttribute

The next attribute in this attribute list (Attribute instances can be linked via this field to store a list of class, field, method or Code attributes).

public final String
type

The type of this attribute, also called its name in the JVMS.

Constructor Summary

AccessConstructor and Description
protected
Attribute(final String
the type of the attribute.
type
)

Constructs a new empty attribute.

Method Summary

Modifier and TypeMethod and Description
pack-priv final int

Returns:

the size of all the attributes in this attribute list. This size includes the size of the attribute headers.
computeAttributesSize
(final SymbolTable
where the constants used in the attributes must be stored.
symbolTable
)

Returns the total size in bytes of all the attributes in the attribute list that begins with this attribute.

pack-priv final int

Returns:

the size of all the attributes in this attribute list. This size includes the size of the attribute headers.
computeAttributesSize
(final SymbolTable
where the constants used in the attributes must be stored.
symbolTable
,
final byte[]
the bytecode of the method corresponding to these Code attributes, or null if they are not Code attributes. Corresponds to the 'code' field of the Code attribute.
code
,
final int
the length of the bytecode of the method corresponding to these code attributes, or 0 if they are not Code attributes. Corresponds to the 'code_length' field of the Code attribute.
codeLength
,
final int
the maximum stack size of the method corresponding to these Code attributes, or -1 if they are not Code attributes.
maxStack
,
final int
the maximum number of local variables of the method corresponding to these Code attributes, or -1 if they are not Code attribute.
maxLocals
)

Returns the total size in bytes of all the attributes in the attribute list that begins with this attribute.

pack-priv static int

Returns:

the size of all the attributes in bytes. This size includes the size of the attribute headers.
computeAttributesSize
(final SymbolTable
where the constants used in the attributes must be stored.
symbolTable
,
final int
some field, method or class access flags.
accessFlags
,
final int
the constant pool index of a field, method of class signature.
signatureIndex
)

Returns the total size in bytes of all the attributes that correspond to the given field, method or class access flags and signature.

pack-priv final int

Returns:

the number of attributes of the attribute list that begins with this attribute.
getAttributeCount
()

Returns the number of attributes of the attribute list that begins with this attribute.

protected Label[]

Returns:

the labels corresponding to this attribute, or null if this attribute is not a Code attribute that contains labels.
getLabels
()

Returns the labels corresponding to this attribute.

public boolean

Returns:

true if this type of attribute is a Code attribute.
isCodeAttribute
()

Returns true if this type of attribute is a Code attribute.

public boolean

Returns:

true if this type of attribute is unknown.
isUnknown
()

Returns true if this type of attribute is unknown.

pack-priv final void
putAttributes(final SymbolTable
where the constants used in the attributes must be stored.
symbolTable
,
final ByteVector
where the attributes must be written.
output
)

Puts all the attributes of the attribute list that begins with this attribute, in the given byte vector.

pack-priv final void
putAttributes(final SymbolTable
where the constants used in the attributes must be stored.
symbolTable
,
final byte[]
the bytecode of the method corresponding to these Code attributes, or null if they are not Code attributes. Corresponds to the 'code' field of the Code attribute.
code
,
final int
the length of the bytecode of the method corresponding to these code attributes, or 0 if they are not Code attributes. Corresponds to the 'code_length' field of the Code attribute.
codeLength
,
final int
the maximum stack size of the method corresponding to these Code attributes, or -1 if they are not Code attributes.
maxStack
,
final int
the maximum number of local variables of the method corresponding to these Code attributes, or -1 if they are not Code attribute.
maxLocals
,
final ByteVector
where the attributes must be written.
output
)

Puts all the attributes of the attribute list that begins with this attribute, in the given byte vector.

pack-priv static void
putAttributes(final SymbolTable
where the constants used in the attributes must be stored.
symbolTable
,
final int
some field, method or class access flags.
accessFlags
,
final int
the constant pool index of a field, method of class signature.
signatureIndex
,
final ByteVector
where the attributes must be written.
output
)

Puts all the attributes that correspond to the given field, method or class access flags and signature, in the given byte vector.

protected Attribute

Returns:

a new Attribute object corresponding to the specified bytes.
read
(final ClassReader
the class that contains the attribute to be read.
classReader
,
final int
index of the first byte of the attribute's content in ClassReader. The 6 attribute header bytes (attribute_name_index and attribute_length) are not taken into account here.
offset
,
final int
the length of the attribute's content (excluding the 6 attribute header bytes).
length
,
final char[]
the buffer to be used to call the ClassReader methods requiring a 'charBuffer' parameter.
charBuffer
,
final int
index of the first byte of content of the enclosing Code attribute in ClassReader, or -1 if the attribute to be read is not a Code attribute. The 6 attribute header bytes (attribute_name_index and attribute_length) are not taken into account here.
codeAttributeOffset
,
final Label[]
the labels of the method's code, or null if the attribute to be read is not a Code attribute.
labels
)

Reads a type attribute.

protected ByteVector

Returns:

the byte array form of this attribute.
write
(final ClassWriter
the class to which this attribute must be added. This parameter can be used to add the items that corresponds to this attribute to the constant pool of this class.
classWriter
,
final byte[]
the bytecode of the method corresponding to this Code attribute, or null if this attribute is not a Code attribute. Corresponds to the 'code' field of the Code attribute.
code
,
final int
the length of the bytecode of the method corresponding to this code attribute, or 0 if this attribute is not a Code attribute. Corresponds to the 'code_length' field of the Code attribute.
codeLength
,
final int
the maximum stack size of the method corresponding to this Code attribute, or -1 if this attribute is not a Code attribute.
maxStack
,
final int
the maximum number of local variables of the method corresponding to this code attribute, or -1 if this attribute is not a Code attribute.
maxLocals
)

Returns the byte array form of the content of this attribute.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentback to summary
private byte[] content

The raw content of this attribute, only used for unknown attributes (see isUnknown()). The 6 header bytes of the attribute (attribute_name_index and attribute_length) are not included.

nextAttributeback to summary
pack-priv Attribute nextAttribute

The next attribute in this attribute list (Attribute instances can be linked via this field to store a list of class, field, method or Code attributes). May be null.

typeback to summary
public final String type

The type of this attribute, also called its name in the JVMS.

Constructor Detail

Attributeback to summary
protected Attribute(final String type)

Constructs a new empty attribute.

Parameters
type:String

the type of the attribute.

Method Detail

computeAttributesSizeback to summary
pack-priv final int computeAttributesSize(final SymbolTable symbolTable)

Returns the total size in bytes of all the attributes in the attribute list that begins with this attribute. This size includes the 6 header bytes (attribute_name_index and attribute_length) per attribute. Also adds the attribute type names to the constant pool.

Parameters
symbolTable:SymbolTable

where the constants used in the attributes must be stored.

Returns:int

the size of all the attributes in this attribute list. This size includes the size of the attribute headers.

computeAttributesSizeback to summary
pack-priv final int computeAttributesSize(final SymbolTable symbolTable, final byte[] code, final int codeLength, final int maxStack, final int maxLocals)

Returns the total size in bytes of all the attributes in the attribute list that begins with this attribute. This size includes the 6 header bytes (attribute_name_index and attribute_length) per attribute. Also adds the attribute type names to the constant pool.

Parameters
symbolTable:SymbolTable

where the constants used in the attributes must be stored.

code:byte[]

the bytecode of the method corresponding to these Code attributes, or null if they are not Code attributes. Corresponds to the 'code' field of the Code attribute.

codeLength:int

the length of the bytecode of the method corresponding to these code attributes, or 0 if they are not Code attributes. Corresponds to the 'code_length' field of the Code attribute.

maxStack:int

the maximum stack size of the method corresponding to these Code attributes, or -1 if they are not Code attributes.

maxLocals:int

the maximum number of local variables of the method corresponding to these Code attributes, or -1 if they are not Code attribute.

Returns:int

the size of all the attributes in this attribute list. This size includes the size of the attribute headers.

computeAttributesSizeback to summary
pack-priv static int computeAttributesSize(final SymbolTable symbolTable, final int accessFlags, final int signatureIndex)

Returns the total size in bytes of all the attributes that correspond to the given field, method or class access flags and signature. This size includes the 6 header bytes (attribute_name_index and attribute_length) per attribute. Also adds the attribute type names to the constant pool.

Parameters
symbolTable:SymbolTable

where the constants used in the attributes must be stored.

accessFlags:int

some field, method or class access flags.

signatureIndex:int

the constant pool index of a field, method of class signature.

Returns:int

the size of all the attributes in bytes. This size includes the size of the attribute headers.

getAttributeCountback to summary
pack-priv final int getAttributeCount()

Returns the number of attributes of the attribute list that begins with this attribute.

Returns:int

the number of attributes of the attribute list that begins with this attribute.

getLabelsback to summary
protected Label[] getLabels()

Returns the labels corresponding to this attribute.

Returns:Label[]

the labels corresponding to this attribute, or null if this attribute is not a Code attribute that contains labels.

isCodeAttributeback to summary
public boolean isCodeAttribute()

Returns true if this type of attribute is a Code attribute.

Returns:boolean

true if this type of attribute is a Code attribute.

isUnknownback to summary
public boolean isUnknown()

Returns true if this type of attribute is unknown. This means that the attribute content can't be parsed to extract constant pool references, labels, etc. Instead, the attribute content is read as an opaque byte array, and written back as is. This can lead to invalid attributes, if the content actually contains constant pool references, labels, or other symbolic references that need to be updated when there are changes to the constant pool, the method bytecode, etc. The default implementation of this method always returns true.

Returns:boolean

true if this type of attribute is unknown.

putAttributesback to summary
pack-priv final void putAttributes(final SymbolTable symbolTable, final ByteVector output)

Puts all the attributes of the attribute list that begins with this attribute, in the given byte vector. This includes the 6 header bytes (attribute_name_index and attribute_length) per attribute.

Parameters
symbolTable:SymbolTable

where the constants used in the attributes must be stored.

output:ByteVector

where the attributes must be written.

putAttributesback to summary
pack-priv final void putAttributes(final SymbolTable symbolTable, final byte[] code, final int codeLength, final int maxStack, final int maxLocals, final ByteVector output)

Puts all the attributes of the attribute list that begins with this attribute, in the given byte vector. This includes the 6 header bytes (attribute_name_index and attribute_length) per attribute.

Parameters
symbolTable:SymbolTable

where the constants used in the attributes must be stored.

code:byte[]

the bytecode of the method corresponding to these Code attributes, or null if they are not Code attributes. Corresponds to the 'code' field of the Code attribute.

codeLength:int

the length of the bytecode of the method corresponding to these code attributes, or 0 if they are not Code attributes. Corresponds to the 'code_length' field of the Code attribute.

maxStack:int

the maximum stack size of the method corresponding to these Code attributes, or -1 if they are not Code attributes.

maxLocals:int

the maximum number of local variables of the method corresponding to these Code attributes, or -1 if they are not Code attribute.

output:ByteVector

where the attributes must be written.

putAttributesback to summary
pack-priv static void putAttributes(final SymbolTable symbolTable, final int accessFlags, final int signatureIndex, final ByteVector output)

Puts all the attributes that correspond to the given field, method or class access flags and signature, in the given byte vector. This includes the 6 header bytes (attribute_name_index and attribute_length) per attribute.

Parameters
symbolTable:SymbolTable

where the constants used in the attributes must be stored.

accessFlags:int

some field, method or class access flags.

signatureIndex:int

the constant pool index of a field, method of class signature.

output:ByteVector

where the attributes must be written.

readback to summary
protected Attribute read(final ClassReader classReader, final int offset, final int length, final char[] charBuffer, final int codeAttributeOffset, final Label[] labels)

Reads a type attribute. This method must return a new Attribute object, of type type, corresponding to the 'length' bytes starting at 'offset', in the given ClassReader.

Parameters
classReader:ClassReader

the class that contains the attribute to be read.

offset:int

index of the first byte of the attribute's content in ClassReader. The 6 attribute header bytes (attribute_name_index and attribute_length) are not taken into account here.

length:int

the length of the attribute's content (excluding the 6 attribute header bytes).

charBuffer:char[]

the buffer to be used to call the ClassReader methods requiring a 'charBuffer' parameter.

codeAttributeOffset:int

index of the first byte of content of the enclosing Code attribute in ClassReader, or -1 if the attribute to be read is not a Code attribute. The 6 attribute header bytes (attribute_name_index and attribute_length) are not taken into account here.

labels:Label[]

the labels of the method's code, or null if the attribute to be read is not a Code attribute.

Returns:Attribute

a new Attribute object corresponding to the specified bytes.

writeback to summary
protected ByteVector write(final ClassWriter classWriter, final byte[] code, final int codeLength, final int maxStack, final int maxLocals)

Returns the byte array form of the content of this attribute. The 6 header bytes (attribute_name_index and attribute_length) must not be added in the returned ByteVector.

Parameters
classWriter:ClassWriter

the class to which this attribute must be added. This parameter can be used to add the items that corresponds to this attribute to the constant pool of this class.

code:byte[]

the bytecode of the method corresponding to this Code attribute, or null if this attribute is not a Code attribute. Corresponds to the 'code' field of the Code attribute.

codeLength:int

the length of the bytecode of the method corresponding to this code attribute, or 0 if this attribute is not a Code attribute. Corresponds to the 'code_length' field of the Code attribute.

maxStack:int

the maximum stack size of the method corresponding to this Code attribute, or -1 if this attribute is not a Code attribute.

maxLocals:int

the maximum number of local variables of the method corresponding to this code attribute, or -1 if this attribute is not a Code attribute.

Returns:ByteVector

the byte array form of this attribute.

net.bytebuddy.jar.asm back to summary

pack-priv final Class Attribute.Set

extends Object
Class Inheritance

A set of attribute prototypes (attributes with the same type are considered equal).

Field Summary

Modifier and TypeField and Description
private Attribute[]
private int
private static final int

Constructor Summary

AccessConstructor and Description
pack-priv
Set()

Method Summary

Modifier and TypeMethod and Description
private void
add(final Attribute attribute)

pack-priv void
addAttributes(final Attribute attributeList)

private boolean
contains(final Attribute attribute)

pack-priv Attribute[]
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databack to summary
private Attribute[] data
sizeback to summary
private int size
SIZE_INCREMENTback to summary
private static final int SIZE_INCREMENT

Constructor Detail

Setback to summary
pack-priv Set()

Method Detail

addback to summary
private void add(final Attribute attribute)
addAttributesback to summary
pack-priv void addAttributes(final Attribute attributeList)
containsback to summary
private boolean contains(final Attribute attribute)
toArrayback to summary
pack-priv Attribute[] toArray()