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