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