View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.plsql.dfa;
5   
6   import java.util.logging.Logger;
7   
8   import net.sourceforge.pmd.lang.DataFlowHandler;
9   import net.sourceforge.pmd.lang.plsql.ast.ASTCompoundTriggerBlock;
10  import net.sourceforge.pmd.lang.plsql.ast.ASTInput;
11  import net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclaration;
12  import net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit;
13  import net.sourceforge.pmd.lang.plsql.ast.ASTTriggerTimingPointSection;
14  import net.sourceforge.pmd.lang.plsql.ast.ASTTriggerUnit;
15  import net.sourceforge.pmd.lang.plsql.ast.ASTTypeMethod;
16  import net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitorAdapter;
17  
18  /**
19   * @author raik
20   *         <p/>
21   *         TODO What about initializers?  This only processes methods and constructors
22   */
23  public class DataFlowFacade extends PLSQLParserVisitorAdapter {
24      private final static String CLASS_PATH= DataFlowFacade.class.getCanonicalName();
25      private final static Logger LOGGER = Logger.getLogger(DataFlowFacade.class.getName()); 
26  
27      private StatementAndBraceFinder sbf;
28      private VariableAccessVisitor vav;
29  
30      public void initializeWith(DataFlowHandler dataFlowHandler, ASTInput node) {
31          sbf = new StatementAndBraceFinder(dataFlowHandler);
32          vav = new VariableAccessVisitor();
33          node.jjtAccept(this, null);
34      }
35  
36      public Object visit(ASTMethodDeclaration node, Object data) {
37          LOGGER.entering(CLASS_PATH,"visit(ASTMethodDeclaration)");
38          LOGGER.finest("visit(ASTMethodDeclaration): " 
39                        + node.getClass().getCanonicalName() + " @ line " 
40                        + node.getBeginLine() 
41                        +", column " + node.getBeginColumn()
42                        + " --- " + new Throwable().getStackTrace()
43                  );
44  
45          super.visit(node, data) ;
46          sbf.buildDataFlowFor(node);
47          vav.compute(node);
48          LOGGER.exiting(CLASS_PATH,"visit(ASTMethodDeclaration)");
49          return data;
50      }
51  
52      public Object visit(ASTTriggerUnit node, Object data) {
53          LOGGER.entering(CLASS_PATH,"visit(ASTTriggerUnit)");
54          LOGGER.finest("visit(ASTTriggerUnit): " 
55                        + node.getClass().getCanonicalName() + " @ line " 
56                        + node.getBeginLine() 
57                        +", column " + node.getBeginColumn()
58                        + " --- " + new Throwable().getStackTrace()
59                  );
60          if (node.hasDescendantOfType(ASTCompoundTriggerBlock.class))
61          {
62            LOGGER.finest("visit(ASTTriggerUnit): treating ASTTriggerUnit like a PackageBody " 
63                          + node.getClass().getCanonicalName() + " @ line " 
64                          + node.getBeginLine() 
65                          +", column " + node.getBeginColumn()
66                          + " --- " + new Throwable().getStackTrace()
67                        );
68            //Pass
69            super.visit(node, data) ;
70          }
71          {
72            LOGGER.finest("visit(ASTTriggerUnit): treating ASTTriggerUnit as standalone " 
73                          + node.getClass().getCanonicalName() + " @ line " 
74                          + node.getBeginLine() 
75                          +", column " + node.getBeginColumn()
76                          + " --- " + new Throwable().getStackTrace()
77                        );
78            sbf.buildDataFlowFor(node);
79            vav.compute(node);
80          }
81          LOGGER.exiting(CLASS_PATH,"visit(ASTTriggerUnit)");
82          return data;
83      }
84  
85      public Object visit(ASTTriggerTimingPointSection node, Object data) {
86          LOGGER.entering(CLASS_PATH,"visit(ASTTriggerTimingPointSection)");
87          LOGGER.finest("visit(ASTTriggerTimingPointSection): " 
88                        + node.getClass().getCanonicalName() + " @ line " 
89                        + node.getBeginLine() 
90                        +", column " + node.getBeginColumn()
91                        + " --- " + new Throwable().getStackTrace()
92                  );
93          sbf.buildDataFlowFor(node);
94          vav.compute(node);
95          LOGGER.exiting(CLASS_PATH,"visit(ASTProgramUnit)");
96          return data;
97      }
98  
99      public Object visit(ASTProgramUnit node, Object data) {
100         LOGGER.entering(CLASS_PATH,"visit(ASTProgramUnit)");
101         LOGGER.finest("visit(ASTProgramUnit): " 
102                       + node.getClass().getCanonicalName() + " @ line " 
103                       + node.getBeginLine() 
104                       +", column " + node.getBeginColumn()
105                       + " --- " + new Throwable().getStackTrace()
106                 );
107         sbf.buildDataFlowFor(node);
108         vav.compute(node);
109         LOGGER.exiting(CLASS_PATH,"visit(ASTProgramUnit)");
110         return data;
111     }
112 
113     public Object visit(ASTTypeMethod node, Object data) {
114         LOGGER.entering(CLASS_PATH,"visit(ASTTypeMethod)");
115         LOGGER.finest("visit(ASTTypeMethod): " 
116                       + node.getClass().getCanonicalName() + " @ line " 
117                       + node.getBeginLine() 
118                       +", column " + node.getBeginColumn()
119                       + " --- " + new Throwable().getStackTrace()
120                 );
121         sbf.buildDataFlowFor(node);
122         vav.compute(node);
123         LOGGER.exiting(CLASS_PATH,"visit(ASTTypeMethod)");
124         return data;
125     }
126 
127     /*
128     public Object visit(ASTConstructorDeclaration node, Object data) {
129         sbf.buildDataFlowFor(node);
130         vav.compute(node);
131         return data;
132     }
133     */
134 }