001: package org.acm.seguin.pmd.symboltable;
002:
003: import net.sourceforge.jrefactory.ast.ASTBlock;
004: import net.sourceforge.jrefactory.ast.ASTClassBodyDeclaration;
005: import net.sourceforge.jrefactory.ast.ASTCompilationUnit;
006: import net.sourceforge.jrefactory.ast.ASTConstructorDeclaration;
007: import net.sourceforge.jrefactory.ast.ASTForStatement;
008: import net.sourceforge.jrefactory.ast.ASTIfStatement;
009: import net.sourceforge.jrefactory.ast.ASTMethodDeclaration;
010: import net.sourceforge.jrefactory.ast.ASTSwitchStatement;
011: import net.sourceforge.jrefactory.ast.ASTTryStatement;
012: import net.sourceforge.jrefactory.ast.ASTUnmodifiedClassDeclaration;
013: import net.sourceforge.jrefactory.ast.ASTUnmodifiedInterfaceDeclaration;
014: import net.sourceforge.jrefactory.parser.ChildrenVisitor;
015: import net.sourceforge.jrefactory.ast.SimpleNode;
016:
017: import java.util.Stack;
018:
019: /**
020: * Serves as a sort of adaptor between the AST nodes and the symbol table scopes
021: */
022: public class BasicScopeCreationVisitor extends ChildrenVisitor {
023:
024: private ScopeFactory sf;
025: private Stack scopes = new Stack();
026:
027: public BasicScopeCreationVisitor(ScopeFactory sf) {
028: this .sf = sf;
029: }
030:
031: public Object visit(ASTCompilationUnit node, Object data) {
032: sf.openScope(scopes, node);
033: cont(node);
034: return data;
035: }
036:
037: public Object visit(ASTUnmodifiedClassDeclaration node, Object data) {
038: sf.openScope(scopes, node);
039: cont(node);
040: return data;
041: }
042:
043: public Object visit(ASTClassBodyDeclaration node, Object data) {
044: if (node.isAnonymousInnerClass()) {
045: sf.openScope(scopes, node);
046: cont(node);
047: } else {
048: super .visit(node, data);
049: }
050: return data;
051: }
052:
053: public Object visit(ASTUnmodifiedInterfaceDeclaration node,
054: Object data) {
055: sf.openScope(scopes, node);
056: cont(node);
057: return data;
058: }
059:
060: public Object visit(ASTBlock node, Object data) {
061: sf.openScope(scopes, node);
062: cont(node);
063: return data;
064: }
065:
066: public Object visit(ASTConstructorDeclaration node, Object data) {
067: sf.openScope(scopes, node);
068: cont(node);
069: return data;
070: }
071:
072: public Object visit(ASTMethodDeclaration node, Object data) {
073: sf.openScope(scopes, node);
074: cont(node);
075: return data;
076: }
077:
078: public Object visit(ASTTryStatement node, Object data) {
079: sf.openScope(scopes, node);
080: cont(node);
081: return data;
082: }
083:
084: public Object visit(ASTForStatement node, Object data) {
085: sf.openScope(scopes, node);
086: cont(node);
087: return data;
088: }
089:
090: public Object visit(ASTIfStatement node, Object data) {
091: sf.openScope(scopes, node);
092: cont(node);
093: return data;
094: }
095:
096: public Object visit(ASTSwitchStatement node, Object data) {
097: sf.openScope(scopes, node);
098: cont(node);
099: return data;
100: }
101:
102: private void cont(SimpleNode node) {
103: super.visit(node, null);
104: scopes.pop();
105: }
106: }
|