1 |
| |
2 |
| |
3 |
| |
4 |
| package net.sourceforge.pmd.dfa; |
5 |
| |
6 |
| import net.sourceforge.pmd.AbstractRule; |
7 |
| import net.sourceforge.pmd.RuleContext; |
8 |
| import net.sourceforge.pmd.ast.ASTMethodDeclaration; |
9 |
| import net.sourceforge.pmd.dfa.pathfinder.CurrentPath; |
10 |
| import net.sourceforge.pmd.dfa.pathfinder.DAAPathFinder; |
11 |
| import net.sourceforge.pmd.dfa.pathfinder.Executable; |
12 |
| import net.sourceforge.pmd.dfa.variableaccess.VariableAccess; |
13 |
| |
14 |
| import java.util.ArrayList; |
15 |
| import java.util.Hashtable; |
16 |
| import java.util.Iterator; |
17 |
| import java.util.List; |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| public class DaaRule extends AbstractRule implements Executable { |
25 |
| |
26 |
| private RuleContext rc; |
27 |
| private int counter; |
28 |
| private static final int MAX_PATHS = 5000; |
29 |
| |
30 |
0
| public Object visit(ASTMethodDeclaration node, Object data) {
|
31 |
0
| this.rc = (RuleContext) data;
|
32 |
0
| counter = 0;
|
33 |
| |
34 |
0
| IDataFlowNode n = (IDataFlowNode) node.getDataFlowNode().getFlow().get(0);
|
35 |
0
| System.out.println("In DaaRule, IDataFlowNode n = " + n);
|
36 |
| |
37 |
0
| DAAPathFinder a = new DAAPathFinder(n, this);
|
38 |
0
| a.run();
|
39 |
| |
40 |
0
| super.visit(node, data);
|
41 |
0
| return data;
|
42 |
| } |
43 |
| |
44 |
0
| public void execute(CurrentPath path) {
|
45 |
0
| Hashtable hash = new Hashtable();
|
46 |
0
| counter++;
|
47 |
0
| if (counter == 5000) {
|
48 |
0
| System.out.print("|");
|
49 |
0
| counter = 0;
|
50 |
| } |
51 |
0
| for (Iterator d = path.iterator(); d.hasNext();) {
|
52 |
0
| IDataFlowNode inode = (IDataFlowNode) d.next();
|
53 |
0
| if (inode.getVariableAccess() != null) {
|
54 |
0
| for (int g = 0; g < inode.getVariableAccess().size(); g++) {
|
55 |
0
| VariableAccess va = (VariableAccess) inode.getVariableAccess().get(g);
|
56 |
| |
57 |
0
| Object o = hash.get(va.getVariableName());
|
58 |
0
| if (o != null) {
|
59 |
0
| List array = (List) o;
|
60 |
0
| int last = ((Integer) array.get(0)).intValue();
|
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| } |
73 |
0
| List array = new ArrayList();
|
74 |
0
| array.add(new Integer(va.getAccessType()));
|
75 |
0
| array.add(new Integer(inode.getLine()));
|
76 |
0
| hash.put(va.getVariableName(), array);
|
77 |
| } |
78 |
| } |
79 |
| } |
80 |
| } |
81 |
| } |