⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gettersetterinliner.java

📁 proguard 3.5 java 混淆器 最新 免费 好用的 大家用用试一下吧 天行健-君子以自强不息 地势坤-君子以厚德载物
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* $Id: GetterSetterInliner.java,v 1.18.2.1 2006/01/16 22:57:56 eric Exp $ * * ProGuard -- shrinking, optimization, and obfuscation of Java class files. * * Copyright (c) 2002-2006 Eric Lafortune (eric@graphics.cornell.edu) * * This program 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 program 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 General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package proguard.optimize.peephole;import proguard.classfile.*;import proguard.classfile.attribute.*;import proguard.classfile.attribute.annotation.*;import proguard.classfile.util.*;import proguard.classfile.editor.*;import proguard.classfile.instruction.*;import proguard.classfile.visitor.*;/** * This InstructionVisitor inlines simple getter and setter methods. * * @author Eric Lafortune */public class GetterSetterInlinerimplements   InstructionVisitor,             CpInfoVisitor{    private static final String SETTER_RETURN_TYPE = "V";    private ConstantPoolEditor constantPoolEditor  = new ConstantPoolEditor();    private MemberInfoVisitor  getterSetterChecker = new AllAttrInfoVisitor(                                                     new MyGetterSetterChecker());    private MemberFinder       memberFinder        = new MemberFinder();    private boolean            allowAccessModification;    private CodeAttrInfoEditor codeAttrInfoEditor;    private InstructionVisitor extraInstructionVisitor;    // Return values of the getter/setter checker.    private byte       getFieldPutFieldOpcode;    private int        referencedFieldIndex;    private ClassFile  referencedClassFile;    private MemberInfo referencedFieldInfo;    /**     * Creates a new GetterSetterInliner.     * @param allowAccessModification indicates whether the access modifiers of     *                                a field can be changed in order to inline     *                                its getter or setter.     * @param codeAttrInfoEditor      a code editor that can be used for     *                                accumulating changes to the code.     */    public GetterSetterInliner(boolean            allowAccessModification,                               CodeAttrInfoEditor codeAttrInfoEditor)    {        this(allowAccessModification, codeAttrInfoEditor, null);    }    /**     * Creates a new GetterSetterInliner.     * @param allowAccessModification indicates whether the access modifiers of     *                                a field can be changed in order to inline     *                                its getter or setter.     * @param codeAttrInfoEditor      a code editor that can be used for     *                                accumulating changes to the code.     * @param extraInstructionVisitor an optional extra visitor for all replaced     *                                store instructions.     */    public GetterSetterInliner(boolean            allowAccessModification,                               CodeAttrInfoEditor codeAttrInfoEditor,                               InstructionVisitor extraInstructionVisitor)    {        this.allowAccessModification = allowAccessModification;        this.codeAttrInfoEditor      = codeAttrInfoEditor;        this.extraInstructionVisitor = extraInstructionVisitor;    }    // Implementations for InstructionVisitor.    public void visitSimpleInstruction(ClassFile classFile, MethodInfo methodInfo, CodeAttrInfo codeAttrInfo, int offset, SimpleInstruction simpleInstruction) {}    public void visitVariableInstruction(ClassFile classFile, MethodInfo methodInfo, CodeAttrInfo codeAttrInfo, int offset, VariableInstruction variableInstruction) {}    public void visitBranchInstruction(ClassFile classFile, MethodInfo methodInfo, CodeAttrInfo codeAttrInfo, int offset, BranchInstruction branchInstruction) {}    public void visitTableSwitchInstruction(ClassFile classFile, MethodInfo methodInfo, CodeAttrInfo codeAttrInfo, int offset, TableSwitchInstruction tableSwitchInstruction) {}    public void visitLookUpSwitchInstruction(ClassFile classFile, MethodInfo methodInfo, CodeAttrInfo codeAttrInfo, int offset, LookUpSwitchInstruction lookUpSwitchInstruction) {}    public void visitCpInstruction(ClassFile classFile, MethodInfo methodInfo, CodeAttrInfo codeAttrInfo, int offset, CpInstruction cpInstruction)    {        byte opcode = cpInstruction.opcode;        // Is this instruction a non-static invoke instruction?        if (opcode == InstructionConstants.OP_INVOKEVIRTUAL ||            opcode == InstructionConstants.OP_INVOKESPECIAL)        {            // Check if it's a getter or setter that can be inlined.            getFieldPutFieldOpcode = 0;            classFile.constantPoolEntryAccept(cpInstruction.cpIndex, this);            // Do we have a getfield or putfield instruction to inline?            if (getFieldPutFieldOpcode != 0)            {                // Reuse or create the field reference in this class.                int fieldrefCpInfoIndex = classFile.equals(referencedClassFile) ?                    referencedFieldIndex :                    constantPoolEditor.addFieldrefCpInfo((ProgramClassFile)classFile,                                                         referencedClassFile.getName(),                                                         referencedFieldInfo.getName(referencedClassFile),                                                         referencedFieldInfo.getDescriptor(referencedClassFile),                                                         referencedClassFile,                                                         referencedFieldInfo);                // Inline the getfield or putfield instruction.                Instruction replacementInstruction = new CpInstruction(getFieldPutFieldOpcode,                                                                       fieldrefCpInfoIndex).shrink();                codeAttrInfoEditor.replaceInstruction(offset, replacementInstruction);                        // Visit the instruction, if required.                if (extraInstructionVisitor != null)                {                    extraInstructionVisitor.visitCpInstruction(classFile, methodInfo, codeAttrInfo, offset, cpInstruction);                }            }        }    }    // Implementations for CpInfoVisitor.    public void visitIntegerCpInfo(ClassFile classFile, IntegerCpInfo integerCpInfo) {}    public void visitLongCpInfo(ClassFile classFile, LongCpInfo longCpInfo) {}    public void visitFloatCpInfo(ClassFile classFile, FloatCpInfo floatCpInfo) {}    public void visitDoubleCpInfo(ClassFile classFile, DoubleCpInfo doubleCpInfo) {}    public void visitStringCpInfo(ClassFile classFile, StringCpInfo stringCpInfo) {}    public void visitUtf8CpInfo(ClassFile classFile, Utf8CpInfo utf8CpInfo) {}    public void visitFieldrefCpInfo(ClassFile classFile, FieldrefCpInfo fieldrefCpInfo) {}    public void visitInterfaceMethodrefCpInfo(ClassFile classFile, InterfaceMethodrefCpInfo interfaceMethodrefCpInfo) {}    public void visitClassCpInfo(ClassFile classFile, ClassCpInfo classCpInfo) {}    public void visitNameAndTypeCpInfo(ClassFile classFile, NameAndTypeCpInfo nameAndTypeCpInfo) {}    public void visitMethodrefCpInfo(ClassFile classFile, MethodrefCpInfo methodrefCpInfo)    {        String descriptor = methodrefCpInfo.getType(classFile);        // A getter or a setter can't have more than one parameter.        int parameterCount = ClassUtil.internalMethodParameterCount(descriptor);        if (parameterCount > 1)        {            return;        }        // A getter must return a value, a setter must return void.        String returnType = ClassUtil.internalMethodReturnType(descriptor);        if ((parameterCount > 0) ^ returnType.equals(SETTER_RETURN_TYPE))        {            return;        }        // The referenced method must be present and private or final.        MemberInfo referencedMethodInfo = methodrefCpInfo.referencedMemberInfo;        if (referencedMethodInfo == null ||            (referencedMethodInfo.getAccessFlags() &             (ClassConstants.INTERNAL_ACC_PRIVATE |              ClassConstants.INTERNAL_ACC_FINAL)) == 0)        {            return;        }        // Check if the method can be inlined.        referencedMethodInfo.accept(methodrefCpInfo.referencedClassFile,                                    getterSetterChecker);        // Do we have a getfield or putfield instruction to inline?        if (getFieldPutFieldOpcode == 0)        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -