Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

DefaultVisitor.java

00001 package de.fub.bytecode.classfile;
00002 
00003 /**
00004  * Traverses a JavaClass with another Visitor object 'piggy-backed'
00005  * that is applied to all components of a JavaClass object. I.e. this
00006  * class supplies the traversal strategy, other classes can make use
00007  * of it.
00008  *
00009  * @version $Id: DefaultVisitor.java,v 1.1.1.1 2002/01/24 03:41:37 pserver Exp $
00010  * @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A> 
00011  */
00012 public class DefaultVisitor implements Visitor {
00013   private JavaClass clazz;
00014   private Visitor   visitor;
00015 
00016   /**
00017    * @param clazz Class to traverse
00018    * @param visitor visitor object to apply to all components
00019    */
00020   public DefaultVisitor(JavaClass clazz, Visitor visitor) {
00021     this.clazz   = clazz;
00022     this.visitor = visitor;
00023   }  
00024   /**
00025    * Start traversal.
00026    */
00027   public void visit() { clazz.accept(this); }  
00028   public void visitCode(Code code) {
00029     code.accept(visitor);
00030 
00031     CodeException[] table = code.getExceptionTable();
00032     for(int i=0; i < table.length; i++)
00033       table[i].accept(this);
00034 
00035     Attribute[] attributes = code.getAttributes();
00036     for(int i=0; i < attributes.length; i++)
00037       attributes[i].accept(this);
00038   }  
00039   public void visitCodeException(CodeException ce) { ce.accept(visitor); }  
00040   public void visitConstantClass(ConstantClass constant) { constant.accept(visitor); }  
00041   public void visitConstantDouble(ConstantDouble constant) { constant.accept(visitor); }  
00042   public void visitConstantFieldref(ConstantFieldref constant) { constant.accept(visitor); }  
00043   public void visitConstantFloat(ConstantFloat constant) { constant.accept(visitor); }  
00044   public void visitConstantInteger(ConstantInteger constant) { constant.accept(visitor); }  
00045   public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref constant) {
00046     constant.accept(visitor);
00047   }  
00048   public void visitConstantLong(ConstantLong constant) { constant.accept(visitor); }  
00049   public void visitConstantMethodref(ConstantMethodref constant) {
00050     constant.accept(visitor); 
00051   }  
00052   public void visitConstantNameAndType(ConstantNameAndType constant) {
00053     constant.accept(visitor);
00054   }  
00055   public void visitConstantPool(ConstantPool cp) {
00056     cp.accept(visitor);
00057 
00058     Constant[] constants = cp.getConstantPool();
00059     for(int i=1; i < constants.length; i++) {
00060       if(constants[i] != null)
00061     constants[i].accept(this);
00062     }
00063   }  
00064   public void visitConstantString(ConstantString constant) { constant.accept(visitor); }  
00065   public void visitConstantUtf8(ConstantUtf8 constant) { constant.accept(visitor); }  
00066   public void visitConstantValue(ConstantValue cv) { cv.accept(visitor); }  
00067   public void visitDeprecated(Deprecated attribute) { attribute.accept(visitor); }  
00068   public void visitExceptionTable(ExceptionTable table) { table.accept(visitor);  }  
00069   public void visitField(Field field) {
00070     field.accept(visitor);
00071     
00072     Attribute[] attributes = field.getAttributes();
00073     for(int i=0; i < attributes.length; i++)
00074       attributes[i].accept(this);
00075   }  
00076   public void visitInnerClass(InnerClass inner) { inner.accept(visitor); }  
00077   public void visitInnerClasses(InnerClasses ic) {
00078     ic.accept(visitor);
00079 
00080     InnerClass[] ics = ic.getInnerClasses();
00081     for(int i=0; i < ics.length; i++)
00082       ics[i].accept(this);
00083   }  
00084   public void visitJavaClass(JavaClass clazz) {
00085     clazz.accept(visitor);
00086 
00087     Field[] fields = clazz.getFields();
00088     for(int i=0; i < fields.length; i++)
00089       fields[i].accept(this);
00090 
00091     Method[] methods = clazz.getMethods();
00092     for(int i=0; i < methods.length; i++)
00093       methods[i].accept(this);
00094 
00095     Attribute[] attributes = clazz.getAttributes();
00096     for(int i=0; i < attributes.length; i++)
00097       attributes[i].accept(this);
00098 
00099     clazz.getConstantPool().accept(this);
00100   }  
00101   public void visitLineNumber(LineNumber number) { number.accept(visitor); }  
00102   public void visitLineNumberTable(LineNumberTable table) {
00103     table.accept(visitor);
00104 
00105     LineNumber[] numbers = table.getLineNumberTable();
00106     for(int i=0; i < numbers.length; i++)
00107       numbers[i].accept(this);
00108   }  
00109   public void visitLocalVariable(LocalVariable var) { var.accept(visitor); }  
00110   public void visitLocalVariableTable(LocalVariableTable table) {
00111     table.accept(visitor);
00112 
00113     LocalVariable[] vars = table.getLocalVariableTable();
00114     for(int i=0; i < vars.length; i++)
00115       vars[i].accept(this);
00116   }  
00117   public void visitMethod(Method method) {
00118     method.accept(visitor);
00119     
00120     Attribute[] attributes = method.getAttributes();
00121     for(int i=0; i < attributes.length; i++)
00122       attributes[i].accept(this);
00123   }  
00124   public void visitSourceFile(SourceFile attribute) { attribute.accept(visitor); }  
00125   public void visitSynthetic(Synthetic attribute) { attribute.accept(visitor); }  
00126   public void visitUnknown(Unknown attribute) { attribute.accept(visitor); }  
00127 }

Generated at Thu Feb 7 06:43:36 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001