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 |
1
| public CurrentPath() {
|
14 |
1
| list = new LinkedList();
|
15 |
| } |
16 |
| |
17 |
0
| public Iterator iterator() {
|
18 |
0
| return list.iterator();
|
19 |
| } |
20 |
| |
21 |
0
| public IDataFlowNode getLast() {
|
22 |
0
| return (IDataFlowNode) list.getLast();
|
23 |
| } |
24 |
| |
25 |
0
| public void removeLast() {
|
26 |
0
| list.removeLast();
|
27 |
| } |
28 |
| |
29 |
0
| public boolean isEmpty() {
|
30 |
0
| return list.isEmpty();
|
31 |
| } |
32 |
| |
33 |
0
| public void addLast(IDataFlowNode n) {
|
34 |
0
| list.addLast(n);
|
35 |
| } |
36 |
| |
37 |
0
| public boolean isDoBranchNode() {
|
38 |
0
| return ((IDataFlowNode) list.getLast()).isType(NodeType.DO_EXPR);
|
39 |
| } |
40 |
| |
41 |
0
| public boolean isFirstDoStatement() {
|
42 |
0
| return isFirstDoStatement((IDataFlowNode) list.getLast());
|
43 |
| } |
44 |
| |
45 |
0
| public IDataFlowNode getDoBranchNodeFromFirstDoStatement() {
|
46 |
0
| IDataFlowNode inode = (IDataFlowNode) list.getLast();
|
47 |
0
| if (!isFirstDoStatement()) return null;
|
48 |
0
| for (int i = 0; i < inode.getParents().size(); i++) {
|
49 |
0
| IDataFlowNode parent = (IDataFlowNode) inode.getParents().get(i);
|
50 |
0
| if (parent.isType(NodeType.DO_EXPR)) {
|
51 |
0
| return parent;
|
52 |
| } |
53 |
| } |
54 |
0
| return null;
|
55 |
| } |
56 |
| |
57 |
0
| public boolean isEndNode() {
|
58 |
0
| return ((IDataFlowNode) list.getLast()).getChildren().size() == 0;
|
59 |
| |
60 |
| } |
61 |
| |
62 |
0
| public boolean isBranch() {
|
63 |
0
| return ((IDataFlowNode) list.getLast()).getChildren().size() > 1;
|
64 |
| } |
65 |
| |
66 |
0
| private boolean isFirstDoStatement(IDataFlowNode inode) {
|
67 |
0
| int index = inode.getIndex() - 1;
|
68 |
0
| if (index < 0) return false;
|
69 |
0
| return ((IDataFlowNode) inode.getFlow().get(index)).isType(NodeType.DO_BEFORE_FIRST_STATEMENT);
|
70 |
| } |
71 |
| } |
72 |
| |