View Javadoc

1   // jq_MethodVisitor.java, created Fri Jan 11 17:28:36 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Class;
5   
6   import java.util.Arrays;
7   import java.util.Iterator;
8   import java.util.Set;
9   import jwutil.collections.AppendIterator;
10  
11  /*
12   * @author  John Whaley <jwhaley@alum.mit.edu>
13   * @version $Id: jq_MethodVisitor.java 1931 2004-09-22 22:17:47Z joewhaley $
14   */
15  public interface jq_MethodVisitor {
16  
17      void visitClassInitializer(jq_ClassInitializer m);
18      void visitInitializer(jq_Initializer m);
19      void visitStaticMethod(jq_StaticMethod m);
20      void visitInstanceMethod(jq_InstanceMethod m);
21      void visitMethod(jq_Method m);
22      
23      class EmptyVisitor implements jq_MethodVisitor {
24          public void visitClassInitializer(jq_ClassInitializer m) {}
25          public void visitInitializer(jq_Initializer m) {}
26          public void visitStaticMethod(jq_StaticMethod m) {}
27          public void visitInstanceMethod(jq_InstanceMethod m) {}
28          public void visitMethod(jq_Method m) {}
29      }
30      
31      class DeclaredMethodVisitor extends jq_TypeVisitor.EmptyVisitor {
32          final jq_MethodVisitor mv; final Set methodNames; boolean trace;
33          public DeclaredMethodVisitor(jq_MethodVisitor mv) { this.mv = mv; this.methodNames = null; this.trace = false; }
34          public DeclaredMethodVisitor(jq_MethodVisitor mv, boolean trace) { this.mv = mv; this.methodNames = null; this.trace = trace; }
35          public DeclaredMethodVisitor(jq_MethodVisitor mv, Set methodNames, boolean trace) { this.mv = mv; this.methodNames = methodNames; this.trace = trace; }
36          public void visitClass(jq_Class k) {
37              if (trace) System.out.println(k.toString());
38              Iterator it = new AppendIterator(Arrays.asList(k.getDeclaredStaticMethods()).iterator(),
39                                               Arrays.asList(k.getDeclaredInstanceMethods()).iterator());
40              while (it.hasNext()) {
41                  jq_Method m = (jq_Method)it.next();
42                  if (methodNames != null && !methodNames.contains(m.getName().toString()))
43                      continue;
44                  m.accept(mv);
45              }
46          }
47      }
48      
49  }
50