001: package net.sourceforge.pmd.util;
002:
003: import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
004: import net.sourceforge.pmd.ast.ASTCompilationUnit;
005: import net.sourceforge.pmd.ast.JavaParserVisitorAdapter;
006:
007: public class SymbolTableViewer extends JavaParserVisitorAdapter {
008:
009: private int depth;
010:
011: public Object visit(ASTCompilationUnit node, Object data) {
012: depth++;
013: System.out.println(spaces() + node.getScope());
014: super .visit(node, data);
015: depth--;
016: return data;
017: }
018:
019: public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
020: depth++;
021: System.out.println(spaces() + node.getScope());
022: super .visit(node, data);
023: depth--;
024: return data;
025: }
026:
027: private String spaces() {
028: StringBuffer sb = new StringBuffer(depth);
029: for (int i = 0; i < depth; i++)
030: sb.append(' ');
031: return sb.toString();
032: }
033:
034: /*
035: public Object visit(ASTClassOrInterfaceBodyDeclaration node, Object data) {
036: System.out.println(node.getScope());
037: node.dump("");
038: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
039: }
040:
041: public Object visit(ASTEnumDeclaration node, Object data) {
042: System.out.println(node.getScope());
043: node.dump("");
044: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
045: }
046:
047: public Object visit(ASTBlock node, Object data) {
048: System.out.println(node.getScope());
049: node.dump("");
050: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
051: }
052:
053: public Object visit(ASTTryStatement node, Object data) {
054: System.out.println(node.getScope());
055: node.dump("");
056: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
057: }
058:
059: public Object visit(ASTCatchStatement node, Object data) {
060: System.out.println(node.getScope());
061: node.dump("");
062: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
063: }
064:
065: public Object visit(ASTFinallyStatement node, Object data) {
066: System.out.println(node.getScope());
067: node.dump("");
068: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
069: }
070:
071: public Object visit(ASTMethodDeclaration node, Object data) {
072: System.out.println(node.getScope());
073: node.dump("");
074: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
075: }
076:
077: public Object visit(ASTConstructorDeclaration node, Object data) {
078: System.out.println(node.getScope());
079: node.dump("");
080: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
081: }
082:
083: public Object visit(ASTSwitchLabel node, Object data) {
084: System.out.println(node.getScope());
085: node.dump("");
086: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
087: }
088:
089: public Object visit(ASTIfStatement node, Object data) {
090: System.out.println(node.getScope());
091: node.dump("");
092: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
093: }
094:
095: public Object visit(ASTForStatement node, Object data) {
096: System.out.println(node.getScope());
097: node.dump("");
098: return super.visit(node, data); //To change body of implemented methods use File | Settings | File Templates.
099: }
100: */
101:
102: }
|