KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > bcel > JavaClassWalker


1 //Tested with BCEL-5.1
2
//http://jakarta.apache.org/builds/jakarta-bcel/release/v5.1/
3

4 package com.puppycrawl.tools.checkstyle.bcel;
5
6 import org.apache.bcel.classfile.DescendingVisitor;
7 import org.apache.bcel.classfile.JavaClass;
8 import org.apache.bcel.classfile.Visitor;
9
10 /**
11  * Walks a JavaClass parse tree.
12  * @author Rick Giles
13  * @version 15-Jun-2003
14  */

15 public final class JavaClassWalker
16 {
17     /** visitor to be accepted during a traversal */
18     private Visitor mVisitor = new EmptyClassFileVisitor();
19
20     /**
21      * Sets a visitor to be accepted during a traversal.
22      * @param aVisitor the visitor to be accepted during a traversal.
23      */

24     public void setVisitor(Visitor aVisitor)
25     {
26         mVisitor = aVisitor;
27     }
28
29     /**
30      * Traverses a JavaClass parse tree and accepts all registered
31      * visitors.
32      * @param aJavaClass the root of the tree.
33      */

34     public void walk(JavaClass aJavaClass)
35     {
36         DescendingVisitor visitor =
37             new DescendingVisitor(aJavaClass, mVisitor);
38         aJavaClass.accept(visitor);
39     }
40 }
41
Popular Tags