public final class CodeAttribute extends AttributeInfo
CodeAttribute
denotes a Code_attribute structure somewhere in a ClassFile structure.
This class is not thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
CodeAttribute.ExceptionHandler
An
ExceptionHandler that can be found as a part of any CodeAttribute instances. |
static class |
CodeAttribute.Instruction
An
Instruction that can be found as a part of any CodeAttribute instances. |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NAME
The name of the Code_attribute structure.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(NodeHierarchicalVisitor nodeHierarchicalVisitor)
Accepts a
NodeHierarchicalVisitor . |
void |
addAttributeInfo(AttributeInfo attributeInfo)
Attempts to add
attributeInfo to this CodeAttribute instance. |
void |
addExceptionHandler(CodeAttribute.ExceptionHandler exceptionHandler)
Attempts to add
exceptionHandler to this CodeAttribute instance. |
void |
addInstruction(CodeAttribute.Instruction instruction)
Adds
instruction to this CodeAttribute instance. |
boolean |
containsAttributeInfo(AttributeInfo attributeInfo)
Returns
true if, and only if, this CodeAttribute instance contains attributeInfo , false otherwise. |
CodeAttribute |
copy()
Returns a copy of this
CodeAttribute instance. |
boolean |
equals(java.lang.Object object)
Returns
true if, and only if, object is an instance of CodeAttribute , and that CodeAttribute instance is equal to this CodeAttribute instance, false otherwise. |
static java.util.List<CodeAttribute> |
filter(Node node)
Returns a
List with all CodeAttribute s. |
static java.util.Optional<CodeAttribute> |
find(MethodInfo methodInfo)
Attempts to find a
CodeAttribute instance in methodInfo . |
AttributeInfo |
getAttributeInfo(AttributeInfo attributeInfo)
|
AttributeInfo |
getAttributeInfo(int index)
Returns an
AttributeInfo given its index. |
int |
getAttributeInfoCount()
Returns the attributes_count of this
CodeAttribute instance. |
java.util.List<AttributeInfo> |
getAttributeInfos()
Returns a
List with all currently added AttributeInfo s. |
int |
getAttributeLength()
Returns the attribute_length of this
CodeAttribute instance. |
int |
getCodeLength()
Returns the code_length of this
CodeAttribute instance. |
java.util.List<CodeAttribute.ExceptionHandler> |
getExceptionHandlers()
Returns a
List with all currently added ExceptionHandler s. |
int |
getExceptionTableLength()
Returns the exception_table_length of this
CodeAttribute instance. |
java.util.List<CodeAttribute.Instruction> |
getInstructions()
Returns a
List with all currently added Instruction s. |
int |
getMaxLocals()
Returns the max_locals of this
CodeAttribute instance. |
int |
getMaxStack()
Returns the max_stack of this
CodeAttribute instance. |
int |
hashCode()
Returns a hash code for this
CodeAttribute instance. |
static CodeAttribute |
newInstance(int attributeNameIndex)
Returns a new
CodeAttribute instance. |
void |
removeAttributeInfo(AttributeInfo attributeInfo)
Attempts to remove
attributeInfo from this CodeAttribute instance. |
void |
removeExceptionHandler(CodeAttribute.ExceptionHandler exceptionHandler)
Attempts to remove
exceptionHandler from this CodeAttribute instance. |
void |
removeInstruction(CodeAttribute.Instruction instruction)
Attempts to remove
instruction from this CodeAttribute instance. |
void |
setMaxLocals(int maxLocals)
Sets a new max_locals for this
CodeAttribute instance. |
void |
setMaxStack(int maxStack)
Sets a new max_stack for this
CodeAttribute instance. |
java.lang.String |
toString()
Returns a
String representation of this CodeAttribute instance. |
void |
write(java.io.DataOutput dataOutput)
Writes this
CodeAttribute to dataOutput . |
getAttributeNameIndex, getName, setAttributeNameIndex
public static final java.lang.String NAME
public AttributeInfo getAttributeInfo(AttributeInfo attributeInfo)
AttributeInfo
instance of this CodeAttribute
instance that is equal to attributeInfo
.
If attributeInfo
is null
, a NullPointerException
will be thrown.
If this CodeAttribute
instance does not contain an AttributeInfo
instance that is equal to attributeInfo
, an IllegalArgumentException
will be thrown.
attributeInfo
- the AttributeInfo
instance to test for equality againstAttributeInfo
instance of this CodeAttribute
instance that is equal to attributeInfo
java.lang.IllegalArgumentException
- thrown if, and only if, this CodeAttribute
instance does not contain an AttributeInfo
instance that is equal to attributeInfo
java.lang.NullPointerException
- thrown if, and only if, attributeInfo
is null
public AttributeInfo getAttributeInfo(int index)
AttributeInfo
given its index.
If index
is less than 0
, or greater than or equal to getAttributeInfoCount()
, an IndexOutOfBoundsException
will be thrown.
index
- the index of the AttributeInfo
AttributeInfo
given its indexjava.lang.IndexOutOfBoundsException
- thrown if, and only if, index
is less than 0
, or greater than or equal to getAttributeInfoCount()
public CodeAttribute copy()
CodeAttribute
instance.copy
in class AttributeInfo
CodeAttribute
instancepublic java.util.List<AttributeInfo> getAttributeInfos()
List
with all currently added AttributeInfo
s.
Modifying the returned List
will not affect this CodeAttribute
instance.
List
with all currently added AttributeInfo
spublic java.util.List<CodeAttribute.ExceptionHandler> getExceptionHandlers()
List
with all currently added ExceptionHandler
s.
Modifying the returned List
will not affect this CodeAttribute
instance.
List
with all currently added ExceptionHandler
spublic java.util.List<CodeAttribute.Instruction> getInstructions()
List
with all currently added Instruction
s.
Modifying the returned List
will not affect this CodeAttribute
instance.
List
with all currently added Instruction
spublic java.lang.String toString()
String
representation of this CodeAttribute
instance.toString
in class java.lang.Object
String
representation of this CodeAttribute
instancepublic boolean accept(NodeHierarchicalVisitor nodeHierarchicalVisitor)
NodeHierarchicalVisitor
.
Returns the result of nodeHierarchicalVisitor.visitLeave(this)
.
If nodeHierarchicalVisitor
is null
, a NullPointerException
will be thrown.
If a RuntimeException
is thrown by the current NodeHierarchicalVisitor
, a NodeTraversalException
will be thrown with the RuntimeException
wrapped.
This implementation will:
NullPointerException
if nodeHierarchicalVisitor
is null
.NodeTraversalException
if nodeHierarchicalVisitor
throws a RuntimeException
.Node
s, if it has any.nodeHierarchicalVisitor
- the NodeHierarchicalVisitor
to acceptnodeHierarchicalVisitor.visitLeave(this)
NodeTraversalException
- thrown if, and only if, a RuntimeException
is thrown by the current NodeHierarchicalVisitor
java.lang.NullPointerException
- thrown if, and only if, nodeHierarchicalVisitor
is null
public boolean containsAttributeInfo(AttributeInfo attributeInfo)
true
if, and only if, this CodeAttribute
instance contains attributeInfo
, false
otherwise.
If attributeInfo
is null
, a NullPointerException
will be thrown.
attributeInfo
- the AttributeInfo
to checktrue
if, and only if, this CodeAttribute
instance contains attributeInfo
, false
otherwisejava.lang.NullPointerException
- thrown if, and only if, attributeInfo
is null
public boolean equals(java.lang.Object object)
true
if, and only if, object
is an instance of CodeAttribute
, and that CodeAttribute
instance is equal to this CodeAttribute
instance, false
otherwise.equals
in class java.lang.Object
object
- an Object
to compare to this CodeAttribute
instance for equalitytrue
if, and only if, object
is an instance of CodeAttribute
, and that CodeAttribute
instance is equal to this CodeAttribute
instance, false
otherwisepublic int getAttributeInfoCount()
CodeAttribute
instance.CodeAttribute
instancepublic int getAttributeLength()
CodeAttribute
instance.getAttributeLength
in class AttributeInfo
CodeAttribute
instancepublic int getCodeLength()
CodeAttribute
instance.CodeAttribute
instancepublic int getExceptionTableLength()
CodeAttribute
instance.CodeAttribute
instancepublic int getMaxLocals()
CodeAttribute
instance.CodeAttribute
instancepublic int getMaxStack()
CodeAttribute
instance.CodeAttribute
instancepublic int hashCode()
CodeAttribute
instance.hashCode
in class java.lang.Object
CodeAttribute
instancepublic void addAttributeInfo(AttributeInfo attributeInfo)
attributeInfo
to this CodeAttribute
instance.
If attributeInfo
is null
, a NullPointerException
will be thrown.
If attributeInfo
(or an AttributeInfo
instance that equals attributeInfo
) has already been added prior to this method call, nothing will happen.
attributeInfo
- the AttributeInfo
to addjava.lang.NullPointerException
- thrown if, and only if, attributeInfo
is null
public void addExceptionHandler(CodeAttribute.ExceptionHandler exceptionHandler)
exceptionHandler
to this CodeAttribute
instance.
If exceptionHandler
is null
, a NullPointerException
will be thrown.
If exceptionHandler
(or an ExceptionHandler
instance that equals exceptionHandler
) has already been added prior to this method call, nothing will happen.
exceptionHandler
- the ExceptionHandler
to addjava.lang.NullPointerException
- thrown if, and only if, exceptionHandler
is null
public void addInstruction(CodeAttribute.Instruction instruction)
instruction
to this CodeAttribute
instance.
If instruction
is null
, a NullPointerException
will be thrown.
instruction
- the Instruction
to addjava.lang.NullPointerException
- thrown if, and only if, instruction
is null
public void removeAttributeInfo(AttributeInfo attributeInfo)
attributeInfo
from this CodeAttribute
instance.
If attributeInfo
is null
, a NullPointerException
will be thrown.
If no AttributeInfo
equal to attributeInfo
can be found, nothing will happen.
attributeInfo
- the AttributeInfo
to removejava.lang.NullPointerException
- thrown if, and only if, attributeInfo
is null
public void removeExceptionHandler(CodeAttribute.ExceptionHandler exceptionHandler)
exceptionHandler
from this CodeAttribute
instance.
If exceptionHandler
is null
, a NullPointerException
will be thrown.
If no ExceptionHandler
equal to exceptionHandler
can be found, nothing will happen.
exceptionHandler
- the ExceptionHandler
to removejava.lang.NullPointerException
- thrown if, and only if, exceptionHandler
is null
public void removeInstruction(CodeAttribute.Instruction instruction)
instruction
from this CodeAttribute
instance.
If instruction
is null
, a NullPointerException
will be thrown.
If no Instruction
equal to instruction
can be found, nothing will happen.
instruction
- the Instruction
to removejava.lang.NullPointerException
- thrown if, and only if, instruction
is null
public void setMaxLocals(int maxLocals)
CodeAttribute
instance.
If maxLocals
is less than 0
, an IllegalArgumentException
will be thrown.
maxLocals
- the new max_locals for this CodeAttribute
instancejava.lang.IllegalArgumentException
- thrown if, and only if, maxLocals
is less than 0
public void setMaxStack(int maxStack)
CodeAttribute
instance.
If maxStack
is less than 0
, an IllegalArgumentException
will be thrown.
maxStack
- the new max_stack for this CodeAttribute
instancejava.lang.IllegalArgumentException
- thrown if, and only if, maxStack
is less than 0
public void write(java.io.DataOutput dataOutput)
CodeAttribute
to dataOutput
.
If dataOutput
is an OutputStream
(or any other type of stream), this method will not close it.
If dataOutput
is null
, a NullPointerException
will be thrown.
If an I/O-error occurs, an UncheckedIOException
will be thrown.
write
in class AttributeInfo
dataOutput
- the DataOutput
to write tojava.lang.NullPointerException
- thrown if, and only if, dataOutput
is null
java.io.UncheckedIOException
- thrown if, and only if, an I/O-error occurspublic static CodeAttribute newInstance(int attributeNameIndex)
CodeAttribute
instance.
If attributeNameIndex
is less than or equal to 0
, an IllegalArgumentException
will be thrown.
attributeNameIndex
- the attribute_name_index of the new CodeAttribute
instanceCodeAttribute
instancejava.lang.IllegalArgumentException
- thrown if, and only if, attributeNameIndex
is less than or equal to 0
public static java.util.List<CodeAttribute> filter(Node node)
List
with all CodeAttribute
s.
All CodeAttribute
s are found by traversing node
using a simple NodeHierarchicalVisitor
implementation.
If node
is null
, a NullPointerException
will be thrown.
node
- the Node
to start traversal fromList
with all CodeAttribute
sjava.lang.NullPointerException
- thrown if, and only if, node
is null
public static java.util.Optional<CodeAttribute> find(MethodInfo methodInfo)
CodeAttribute
instance in methodInfo
.
Returns an Optional
with the optional CodeAttribute
instance.
If methodInfo
is null
, a NullPointerException
will be thrown.
methodInfo
- the MethodInfo
to check inOptional
with the optional CodeAttribute
instancejava.lang.NullPointerException
- thrown if, and only if, methodInfo
is null