Package proguard.classfile.editor
Class LibraryClassBuilder
- java.lang.Object
-
- proguard.classfile.editor.LibraryClassBuilder
-
public class LibraryClassBuilder extends java.lang.Object
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
Constructors Constructor Description LibraryClassBuilder(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.LibraryClassBuilder(int u2accessFlags, java.lang.String className, java.lang.String superclassName, java.lang.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LibraryField
addAndReturnField(int u2accessFlags, java.lang.String fieldName, java.lang.String fieldDescriptor)
Adds a new field to the edited class, and returns it.LibraryMethod
addAndReturnMethod(int u2accessFlags, java.lang.String methodName, java.lang.String methodDescriptor)
Adds a new method to the edited class, and returns it.LibraryClassBuilder
addField(int u2accessFlags, java.lang.String fieldName, java.lang.String fieldDescriptor)
Adds a new field to the edited class.LibraryClassBuilder
addField(int u2accessFlags, java.lang.String fieldName, java.lang.String fieldDescriptor, MemberVisitor extraMemberVisitor)
Adds a new field to the edited class.LibraryClassBuilder
addInterface(java.lang.String interfaceName)
Adds a new interface to the edited class.LibraryClassBuilder
addInterface(java.lang.String interfaceName, Clazz referencedInterface)
Adds a new interface to the edited class.LibraryClassBuilder
addInterface(Clazz interfaceClass)
Adds a new interface to the edited class.LibraryClassBuilder
addMethod(int u2accessFlags, java.lang.String methodName, java.lang.String methodDescriptor)
Adds a new method to the edited class.LibraryClassBuilder
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.LibraryClass
getLibraryClass()
Returns the created or edited LibraryClass instance.
-
-
-
Constructor Detail
-
LibraryClassBuilder
public LibraryClassBuilder(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.- 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:
VersionConstants
,AccessConstants
-
LibraryClassBuilder
public LibraryClassBuilder(int u2accessFlags, java.lang.String className, java.lang.String superclassName, java.lang.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:
VersionConstants
,AccessConstants
-
LibraryClassBuilder
public LibraryClassBuilder(LibraryClass libraryClass)
Creates a new ClassBuilder for the given class.- Parameters:
libraryClass
- the class to be edited.
-
-
Method Detail
-
getLibraryClass
public LibraryClass 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
public ConstantPoolEditor getConstantPoolEditor()
Returns a ConstantPoolEditor instance for the created or edited class instance. Reusing this instance is more efficient for newly created classes.
-
addInterface
public LibraryClassBuilder addInterface(Clazz interfaceClass)
Adds a new interface to the edited class.- Parameters:
interfaceClass
- the interface class.- Returns:
- this instance of ClassBuilder.
-
addInterface
public LibraryClassBuilder addInterface(java.lang.String interfaceName)
Adds a new interface to the edited class.- Parameters:
interfaceName
- the name of the interface.- Returns:
- this instance of ClassBuilder.
-
addInterface
public LibraryClassBuilder addInterface(java.lang.String interfaceName, Clazz referencedInterface)
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
public LibraryClassBuilder addField(int u2accessFlags, java.lang.String fieldName, java.lang.String fieldDescriptor)
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, java.lang.String fieldName, java.lang.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
public LibraryField addAndReturnField(int u2accessFlags, java.lang.String fieldName, java.lang.String fieldDescriptor)
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
public LibraryClassBuilder addMethod(int u2accessFlags, java.lang.String methodName, java.lang.String methodDescriptor)
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, java.lang.String methodName, java.lang.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, java.lang.String methodName, java.lang.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.
-
-