1 4 package com.puppycrawl.tools.checkstyle.bcel; 5 6 import java.util.HashSet ; 7 import java.util.Iterator ; 8 import java.util.Set ; 9 10 import org.apache.bcel.classfile.Code; 11 import org.apache.bcel.classfile.ConstantPool; 12 import org.apache.bcel.classfile.EmptyVisitor; 13 import org.apache.bcel.classfile.Field; 14 import org.apache.bcel.classfile.JavaClass; 15 import org.apache.bcel.classfile.LocalVariable; 16 import org.apache.bcel.classfile.LocalVariableTable; 17 import org.apache.bcel.classfile.Method; 18 import org.apache.bcel.classfile.Visitor; 19 import org.apache.bcel.generic.InstructionHandle; 20 import org.apache.bcel.generic.InstructionList; 21 22 28 public class VisitorSet 30 extends EmptyVisitor 31 { 32 33 private Set mVisitors = new HashSet (); 34 35 38 public VisitorSet(Set aVisitors) 39 { 40 mVisitors = aVisitors; 41 } 42 43 46 public void visitCode(Code aCode) 47 { 48 for (Iterator iter = mVisitors.iterator(); iter.hasNext();) { 49 IDeepVisitor visitor = (IDeepVisitor) iter.next(); 50 Visitor v = visitor.getClassFileVisitor(); 51 aCode.accept(v); 52 } 53 54 final byte[] code = aCode.getCode(); 56 final InstructionList list = new InstructionList(code); 57 final Iterator it = list.iterator(); 58 for (Iterator iter = list.iterator(); iter.hasNext();) { 59 InstructionHandle instruction = (InstructionHandle) iter.next(); 60 visitInstructionHandle(instruction); 61 } 62 } 63 64 68 private void visitInstructionHandle(InstructionHandle aInstruction) 69 { 70 for (Iterator iter = mVisitors.iterator(); iter.hasNext();) { 71 final IDeepVisitor visitor = (IDeepVisitor) iter.next(); 72 org.apache.bcel.generic.Visitor v = 73 visitor.getGenericVisitor(); 74 aInstruction.accept(v); 75 } 76 } 77 78 81 public void visitConstantPool(ConstantPool aConstantPool) 82 { 83 for (Iterator iter = mVisitors.iterator(); iter.hasNext();) { 84 IDeepVisitor visitor = (IDeepVisitor) iter.next(); 85 Visitor v = visitor.getClassFileVisitor(); 86 aConstantPool.accept(v); 87 } 88 } 89 90 93 public void visitField(Field aField) 94 { 95 for (Iterator iter = mVisitors.iterator(); iter.hasNext();) { 96 IDeepVisitor visitor = (IDeepVisitor) iter.next(); 97 Visitor v = visitor.getClassFileVisitor(); 98 aField.accept(v); 99 } 100 } 101 102 105 public void visitJavaClass(JavaClass aJavaClass) 106 { 107 for (Iterator iter = mVisitors.iterator(); iter.hasNext();) { 108 IDeepVisitor visitor = (IDeepVisitor) iter.next(); 109 Visitor v = visitor.getClassFileVisitor(); 110 aJavaClass.accept(v); 111 } 112 } 113 114 129 public void visitLocalVariableTable(LocalVariableTable aTable) 130 { 131 for (Iterator iter = mVisitors.iterator(); iter.hasNext();) { 132 IDeepVisitor visitor = (IDeepVisitor) iter.next(); 133 Visitor v = visitor.getClassFileVisitor(); 134 aTable.accept(v); 135 } 136 } 137 138 141 public void visitMethod(Method aMethod) 142 { 143 for (Iterator iter = mVisitors.iterator(); iter.hasNext();) { 144 IDeepVisitor visitor = (IDeepVisitor) iter.next(); 145 Visitor v = visitor.getClassFileVisitor(); 146 aMethod.accept(v); 147 } 148 } 149 } 150 | Popular Tags |