1 21 package proguard.classfile.editor; 22 23 import proguard.classfile.*; 24 import proguard.classfile.constant.*; 25 import proguard.classfile.constant.visitor.ConstantVisitor; 26 27 33 public class ConstantAdder 34 implements ConstantVisitor 35 { 36 private ProgramClass targetClass; 37 private int constantIndex; 38 39 private ConstantPoolEditor constantPoolEditor = new ConstantPoolEditor(); 40 41 42 45 public void setTargetClass(ProgramClass targetClass) 46 { 47 this.targetClass = targetClass; 48 } 49 50 51 54 public ProgramClass getTargetClass() 55 { 56 return targetClass; 57 } 58 59 60 64 public int getConstantIndex() 65 { 66 return constantIndex; 67 } 68 69 70 72 public void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant) 73 { 74 constantIndex = 75 constantPoolEditor.addIntegerConstant(targetClass, 76 integerConstant.getValue()); 77 } 78 79 80 public void visitLongConstant(Clazz clazz, LongConstant longConstant) 81 { 82 constantIndex = 83 constantPoolEditor.addLongConstant(targetClass, 84 longConstant.getValue()); 85 } 86 87 88 public void visitFloatConstant(Clazz clazz, FloatConstant floatConstant) 89 { 90 constantIndex = 91 constantPoolEditor.addFloatConstant(targetClass, 92 floatConstant.getValue()); 93 } 94 95 96 public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant) 97 { 98 constantIndex = 99 constantPoolEditor.addDoubleConstant(targetClass, 100 doubleConstant.getValue()); 101 } 102 103 104 public void visitStringConstant(Clazz clazz, StringConstant stringConstant) 105 { 106 constantIndex = 107 constantPoolEditor.addStringConstant(targetClass, 108 stringConstant.getString(clazz), 109 stringConstant.referencedClass, 110 stringConstant.referencedMember); 111 } 112 113 114 public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) 115 { 116 constantIndex = 117 constantPoolEditor.addUtf8Constant(targetClass, 118 utf8Constant.getString()); 119 } 120 121 122 public void visitFieldrefConstant(Clazz clazz, FieldrefConstant fieldrefConstant) 123 { 124 clazz.constantPoolEntryAccept(fieldrefConstant.u2classIndex, this); 126 127 constantIndex = 130 constantPoolEditor.addFieldrefConstant(targetClass, 131 constantIndex, 132 fieldrefConstant.getName(clazz), 133 fieldrefConstant.getType(clazz), 134 fieldrefConstant.referencedClass, 135 fieldrefConstant.referencedMember); 136 } 137 138 139 public void visitInterfaceMethodrefConstant(Clazz clazz, InterfaceMethodrefConstant interfaceMethodrefConstant) 140 { 141 clazz.constantPoolEntryAccept(interfaceMethodrefConstant.u2classIndex, this); 143 144 constantIndex = 147 constantPoolEditor.addInterfaceMethodrefConstant(targetClass, 148 constantIndex, 149 interfaceMethodrefConstant.getName(clazz), 150 interfaceMethodrefConstant.getType(clazz), 151 interfaceMethodrefConstant.referencedClass, 152 interfaceMethodrefConstant.referencedMember); 153 } 154 155 156 public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant) 157 { 158 clazz.constantPoolEntryAccept(methodrefConstant.u2classIndex, this); 160 161 constantIndex = 164 constantPoolEditor.addMethodrefConstant(targetClass, 165 constantIndex, 166 methodrefConstant.getName(clazz), 167 methodrefConstant.getType(clazz), 168 methodrefConstant.referencedClass, 169 methodrefConstant.referencedMember); 170 } 171 172 173 public void visitClassConstant(Clazz clazz, ClassConstant classConstant) 174 { 175 constantIndex = 177 constantPoolEditor.addClassConstant(targetClass, 178 classConstant.getName(clazz), 179 classConstant.referencedClass); 180 } 181 182 183 public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant) 184 { 185 constantIndex = 186 constantPoolEditor.addNameAndTypeConstant(targetClass, 187 nameAndTypeConstant.getName(clazz), 188 nameAndTypeConstant.getType(clazz)); 189 } 190 } 191 | Popular Tags |