Package proguard.classfile.editor
Class ConstantAdder
- java.lang.Object
-
- proguard.classfile.editor.ConstantAdder
-
- All Implemented Interfaces:
ConstantVisitor
public class ConstantAdder extends java.lang.Object implements ConstantVisitor
ThisConstantVisitor
adds all constants that it visits to the constant pool of a given target class.Bootstrap methods attributes are automatically updated for invokedynamic constants.
-
-
Constructor Summary
Constructors Constructor Description ConstantAdder(ProgramClass targetClass)
Creates a new ConstantAdder that will copy constants into the given target class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addConstant(Clazz clazz, int constantIndex)
Adds a copy of the specified constant in the given class and returns its index.int
addConstant(Clazz clazz, Constant constant)
Adds a copy of the given constant in the given class and returns its index.int
getConstantIndex()
Returns the index of the most recently created constant in the constant pool of the target class.void
visitClassConstant(Clazz clazz, ClassConstant classConstant)
void
visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant)
void
visitDynamicConstant(Clazz clazz, DynamicConstant dynamicConstant)
void
visitFieldrefConstant(Clazz clazz, FieldrefConstant fieldrefConstant)
void
visitFloatConstant(Clazz clazz, FloatConstant floatConstant)
void
visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant)
void
visitInterfaceMethodrefConstant(Clazz clazz, InterfaceMethodrefConstant interfaceMethodrefConstant)
void
visitInvokeDynamicConstant(Clazz clazz, InvokeDynamicConstant invokeDynamicConstant)
void
visitLongConstant(Clazz clazz, LongConstant longConstant)
void
visitMethodHandleConstant(Clazz clazz, MethodHandleConstant methodHandleConstant)
void
visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
void
visitMethodTypeConstant(Clazz clazz, MethodTypeConstant methodTypeConstant)
void
visitModuleConstant(Clazz clazz, ModuleConstant moduleConstant)
void
visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant)
void
visitPackageConstant(Clazz clazz, PackageConstant packageConstant)
void
visitPrimitiveArrayConstant(Clazz clazz, PrimitiveArrayConstant primitiveArrayConstant)
void
visitStringConstant(Clazz clazz, StringConstant stringConstant)
void
visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface proguard.classfile.constant.visitor.ConstantVisitor
visitAnyConstant, visitAnyMethodrefConstant, visitAnyRefConstant
-
-
-
-
Constructor Detail
-
ConstantAdder
public ConstantAdder(ProgramClass targetClass)
Creates a new ConstantAdder that will copy constants into the given target class.
-
-
Method Detail
-
addConstant
public int addConstant(Clazz clazz, int constantIndex)
Adds a copy of the specified constant in the given class and returns its index. If the specified index is 0, the returned value is 0 too.
-
addConstant
public int addConstant(Clazz clazz, Constant constant)
Adds a copy of the given constant in the given class and returns its index.
-
getConstantIndex
public int getConstantIndex()
Returns the index of the most recently created constant in the constant pool of the target class.
-
visitIntegerConstant
public void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant)
- Specified by:
visitIntegerConstant
in interfaceConstantVisitor
-
visitLongConstant
public void visitLongConstant(Clazz clazz, LongConstant longConstant)
- Specified by:
visitLongConstant
in interfaceConstantVisitor
-
visitFloatConstant
public void visitFloatConstant(Clazz clazz, FloatConstant floatConstant)
- Specified by:
visitFloatConstant
in interfaceConstantVisitor
-
visitDoubleConstant
public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant)
- Specified by:
visitDoubleConstant
in interfaceConstantVisitor
-
visitPrimitiveArrayConstant
public void visitPrimitiveArrayConstant(Clazz clazz, PrimitiveArrayConstant primitiveArrayConstant)
- Specified by:
visitPrimitiveArrayConstant
in interfaceConstantVisitor
-
visitStringConstant
public void visitStringConstant(Clazz clazz, StringConstant stringConstant)
- Specified by:
visitStringConstant
in interfaceConstantVisitor
-
visitUtf8Constant
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
- Specified by:
visitUtf8Constant
in interfaceConstantVisitor
-
visitDynamicConstant
public void visitDynamicConstant(Clazz clazz, DynamicConstant dynamicConstant)
- Specified by:
visitDynamicConstant
in interfaceConstantVisitor
-
visitInvokeDynamicConstant
public void visitInvokeDynamicConstant(Clazz clazz, InvokeDynamicConstant invokeDynamicConstant)
- Specified by:
visitInvokeDynamicConstant
in interfaceConstantVisitor
-
visitMethodHandleConstant
public void visitMethodHandleConstant(Clazz clazz, MethodHandleConstant methodHandleConstant)
- Specified by:
visitMethodHandleConstant
in interfaceConstantVisitor
-
visitModuleConstant
public void visitModuleConstant(Clazz clazz, ModuleConstant moduleConstant)
- Specified by:
visitModuleConstant
in interfaceConstantVisitor
-
visitPackageConstant
public void visitPackageConstant(Clazz clazz, PackageConstant packageConstant)
- Specified by:
visitPackageConstant
in interfaceConstantVisitor
-
visitFieldrefConstant
public void visitFieldrefConstant(Clazz clazz, FieldrefConstant fieldrefConstant)
- Specified by:
visitFieldrefConstant
in interfaceConstantVisitor
-
visitInterfaceMethodrefConstant
public void visitInterfaceMethodrefConstant(Clazz clazz, InterfaceMethodrefConstant interfaceMethodrefConstant)
- Specified by:
visitInterfaceMethodrefConstant
in interfaceConstantVisitor
-
visitMethodrefConstant
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
- Specified by:
visitMethodrefConstant
in interfaceConstantVisitor
-
visitClassConstant
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
- Specified by:
visitClassConstant
in interfaceConstantVisitor
-
visitMethodTypeConstant
public void visitMethodTypeConstant(Clazz clazz, MethodTypeConstant methodTypeConstant)
- Specified by:
visitMethodTypeConstant
in interfaceConstantVisitor
-
visitNameAndTypeConstant
public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant)
- Specified by:
visitNameAndTypeConstant
in interfaceConstantVisitor
-
-