|
1 |
| package net.sourceforge.pmd.dfa.pathfinder; |
|
2 |
| |
|
3 |
| import net.sourceforge.pmd.dfa.IDataFlowNode; |
|
4 |
| import net.sourceforge.pmd.dfa.NodeType; |
|
5 |
| |
|
6 |
| import java.util.Iterator; |
|
7 |
| import java.util.LinkedList; |
|
8 |
| |
|
9 |
| public class CurrentPath { |
|
10 |
| |
|
11 |
| private LinkedList list; |
|
12 |
| |
|
13 |
6
| public CurrentPath() {
|
|
14 |
6
| list = new LinkedList();
|
|
15 |
| } |
|
16 |
| |
|
17 |
0
| public int getLength() {
|
|
18 |
0
| return list.size();
|
|
19 |
| } |
|
20 |
| |
|
21 |
7
| public Iterator iterator() {
|
|
22 |
7
| return list.iterator();
|
|
23 |
| } |
|
24 |
| |
|
25 |
31
| public IDataFlowNode getLast() {
|
|
26 |
31
| return (IDataFlowNode) list.getLast();
|
|
27 |
| } |
|
28 |
| |
|
29 |
33
| public void removeLast() {
|
|
30 |
33
| list.removeLast();
|
|
31 |
| } |
|
32 |
| |
|
33 |
40
| public boolean isEmpty() {
|
|
34 |
40
| return list.isEmpty();
|
|
35 |
| } |
|
36 |
| |
|
37 |
33
| public void addLast(IDataFlowNode n) {
|
|
38 |
33
| list.addLast(n);
|
|
39 |
| |
|
40 |
| } |
|
41 |
| |
|
42 |
4
| public boolean isDoBranchNode() {
|
|
43 |
4
| return ((IDataFlowNode) list.getLast()).isType(NodeType.DO_EXPR);
|
|
44 |
| } |
|
45 |
| |
|
46 |
26
| public boolean isFirstDoStatement() {
|
|
47 |
26
| return isFirstDoStatement((IDataFlowNode) list.getLast());
|
|
48 |
| } |
|
49 |
| |
|
50 |
0
| public IDataFlowNode getDoBranchNodeFromFirstDoStatement() {
|
|
51 |
0
| IDataFlowNode inode = (IDataFlowNode) list.getLast();
|
|
52 |
0
| if (!isFirstDoStatement()) return null;
|
|
53 |
0
| for (int i = 0; i < inode.getParents().size(); i++) {
|
|
54 |
0
| IDataFlowNode parent = (IDataFlowNode) inode.getParents().get(i);
|
|
55 |
0
| if (parent.isType(NodeType.DO_EXPR)) {
|
|
56 |
0
| return parent;
|
|
57 |
| } |
|
58 |
| } |
|
59 |
0
| return null;
|
|
60 |
| } |
|
61 |
| |
|
62 |
35
| public boolean isEndNode() {
|
|
63 |
35
| return ((IDataFlowNode) list.getLast()).getChildren().size() == 0;
|
|
64 |
| |
|
65 |
| } |
|
66 |
| |
|
67 |
94
| public boolean isBranch() {
|
|
68 |
94
| return ((IDataFlowNode) list.getLast()).getChildren().size() > 1;
|
|
69 |
| } |
|
70 |
| |
|
71 |
26
| private boolean isFirstDoStatement(IDataFlowNode inode) {
|
|
72 |
26
| int index = inode.getIndex() - 1;
|
|
73 |
5
| if (index < 0) return false;
|
|
74 |
21
| return ((IDataFlowNode) inode.getFlow().get(index)).isType(NodeType.DO_BEFORE_FIRST_STATEMENT);
|
|
75 |
| } |
|
76 |
| } |
|
77 |
| |