📄 constantadder.java
字号:
/* * ProGuard -- shrinking, optimization, obfuscation, and preverification * of Java bytecode. * * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu) * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package proguard.classfile.editor;import proguard.classfile.util.SimplifiedVisitor;import proguard.classfile.attribute.visitor.*;import proguard.classfile.attribute.*;import proguard.classfile.instruction.visitor.InstructionVisitor;import proguard.classfile.instruction.*;import proguard.classfile.*;import proguard.classfile.constant.visitor.ConstantVisitor;import proguard.classfile.constant.*;import proguard.classfile.visitor.*;/** * This ConstantVisitor adds all constants that it visits to the constant pool * of a given target class. * * @author Eric Lafortune */public class ConstantAdderimplements ConstantVisitor{ private ProgramClass targetClass; private int constantIndex; private ConstantPoolEditor constantPoolEditor = new ConstantPoolEditor(); /** * Sets the class to which visited constants will be copied. */ public void setTargetClass(ProgramClass targetClass) { this.targetClass = targetClass; } /** * Returns the class to which visited constants will be copied. */ public ProgramClass getTargetClass() { return targetClass; } /** * Returns the index of the most recently created constant in the constant * pool of the target class. */ public int getConstantIndex() { return constantIndex; } // Implementations for ConstantVisitor. public void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant) { constantIndex = constantPoolEditor.addIntegerConstant(targetClass, integerConstant.getValue()); } public void visitLongConstant(Clazz clazz, LongConstant longConstant) { constantIndex = constantPoolEditor.addLongConstant(targetClass, longConstant.getValue()); } public void visitFloatConstant(Clazz clazz, FloatConstant floatConstant) { constantIndex = constantPoolEditor.addFloatConstant(targetClass, floatConstant.getValue()); } public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant) { constantIndex = constantPoolEditor.addDoubleConstant(targetClass, doubleConstant.getValue()); } public void visitStringConstant(Clazz clazz, StringConstant stringConstant) { constantIndex = constantPoolEditor.addStringConstant(targetClass, stringConstant.getString(clazz), stringConstant.referencedClass); } public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) { constantIndex = constantPoolEditor.addUtf8Constant(targetClass, utf8Constant.getString()); } public void visitFieldrefConstant(Clazz clazz, FieldrefConstant fieldrefConstant) { constantIndex = constantPoolEditor.addFieldrefConstant(targetClass, fieldrefConstant.getClassName(clazz), fieldrefConstant.getName(clazz), fieldrefConstant.getType(clazz), fieldrefConstant.referencedClass, fieldrefConstant.referencedMember); } public void visitInterfaceMethodrefConstant(Clazz clazz, InterfaceMethodrefConstant interfaceMethodrefConstant) { constantIndex = constantPoolEditor.addInterfaceMethodrefConstant(targetClass, interfaceMethodrefConstant.getClassName(clazz), interfaceMethodrefConstant.getName(clazz), interfaceMethodrefConstant.getType(clazz), interfaceMethodrefConstant.referencedClass, interfaceMethodrefConstant.referencedMember); } public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant) { constantIndex = constantPoolEditor.addMethodrefConstant(targetClass, methodrefConstant.getClassName(clazz), methodrefConstant.getName(clazz), methodrefConstant.getType(clazz), methodrefConstant.referencedClass, methodrefConstant.referencedMember); } public void visitClassConstant(Clazz clazz, ClassConstant classConstant) { constantIndex = constantPoolEditor.addClassConstant(targetClass, classConstant.getName(clazz), classConstant.referencedClass); } public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant) { constantIndex = constantPoolEditor.addNameAndTypeConstant(targetClass, nameAndTypeConstant.getName(clazz), nameAndTypeConstant.getType(clazz)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -