proguard.classfile.editor
Class ConstantAdder

java.lang.Object
  extended by proguard.classfile.editor.ConstantAdder
All Implemented Interfaces:
ConstantVisitor

public class ConstantAdder
extends java.lang.Object
implements ConstantVisitor

This ConstantVisitor adds all constants that it visits to the constant pool of a given target class.


Constructor Summary
ConstantAdder(ProgramClass targetClass)
          Creates a new ConstantAdder that will copy constants into the given target class.
 
Method Summary
 int addConstant(Clazz clazz, Constant constant)
          Adds a copy of the given constant in the given class and returns its index.
 int addConstant(Clazz clazz, int constantIndex)
          Adds a copy of the specified 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 visitFieldrefConstant(Clazz clazz, FieldrefConstant fieldrefConstant)
           
 void visitFloatConstant(Clazz clazz, FloatConstant floatConstant)
           
 void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant)
           
 void visitInterfaceMethodrefConstant(Clazz clazz, InterfaceMethodrefConstant interfaceMethodrefConstant)
           
 void visitLongConstant(Clazz clazz, LongConstant longConstant)
           
 void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
           
 void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant)
           
 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
 

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 interface ConstantVisitor

visitLongConstant

public void visitLongConstant(Clazz clazz,
                              LongConstant longConstant)
Specified by:
visitLongConstant in interface ConstantVisitor

visitFloatConstant

public void visitFloatConstant(Clazz clazz,
                               FloatConstant floatConstant)
Specified by:
visitFloatConstant in interface ConstantVisitor

visitDoubleConstant

public void visitDoubleConstant(Clazz clazz,
                                DoubleConstant doubleConstant)
Specified by:
visitDoubleConstant in interface ConstantVisitor

visitStringConstant

public void visitStringConstant(Clazz clazz,
                                StringConstant stringConstant)
Specified by:
visitStringConstant in interface ConstantVisitor

visitUtf8Constant

public void visitUtf8Constant(Clazz clazz,
                              Utf8Constant utf8Constant)
Specified by:
visitUtf8Constant in interface ConstantVisitor

visitFieldrefConstant

public void visitFieldrefConstant(Clazz clazz,
                                  FieldrefConstant fieldrefConstant)
Specified by:
visitFieldrefConstant in interface ConstantVisitor

visitInterfaceMethodrefConstant

public void visitInterfaceMethodrefConstant(Clazz clazz,
                                            InterfaceMethodrefConstant interfaceMethodrefConstant)
Specified by:
visitInterfaceMethodrefConstant in interface ConstantVisitor

visitMethodrefConstant

public void visitMethodrefConstant(Clazz clazz,
                                   MethodrefConstant methodrefConstant)
Specified by:
visitMethodrefConstant in interface ConstantVisitor

visitClassConstant

public void visitClassConstant(Clazz clazz,
                               ClassConstant classConstant)
Specified by:
visitClassConstant in interface ConstantVisitor

visitNameAndTypeConstant

public void visitNameAndTypeConstant(Clazz clazz,
                                     NameAndTypeConstant nameAndTypeConstant)
Specified by:
visitNameAndTypeConstant in interface ConstantVisitor