View Javadoc

1   // jq_FieldVisitor.java, created Wed Jun 26 12:26:34 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 jwutil.collections.AppendIterator;
9   
10  /*
11   * @author  John Whaley <jwhaley@alum.mit.edu>
12   * @version $Id: jq_FieldVisitor.java 1931 2004-09-22 22:17:47Z joewhaley $
13   */
14  public interface jq_FieldVisitor {
15  
16      void visitStaticField(jq_StaticField m);
17      void visitInstanceField(jq_InstanceField m);
18      void visitField(jq_Field m);
19      
20      class EmptyVisitor implements jq_FieldVisitor {
21          public void visitStaticField(jq_StaticField m) {}
22          public void visitInstanceField(jq_InstanceField m) {}
23          public void visitField(jq_Field m) {}
24      }
25      
26      class DeclaredFieldVisitor extends jq_TypeVisitor.EmptyVisitor {
27          final jq_FieldVisitor mv; boolean trace;
28          public DeclaredFieldVisitor(jq_FieldVisitor mv) { this.mv = mv; }
29          public DeclaredFieldVisitor(jq_FieldVisitor mv, boolean trace) { this.mv = mv; this.trace = trace; }
30          public void visitClass(jq_Class k) {
31              if (trace) System.out.println(k.toString());
32              Iterator it = new AppendIterator(Arrays.asList(k.getDeclaredStaticFields()).iterator(),
33                                              Arrays.asList(k.getDeclaredInstanceFields()).iterator());
34              while (it.hasNext()) {
35                  jq_Field m = (jq_Field)it.next();
36                  m.accept(mv);
37              }
38          }
39      }
40      
41  }
42