Package org.objectweb.asm.test
Class ClassFile.AbstractBuilder<T>
- java.lang.Object
-
- org.objectweb.asm.test.ClassFile.AbstractBuilder<T>
-
- All Implemented Interfaces:
ClassFile.ClassContext
,ClassFile.MethodContext
- Direct Known Subclasses:
ClassFile.Builder
,ClassFile.SortedBuilder
- Enclosing class:
- ClassFile
private abstract static class ClassFile.AbstractBuilder<T> extends java.lang.Object implements ClassFile.ClassContext, ClassFile.MethodContext
A helper class to build the dump of a class file. The dump can't be output fully sequentially, as the input class is parsed, in particular due to the re-ordering of attributes and annotations. Instead, a tree is constructed first, then its nodes are sorted and finally the tree is parsed in Depth First Search order to build the dump. This class is the super class of the internal nodes of the tree.Each internal node is a context that can store a mapping between constant pool indices and constant pool items and between bytecode offsets and instructions indices. This can be used to resolve references to such objects. Contexts inherit from their parent, i.e. if a lookup fails in some builder, the lookup continues in the parent, and so on until the root is reached.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.ArrayList<T>
children
The children of this builder.private java.util.HashMap<java.lang.Integer,java.lang.Object>
context
The map used to implement the Context interfaces.private static int
CP_INFO_KEY
Flag used to distinguish CpInfo keys incontext
.private ClassFile.AbstractBuilder<?>
parent
The parent node of this node.
-
Constructor Summary
Constructors Constructor Description AbstractBuilder(ClassFile.AbstractBuilder<?> parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
build(java.lang.StringBuilder stringBuilder)
Recursively appends the builder's children to the given string.private java.lang.Object
get(int key)
Returns the value associated with the given key.(package private) ClassFile.CpInfo
getCpInfo(int cpIndex)
Lookup constant pool items from their index.<C extends ClassFile.CpInfo>
CgetCpInfo(int cpIndex, java.lang.Class<C> cpInfoType)
int
getInsnIndex(int bytecodeOffset)
(package private) void
putCpInfo(int cpIndex, ClassFile.CpInfo cpInfo)
Registers the CpInfo for the given constant pool index.(package private) void
putInsnIndex(int bytecodeOffset, int instructionIndex)
Registers the instruction index for the given bytecode offset.
-
-
-
Field Detail
-
CP_INFO_KEY
private static final int CP_INFO_KEY
Flag used to distinguish CpInfo keys incontext
.- See Also:
- Constant Field Values
-
parent
private final ClassFile.AbstractBuilder<?> parent
The parent node of this node. May be null.
-
children
final java.util.ArrayList<T> children
The children of this builder.
-
context
private final java.util.HashMap<java.lang.Integer,java.lang.Object> context
The map used to implement the Context interfaces.
-
-
Constructor Detail
-
AbstractBuilder
AbstractBuilder(ClassFile.AbstractBuilder<?> parent)
-
-
Method Detail
-
getCpInfo
ClassFile.CpInfo getCpInfo(int cpIndex)
Lookup constant pool items from their index.- Parameters:
cpIndex
- a constant pool item index.- Returns:
- the constant pool item at the given index.
-
getCpInfo
public <C extends ClassFile.CpInfo> C getCpInfo(int cpIndex, java.lang.Class<C> cpInfoType)
- Specified by:
getCpInfo
in interfaceClassFile.ClassContext
-
getInsnIndex
public int getInsnIndex(int bytecodeOffset)
- Specified by:
getInsnIndex
in interfaceClassFile.MethodContext
-
putCpInfo
void putCpInfo(int cpIndex, ClassFile.CpInfo cpInfo)
Registers the CpInfo for the given constant pool index.- Parameters:
cpIndex
- a constant pool item index.cpInfo
- a constant pool item.
-
putInsnIndex
void putInsnIndex(int bytecodeOffset, int instructionIndex)
Registers the instruction index for the given bytecode offset.- Parameters:
bytecodeOffset
- a bytecode offset.instructionIndex
- the index of a bytecode instruction.
-
build
void build(java.lang.StringBuilder stringBuilder)
Recursively appends the builder's children to the given string.- Parameters:
stringBuilder
- a string builder.
-
get
private java.lang.Object get(int key)
Returns the value associated with the given key.- Parameters:
key
- a context key.- Returns:
- the value associated with the given key in this context or, if not found, in the parent context (recursively).
-
-