1 32 33 package com.jeantessier.classreader; 34 35 import java.util.*; 36 37 import org.apache.log4j.*; 38 39 public abstract class VisitorBase implements Visitor { 40 private int currentCount; 41 42 protected void resetCount() { 43 currentCount = 0; 44 } 45 46 protected void raiseCount() { 47 currentCount++; 48 } 49 50 protected int currentCount() { 51 return currentCount; 52 } 53 54 public void visitConstantPool(ConstantPool constantPool) { 55 Iterator i = constantPool.iterator(); 56 while (i.hasNext()) { 57 Visitable entry = (Visitable) i.next(); 58 if (entry != null) { 59 entry.accept(this); 60 } 61 raiseCount(); 62 } 63 } 64 65 public void visitClassfiles(Collection classfiles) { 67 Iterator i = classfiles.iterator(); 68 while (i.hasNext()) { 69 ((Classfile) i.next()).accept(this); 70 } 71 } 72 73 public void visitClassfile(Classfile classfile) { 74 Iterator i; 75 76 i = classfile.getAttributes().iterator(); 77 while (i.hasNext()) { 78 ((Visitable) i.next()).accept(this); 79 } 80 81 i = classfile.getAllFields().iterator(); 82 while (i.hasNext()) { 83 ((Visitable) i.next()).accept(this); 84 } 85 86 i = classfile.getAllMethods().iterator(); 87 while (i.hasNext()) { 88 ((Visitable) i.next()).accept(this); 89 } 90 } 91 92 public void visitClass_info(Class_info entry) {} 94 public void visitFieldRef_info(FieldRef_info entry) {} 95 public void visitMethodRef_info(MethodRef_info entry) {} 96 public void visitInterfaceMethodRef_info(InterfaceMethodRef_info entry) {} 97 public void visitString_info(String_info entry) {} 98 public void visitInteger_info(Integer_info entry) {} 99 public void visitFloat_info(Float_info entry) {} 100 public void visitLong_info(Long_info entry) {} 101 public void visitDouble_info(Double_info entry) {} 102 public void visitNameAndType_info(NameAndType_info entry) {} 103 public void visitUTF8_info(UTF8_info entry) {} 104 105 public void visitField_info(Field_info entry) { 107 Iterator i = entry.getAttributes().iterator(); 108 while (i.hasNext()) { 109 ((Visitable) i.next()).accept(this); 110 } 111 } 112 113 public void visitMethod_info(Method_info entry) { 114 Iterator i = entry.getAttributes().iterator(); 115 while (i.hasNext()) { 116 ((Visitable) i.next()).accept(this); 117 } 118 } 119 120 public void visitConstantValue_attribute(ConstantValue_attribute attribute) { 122 } 124 125 public void visitCode_attribute(Code_attribute attribute) { 126 Iterator i; 127 128 Logger.getLogger(getClass()).debug("Visiting " + attribute.getExceptionHandlers().size() + " exception handler(s) ..."); 129 i = attribute.getExceptionHandlers().iterator(); 130 while (i.hasNext()) { 131 ((Visitable) i.next()).accept(this); 132 } 133 134 Logger.getLogger(getClass()).debug("Visiting " + attribute.getAttributes().size() + " code attribute(s) ..."); 135 i = attribute.getAttributes().iterator(); 136 while (i.hasNext()) { 137 ((Visitable) i.next()).accept(this); 138 } 139 } 140 141 public void visitExceptions_attribute(Exceptions_attribute attribute) { 142 Logger.getLogger(getClass()).debug("Visiting " + attribute.getExceptions().size() + " exception class(es) ..."); 143 144 Iterator i = attribute.getExceptions().iterator(); 145 while (i.hasNext()) { 146 ((Visitable) i.next()).accept(this); 147 } 148 } 149 150 public void visitInnerClasses_attribute(InnerClasses_attribute attribute) { 151 Logger.getLogger(getClass()).debug("Visiting " + attribute.getClasses().size() + " inner class(es) ..."); 152 153 Iterator i = attribute.getClasses().iterator(); 154 while (i.hasNext()) { 155 ((Visitable) i.next()).accept(this); 156 } 157 } 158 159 public void visitSynthetic_attribute(Synthetic_attribute attribute) { 160 } 162 163 public void visitSourceFile_attribute(SourceFile_attribute attribute) { 164 } 166 167 public void visitLineNumberTable_attribute(LineNumberTable_attribute attribute) { 168 Logger.getLogger(getClass()).debug("Visiting " + attribute.getLineNumbers().size() + " line number(s) ..."); 169 170 Iterator i = attribute.getLineNumbers().iterator(); 171 while (i.hasNext()) { 172 ((Visitable) i.next()).accept(this); 173 } 174 } 175 176 public void visitLocalVariableTable_attribute(LocalVariableTable_attribute attribute) { 177 Logger.getLogger(getClass()).debug("Visiting " + attribute.getLocalVariables().size() + " local variable(s) ..."); 178 179 Iterator i = attribute.getLocalVariables().iterator(); 180 while (i.hasNext()) { 181 ((Visitable) i.next()).accept(this); 182 } 183 } 184 185 public void visitDeprecated_attribute(Deprecated_attribute attribute) { 186 } 188 189 public void visitCustom_attribute(Custom_attribute attribute) { 190 } 192 193 public void visitExceptionHandler(ExceptionHandler helper) {} 195 public void visitInnerClass(InnerClass helper) {} 196 public void visitLineNumber(LineNumber helper) {} 197 public void visitLocalVariable(LocalVariable helper) {} 198 } 199 | Popular Tags |