View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.util;
5   
6   import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
7   import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
8   import net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter;
9   
10  public class SymbolTableViewer extends JavaParserVisitorAdapter {
11  
12      private int depth;
13      
14      public Object visit(ASTCompilationUnit node, Object data) {
15          depth++;
16          System.out.println(spaces() + node.getScope());
17          super.visit(node, data);
18          depth--;
19          return data;
20      }
21  
22      public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
23          depth++;
24          System.out.println(spaces() + node.getScope());
25          super.visit(node, data);
26          depth--;
27          return data;
28      }
29  
30      private String spaces() {
31          StringBuffer sb = new StringBuffer(depth);
32          for (int i=0; i<depth; i++) {
33              sb.append(' ');
34          }
35          return sb.toString();
36      }
37  
38  /*
39      public Object visit(ASTClassOrInterfaceBodyDeclaration node, Object data) {
40          System.out.println(node.getScope());
41          node.dump("");
42          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
43      }
44  
45      public Object visit(ASTEnumDeclaration node, Object data) {
46          System.out.println(node.getScope());
47          node.dump("");
48          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
49      }
50  
51      public Object visit(ASTBlock node, Object data) {
52          System.out.println(node.getScope());
53          node.dump("");
54          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
55      }
56  
57      public Object visit(ASTTryStatement node, Object data) {
58          System.out.println(node.getScope());
59          node.dump("");
60          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
61      }
62  
63      public Object visit(ASTCatchStatement node, Object data) {
64          System.out.println(node.getScope());
65          node.dump("");
66          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
67      }
68  
69      public Object visit(ASTFinallyStatement node, Object data) {
70          System.out.println(node.getScope());
71          node.dump("");
72          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
73      }
74  
75      public Object visit(ASTMethodDeclaration node, Object data) {
76          System.out.println(node.getScope());
77          node.dump("");
78          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
79      }
80  
81      public Object visit(ASTConstructorDeclaration node, Object data) {
82          System.out.println(node.getScope());
83          node.dump("");
84          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
85      }
86  
87      public Object visit(ASTSwitchLabel node, Object data) {
88          System.out.println(node.getScope());
89          node.dump("");
90          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
91      }
92  
93      public Object visit(ASTIfStatement node, Object data) {
94          System.out.println(node.getScope());
95          node.dump("");
96          return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
97      }
98  
99      public Object visit(ASTForStatement node, Object data) {
100         System.out.println(node.getScope());
101         node.dump("");
102         return super.visit(node, data);  //To change body of implemented methods use File | Settings | File Templates.
103     }
104 */
105 
106 }