saker.build Documentation TaskDoc JavaDoc Packages
public class Attribute
A non standard class, field, method or Code attribute, as defined in the Java Virtual Machine Specification (JVMS).
Fields
public final String
The type of this attribute, also called its name in the JVMS.
Constructors
protected
Constructs a new empty attribute.
Methods
protected Label[]
Returns the labels corresponding to this attribute.
public boolean
Returns true if this type of attribute is a Code attribute.
public boolean
Returns true if this type of attribute is unknown.
protected Attribute
read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels)
Reads a type attribute.
protected ByteVector
write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals)
Returns the byte array form of the content of this attribute.
public final String type
The type of this attribute, also called its name in the JVMS.
protected Attribute(String type)
Constructs a new empty attribute.
typethe type of the attribute.
protected Label[] getLabels()
Returns the labels corresponding to this attribute.
the labels corresponding to this attribute, or null if this attribute is not a Code attribute that contains labels.
public boolean isCodeAttribute()
Returns true if this type of attribute is a Code attribute.
true if this type of attribute is a Code attribute.
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.
true if this type of attribute is unknown.
protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, 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.
classReaderthe class that contains the attribute to be read.
offsetindex 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.
lengththe length of the attribute's content (excluding the 6 attribute header bytes).
charBufferthe buffer to be used to call the ClassReader methods requiring a 'charBuffer' parameter.
codeAttributeOffsetindex 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.
labelsthe labels of the method's code, or null if the attribute to be read is not a Code attribute.
a new Attribute object corresponding to the specified bytes.
protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, 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.
classWriterthe 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.
codethe 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.
codeLengththe 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.
maxStackthe maximum stack size of the method corresponding to this Code attribute, or -1 if this attribute is not a Code attribute.
maxLocalsthe maximum number of local variables of the method corresponding to this code attribute, or -1 if this attribute is not a Code attribute.
the byte array form of this attribute.