Package proguard.classfile.editor
Class InitializerEditor
- java.lang.Object
-
- proguard.classfile.editor.InitializerEditor
-
- All Implemented Interfaces:
AttributeVisitor
public class InitializerEditor extends java.lang.Object implements AttributeVisitor
This editor allows to build and/or edit classes (ProgramClass instances). It provides methods to easily add fields and methods to classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
InitializerEditor.CodeBuilder
This functional interface provides an instruction sequence builder to its caller.
-
Constructor Summary
Constructors Constructor Description InitializerEditor(ProgramClass programClass)
Creates a new InitializerEditor for the given class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addInitializerInstructions(InitializerEditor.CodeBuilder codeBuilder)
Adds the specified initialization instructions to the edited class.void
addInitializerInstructions(Instruction[] instructions)
Adds the given initialization instructions to the edited class.void
addStaticInitializerInstructions(boolean mergeIntoExistingInitializer, InitializerEditor.CodeBuilder codeBuilder)
Adds the specified static initializer instructions to the edited class.void
addStaticInitializerInstructions(boolean mergeIntoExistingInitializer, Instruction[] instructions)
Adds the given static initializer instructions to the edited class.void
visitAnyAttribute(Clazz clazz, Attribute attribute)
Visits any Attribute instance.void
visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface proguard.classfile.attribute.visitor.AttributeVisitor
visitAnnotationDefaultAttribute, visitAnyAnnotationsAttribute, visitAnyParameterAnnotationsAttribute, visitAnyTypeAnnotationsAttribute, visitBootstrapMethodsAttribute, visitConstantValueAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitEnclosingMethodAttribute, visitExceptionsAttribute, visitInnerClassesAttribute, visitLineNumberTableAttribute, visitLocalVariableTableAttribute, visitLocalVariableTypeTableAttribute, visitMethodParametersAttribute, visitModuleAttribute, visitModuleMainClassAttribute, visitModulePackagesAttribute, visitNestHostAttribute, visitNestMembersAttribute, visitPermittedSubclassesAttribute, visitRecordAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleParameterAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleParameterAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSourceDebugExtensionAttribute, visitSourceDirAttribute, visitSourceFileAttribute, visitStackMapAttribute, visitStackMapTableAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitUnknownAttribute
-
-
-
-
Constructor Detail
-
InitializerEditor
public InitializerEditor(ProgramClass programClass)
Creates a new InitializerEditor for the given class.- Parameters:
programClass
- The class to be edited.
-
-
Method Detail
-
addStaticInitializerInstructions
public void addStaticInitializerInstructions(boolean mergeIntoExistingInitializer, InitializerEditor.CodeBuilder codeBuilder)
Adds the specified static initializer instructions to the edited class. If the class already contains a static initializer, the new instructions will be appended to the existing initializer.- Parameters:
mergeIntoExistingInitializer
- Indicates whether the instructions should be added to the existing static initializer (if it exists), or if a new method should be created, which is then called from the existing initializer.codeBuilder
- The provider of a builder to add instructions. This functional interface can conveniently be implemented as a closure.
-
addStaticInitializerInstructions
public void addStaticInitializerInstructions(boolean mergeIntoExistingInitializer, Instruction[] instructions)
Adds the given static initializer instructions to the edited class. If the class already contains a static initializer, the new instructions will be appended to the existing initializer.- Parameters:
mergeIntoExistingInitializer
- Indicates whether the instructions should be added to the existing static initializer (if it exists), or if a new method should be created, which is then called from the existing initializer.instructions
- The instructions to be added.
-
addInitializerInstructions
public void addInitializerInstructions(InitializerEditor.CodeBuilder codeBuilder)
Adds the specified initialization instructions to the edited class.- If the class doesn't contain a constructor yet, it will be created, and the instructions will be added to this constructor.
- If there is a single super-calling constructor, the instructions will be added at the beginning of its code attribute.
- If there are multiple super-calling constructors, a new private parameterless helper method will be created, to which the instructions will be added. An invocation to this new method will be added at the beginning of the code attribute of all super-calling constructors.
- Parameters:
codeBuilder
- The provider of a builder to add instructions. This functional interface can conveniently be implemented as a closure.
-
addInitializerInstructions
public void addInitializerInstructions(Instruction[] instructions)
Adds the given initialization instructions to the edited class.- If the class doesn't contain a constructor yet, it will be created, and the instructions will be added to this constructor.
- If there is a single super-calling constructor, the instructions will be added at the beginning of its code attribute.
- If there are multiple super-calling constructors, a new private parameterless helper method will be created, to which the instructions will be added. An invocation to this new method will be added at the beginning of the code attribute of all super-calling constructors.
- Parameters:
instructions
- The instructions to be added.
-
visitAnyAttribute
public void visitAnyAttribute(Clazz clazz, Attribute attribute)
Description copied from interface:AttributeVisitor
Visits any Attribute instance. The more specific default implementations of this interface delegate to this method.- Specified by:
visitAnyAttribute
in interfaceAttributeVisitor
-
visitCodeAttribute
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- Specified by:
visitCodeAttribute
in interfaceAttributeVisitor
-
-