Package proguard.classfile.editor
Class LibraryClassBuilder
java.lang.Object
proguard.classfile.editor.LibraryClassBuilder
This editor allows to build or extend classes (
LibraryClass instances). It provides
methods to easily add interfaces, fields, and methods, optionally with method bodies.
If you're adding many fields and methods, it is more efficient to reuse a single instance of this builder for all fields and methods that you add.
-
Constructor Summary
ConstructorsConstructorDescriptionLibraryClassBuilder(int u2accessFlags, String className, String superclassName) Creates a new ClassBuilder for the Java class with the given name and super class.LibraryClassBuilder(int u2accessFlags, String className, String superclassName, String[] interfaceNames, Clazz[] interfaceClasses, int subClassCount, Clazz[] subClasses, LibraryField[] fields, LibraryMethod[] methods, KotlinMetadata kotlinMetadata) Creates a new ClassBuilder for the Java class with the given name and super class.LibraryClassBuilder(LibraryClass libraryClass) Creates a new ClassBuilder for the given class. -
Method Summary
Modifier and TypeMethodDescriptionaddAndReturnField(int u2accessFlags, String fieldName, String fieldDescriptor) Adds a new field to the edited class, and returns it.addAndReturnMethod(int u2accessFlags, String methodName, String methodDescriptor) Adds a new method to the edited class, and returns it.Adds a new field to the edited class.addField(int u2accessFlags, String fieldName, String fieldDescriptor, MemberVisitor extraMemberVisitor) Adds a new field to the edited class.addInterface(String interfaceName) Adds a new interface to the edited class.addInterface(String interfaceName, Clazz referencedInterface) Adds a new interface to the edited class.addInterface(Clazz interfaceClass) Adds a new interface to the edited class.Adds a new method to the edited class.addMethod(int u2accessFlags, String methodName, String methodDescriptor, MemberVisitor extraMemberVisitor) Adds a new method to the edited class.Returns a ConstantPoolEditor instance for the created or edited class instance.Returns the created or edited LibraryClass instance.
-
Constructor Details
-
LibraryClassBuilder
Creates a new ClassBuilder for the Java class with the given name and super class.- Parameters:
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.- See Also:
-
LibraryClassBuilder
public LibraryClassBuilder(int u2accessFlags, String className, String superclassName, String[] interfaceNames, Clazz[] interfaceClasses, int subClassCount, Clazz[] subClasses, LibraryField[] fields, LibraryMethod[] methods, KotlinMetadata kotlinMetadata) Creates a new ClassBuilder for the Java class with the given name and super class.- Parameters:
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.interfaceNames- the names of the interfaces that are implemented by this class.interfaceClasses- references to the interface classes of the interfaces that are implemented by this class.subClassCount- the number of subclasses of this class.subClasses- references to the subclasses of this class.fields- references to the fields of this class.methods- references to the methods of this class.kotlinMetadata- the metadata attached to this class if it is a Kotlin class- See Also:
-
LibraryClassBuilder
Creates a new ClassBuilder for the given class.- Parameters:
libraryClass- the class to be edited.
-
-
Method Details
-
getLibraryClass
Returns the created or edited LibraryClass instance. This is a live instance; any later calls to the builder will still affect the instance. -
getConstantPoolEditor
Returns a ConstantPoolEditor instance for the created or edited class instance. Reusing this instance is more efficient for newly created classes. -
addInterface
Adds a new interface to the edited class.- Parameters:
interfaceClass- the interface class.- Returns:
- this instance of ClassBuilder.
-
addInterface
Adds a new interface to the edited class.- Parameters:
interfaceName- the name of the interface.- Returns:
- this instance of ClassBuilder.
-
addInterface
Adds a new interface to the edited class.- Parameters:
interfaceName- the name of the interface.referencedInterface- the referenced interface.- Returns:
- this instance of ClassBuilder.
-
addField
Adds a new field to the edited class.- Parameters:
u2accessFlags- access flags for the new field.fieldName- name of the new field.fieldDescriptor- descriptor of the new field.- Returns:
- this instance of ClassBuilder.
-
addField
public LibraryClassBuilder addField(int u2accessFlags, String fieldName, String fieldDescriptor, MemberVisitor extraMemberVisitor) Adds a new field to the edited class.- Parameters:
u2accessFlags- access flags for the new field.fieldName- name of the new field.fieldDescriptor- descriptor of the new field.- Returns:
- this instance of ClassBuilder.
-
addAndReturnField
Adds a new field to the edited class, and returns it.- Parameters:
u2accessFlags- access flags for the new field.fieldName- name of the new field.fieldDescriptor- descriptor of the new field.- Returns:
- the newly created field.
-
addMethod
Adds a new method to the edited class.- Parameters:
u2accessFlags- the access flags of the new method.methodName- the name of the new method.methodDescriptor- the descriptor of the new method.- Returns:
- this instance of ClassBuilder.
-
addMethod
public LibraryClassBuilder addMethod(int u2accessFlags, String methodName, String methodDescriptor, MemberVisitor extraMemberVisitor) Adds a new method to the edited class.- Parameters:
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.- Returns:
- this instance of ClassBuilder.
-
addAndReturnMethod
public LibraryMethod addAndReturnMethod(int u2accessFlags, String methodName, String methodDescriptor) Adds a new method to the edited class, and returns it.- Parameters:
u2accessFlags- the access flags of the new method.methodName- the name of the new method.methodDescriptor- the descriptor of the new method.- Returns:
- the newly created method.
-