📄 multiinstructionvisitor.java
字号:
/* * ProGuard -- shrinking, optimization, obfuscation, and preverification * of Java bytecode. * * Copyright (c) 2002-2007 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.classfile.instruction.visitor;import proguard.classfile.*;import proguard.classfile.instruction.visitor.InstructionVisitor;import proguard.classfile.instruction.*;import proguard.classfile.attribute.*;/** * This InstructionVisitor delegates all visits to each InstructionVisitor * in a given list. * * @author Eric Lafortune */public class MultiInstructionVisitor implements InstructionVisitor{ private static final int ARRAY_SIZE_INCREMENT = 5; // Shared copies of Instruction objects, to avoid creating a lot of objects. private final SimpleInstruction simpleInstruction = new SimpleInstruction(); private final ConstantInstruction constantInstruction = new ConstantInstruction(); private final VariableInstruction variableInstruction = new VariableInstruction(); private final BranchInstruction branchInstruction = new BranchInstruction(); private final TableSwitchInstruction tableSwitchInstruction = new TableSwitchInstruction(); private final LookUpSwitchInstruction lookUpSwitchInstruction = new LookUpSwitchInstruction(); private InstructionVisitor[] instructionVisitors; private int instructionVisitorCount; public MultiInstructionVisitor() { } public MultiInstructionVisitor(InstructionVisitor[] instructionVisitors) { this.instructionVisitors = instructionVisitors; this.instructionVisitorCount = instructionVisitors.length; } public void addInstructionVisitor(InstructionVisitor instructionVisitor) { ensureArraySize(); instructionVisitors[instructionVisitorCount++] = instructionVisitor; } private void ensureArraySize() { if (instructionVisitors == null) { instructionVisitors = new InstructionVisitor[ARRAY_SIZE_INCREMENT]; } else if (instructionVisitors.length == instructionVisitorCount) { InstructionVisitor[] newInstructionVisitors = new InstructionVisitor[instructionVisitorCount + ARRAY_SIZE_INCREMENT]; System.arraycopy(instructionVisitors, 0, newInstructionVisitors, 0, instructionVisitorCount); instructionVisitors = newInstructionVisitors; } } // Implementations for InstructionVisitor. public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction) { simpleInstruction = this.simpleInstruction.copy(simpleInstruction); for (int index = 0; index < instructionVisitorCount; index++) { instructionVisitors[index].visitSimpleInstruction(clazz, method, codeAttribute, offset, simpleInstruction); } } public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction) { variableInstruction = this.variableInstruction.copy(variableInstruction); for (int index = 0; index < instructionVisitorCount; index++) { instructionVisitors[index].visitVariableInstruction(clazz, method, codeAttribute, offset, variableInstruction); } } public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { constantInstruction = this.constantInstruction.copy(constantInstruction); for (int index = 0; index < instructionVisitorCount; index++) { instructionVisitors[index].visitConstantInstruction(clazz, method, codeAttribute, offset, constantInstruction); } } public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction) { branchInstruction = this.branchInstruction.copy(branchInstruction); for (int index = 0; index < instructionVisitorCount; index++) { instructionVisitors[index].visitBranchInstruction(clazz, method, codeAttribute, offset, branchInstruction); } } public void visitTableSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction) { tableSwitchInstruction = this.tableSwitchInstruction.copy(tableSwitchInstruction); for (int index = 0; index < instructionVisitorCount; index++) { instructionVisitors[index].visitTableSwitchInstruction(clazz, method, codeAttribute, offset, tableSwitchInstruction); } } public void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction) { lookUpSwitchInstruction = this.lookUpSwitchInstruction.copy(lookUpSwitchInstruction); for (int index = 0; index < instructionVisitorCount; index++) { instructionVisitors[index].visitLookUpSwitchInstruction(clazz, method, codeAttribute, offset, lookUpSwitchInstruction); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -