Package proguard.classfile.editor
Class InitializerEditor
java.lang.Object
proguard.classfile.editor.InitializerEditor
- All Implemented Interfaces:
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 ClassesModifier and TypeClassDescriptionstatic interfaceThis functional interface provides an instruction sequence builder to its caller. -
Constructor Summary
ConstructorsConstructorDescriptionInitializerEditor(ProgramClass programClass) Creates a new InitializerEditor for the given class.InitializerEditor(ProgramClass programClass, CodeAttributeEditor codeAttributeEditor) Creates a new InitializerEditor for the given class. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInitializerInstructions(InitializerEditor.CodeBuilder codeBuilder) Adds the specified initialization instructions to the edited class.voidaddInitializerInstructions(Instruction[] instructions) Adds the given initialization instructions to the edited class.voidaddStaticInitializerInstructions(boolean mergeIntoExistingInitializer, InitializerEditor.CodeBuilder codeBuilder) Adds the specified static initializer instructions to the edited class.voidaddStaticInitializerInstructions(boolean mergeIntoExistingInitializer, Instruction[] instructions) Adds the given static initializer instructions to the edited class.voidvisitAnyAttribute(Clazz clazz, Attribute attribute) Visits any Attribute instance.voidvisitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 Details
-
InitializerEditor
Creates a new InitializerEditor for the given class.- Parameters:
programClass- The class to be edited.
-
InitializerEditor
Creates a new InitializerEditor for the given class.- Parameters:
programClass- The class to be edited.codeAttributeEditor- The CodeAttributeEditor to use for code editing.
-
-
Method Details
-
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
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
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
Description copied from interface:AttributeVisitorVisits any Attribute instance. The more specific default implementations of this interface delegate to this method.- Specified by:
visitAnyAttributein interfaceAttributeVisitor
-
visitCodeAttribute
- Specified by:
visitCodeAttributein interfaceAttributeVisitor
-