View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.java.dfa;
5   
6   import java.util.ArrayList;
7   import java.util.List;
8   
9   import net.sourceforge.pmd.lang.dfa.DFAGraphMethod;
10  import net.sourceforge.pmd.lang.dfa.DFAGraphRule;
11  import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
12  import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
13  import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
14  
15  public class JavaDFAGraphRule extends AbstractJavaRule implements DFAGraphRule {
16  
17      private List<DFAGraphMethod> methods;
18  
19      public JavaDFAGraphRule() {
20  	super.setUsesDFA();
21      }
22  
23      public List<DFAGraphMethod> getMethods() {
24  	return this.methods;
25      }
26  
27      @Override
28      public Object visit(ASTMethodDeclaration node, Object data) {
29  	methods.add(node);
30  	return super.visit(node, data);
31      }
32  
33      @Override
34      public Object visit(ASTCompilationUnit acu, Object data) {
35  	methods = new ArrayList<>();
36  	return super.visit(acu, data);
37      }
38  }