public class ClassBuilder
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
ClassBuilder.CodeBuilder
This functional interface provides a code attribute composer to
its implementation.
|
| Constructor and Description |
|---|
ClassBuilder(int u4version,
int u2accessFlags,
java.lang.String className,
java.lang.String superclassName)
Creates a new ClassBuilder for the Java class with the given
name and super class.
|
ClassBuilder(int u4version,
int u2accessFlags,
java.lang.String className,
java.lang.String superclassName,
java.lang.String featureName,
int processingFlags,
java.lang.Object processingInfo)
Creates a new ClassBuilder for the Java class with the given
name and super class.
|
ClassBuilder(ProgramClass programClass)
Creates a new ClassBuilder for the given class.
|
ClassBuilder(ProgramClass programClass,
ClassPool programClassPool,
ClassPool libraryClassPool)
Creates a new ClassBuilder for the given class, that automatically
initializes class references and class member references in new
constants.
|
| Modifier and Type | Method and Description |
|---|---|
ProgramField |
addAndReturnField(int u2accessFlags,
java.lang.String fieldName,
java.lang.String fieldDescriptor)
Adds a new field to the edited class, and returns it.
|
ProgramMethod |
addAndReturnMethod(int u2accessFlags,
java.lang.String methodName,
java.lang.String methodDescriptor)
Adds a new method to the edited class, and returns it.
|
ProgramMethod |
addAndReturnMethod(int u2accessFlags,
java.lang.String methodName,
java.lang.String methodDescriptor,
int maxCodeFragmentLength,
ClassBuilder.CodeBuilder codeBuilder)
Adds a new method with a code attribute to the edited class, and returns
it.
|
ClassBuilder |
addField(int u2accessFlags,
java.lang.String fieldName,
java.lang.String fieldDescriptor)
Adds a new field to the edited class.
|
ClassBuilder |
addField(int u2accessFlags,
java.lang.String fieldName,
java.lang.String fieldDescriptor,
MemberVisitor extraMemberVisitor)
Adds a new field to the edited class.
|
ClassBuilder |
addInterface(Clazz interfaceClass)
Adds a new interface to the edited class.
|
ClassBuilder |
addInterface(java.lang.String interfaceName)
Adds a new interface to the edited class.
|
ClassBuilder |
addInterface(java.lang.String interfaceName,
Clazz referencedInterface)
Adds a new interface to the edited class.
|
ClassBuilder |
addMethod(int u2accessFlags,
java.lang.String methodName,
java.lang.String methodDescriptor)
Adds a new method to the edited class.
|
ClassBuilder |
addMethod(int u2accessFlags,
java.lang.String methodName,
java.lang.String methodDescriptor,
int maxCodeFragmentLength,
ClassBuilder.CodeBuilder codeBuilder)
Adds a new method with a code attribute to the edited class.
|
ClassBuilder |
addMethod(int u2accessFlags,
java.lang.String methodName,
java.lang.String methodDescriptor,
int maxCodeFragmentLength,
ClassBuilder.CodeBuilder codeBuilder,
MemberVisitor extraMemberVisitor)
Adds a new method with a code attribute to the edited class.
|
ClassBuilder |
addMethod(int u2accessFlags,
java.lang.String methodName,
java.lang.String methodDescriptor,
MemberVisitor extraMemberVisitor)
Adds a new method to the edited class.
|
ConstantPoolEditor |
getConstantPoolEditor()
Returns a ConstantPoolEditor instance for the created or edited class
instance.
|
ProgramClass |
getProgramClass()
Returns the created or edited ProgramClass instance.
|
static void |
main(java.lang.String[] args)
Small sample application that illustrates the use of this class.
|
public ClassBuilder(int u4version,
int u2accessFlags,
java.lang.String className,
java.lang.String superclassName)
u4version - the class version.u2accessFlags - access flags for the new class.className - the fully qualified name of the new class.superclassName - the fully qualified name of the super class.VersionConstants,
AccessConstantspublic ClassBuilder(int u4version,
int u2accessFlags,
java.lang.String className,
java.lang.String superclassName,
java.lang.String featureName,
int processingFlags,
java.lang.Object processingInfo)
u4version - the class version.u2accessFlags - access flags for the new class.className - the fully qualified name of the new class.superclassName - the fully qualified name of the super class.featureName - an optional feature name for the new class.processingFlags - optional processing flags for the new class.processingInfo - optional processing info for the new class.VersionConstants,
AccessConstantspublic ClassBuilder(ProgramClass programClass)
programClass - the class to be edited.public ClassBuilder(ProgramClass programClass, ClassPool programClassPool, ClassPool libraryClassPool)
programClass - the class to be edited.programClassPool - the program class pool from which new constants
can be initialized.libraryClassPool - the library class pool from which new constants
can be initialized.public ProgramClass getProgramClass()
public ConstantPoolEditor getConstantPoolEditor()
public ClassBuilder addInterface(Clazz interfaceClass)
interfaceClass - the interface class.public ClassBuilder addInterface(java.lang.String interfaceName)
interfaceName - the name of the interface.public ClassBuilder addInterface(java.lang.String interfaceName, Clazz referencedInterface)
interfaceName - the name of the interface.referencedInterface - the referenced interface.public ClassBuilder addField(int u2accessFlags, java.lang.String fieldName, java.lang.String fieldDescriptor)
u2accessFlags - access flags for the new field.fieldName - name of the new field.fieldDescriptor - descriptor of the new field.public ClassBuilder addField(int u2accessFlags, java.lang.String fieldName, java.lang.String fieldDescriptor, MemberVisitor extraMemberVisitor)
u2accessFlags - access flags for the new field.fieldName - name of the new field.fieldDescriptor - descriptor of the new field.public ProgramField addAndReturnField(int u2accessFlags, java.lang.String fieldName, java.lang.String fieldDescriptor)
u2accessFlags - access flags for the new field.fieldName - name of the new field.fieldDescriptor - descriptor of the new field.public ClassBuilder addMethod(int u2accessFlags, java.lang.String methodName, java.lang.String methodDescriptor)
u2accessFlags - the access flags of the new method.methodName - the name of the new method.methodDescriptor - the descriptor of the new method.public ClassBuilder addMethod(int u2accessFlags, java.lang.String methodName, java.lang.String methodDescriptor, MemberVisitor extraMemberVisitor)
u2accessFlags - the access flags of the new method.methodName - the name of the new method.methodDescriptor - the descriptor of the new method.extraMemberVisitor - an optional visitor for the method after
it has been created and added to the class.public ProgramMethod addAndReturnMethod(int u2accessFlags, java.lang.String methodName, java.lang.String methodDescriptor)
u2accessFlags - the access flags of the new method.methodName - the name of the new method.methodDescriptor - the descriptor of the new method.public ClassBuilder addMethod(int u2accessFlags, java.lang.String methodName, java.lang.String methodDescriptor, int maxCodeFragmentLength, ClassBuilder.CodeBuilder codeBuilder)
u2accessFlags - the access flags of the new method.methodName - the name of the new method.methodDescriptor - the descriptor of the new method.maxCodeFragmentLength - the maximum length for the code fragment.codeBuilder - the provider of a composer to create code
attributes.public ClassBuilder addMethod(int u2accessFlags, java.lang.String methodName, java.lang.String methodDescriptor, int maxCodeFragmentLength, ClassBuilder.CodeBuilder codeBuilder, MemberVisitor extraMemberVisitor)
u2accessFlags - the access flags of the new method.methodName - the name of the new method.methodDescriptor - the descriptor of the new method.maxCodeFragmentLength - the maximum length for the code fragment.codeBuilder - the provider of a composer to create code
attributes.extraMemberVisitor - an optional visitor for the method after
it has been created and added to the class.public ProgramMethod addAndReturnMethod(int u2accessFlags, java.lang.String methodName, java.lang.String methodDescriptor, int maxCodeFragmentLength, ClassBuilder.CodeBuilder codeBuilder)
u2accessFlags - the access flags of the new method.methodName - the name of the new method.methodDescriptor - the descriptor of the new method.maxCodeFragmentLength - the maximum length for the code fragment.codeBuilder - the provider of a composer to create code
attributes.public static void main(java.lang.String[] args)