86edb08d6c463b158ab56114acda1af13e9703f8
[IRC.git] / Robust / src / Analysis / SSJava / FlowNode.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.Iterator;
5 import java.util.Set;
6
7 import IR.Descriptor;
8
9 public class FlowNode {
10
11   // descriptor tuple is a unique identifier of the flow node
12   private NTuple<Descriptor> descTuple;
13
14   // if the infer node represents the base type of field access,
15   // this set contains fields of the base type
16   private Set<FlowNode> fieldNodeSet;
17
18   public Set<FlowNode> getFieldNodeSet() {
19     return fieldNodeSet;
20   }
21
22   private Set<FlowEdge> outEdgeSet;
23
24   public FlowNode(NTuple<Descriptor> tuple) {
25
26     NTuple<Descriptor> base = null;
27     Descriptor desc = null;
28     if (tuple.size() > 1) {
29       base = tuple.subList(0, tuple.size() - 1);
30       desc = tuple.get(tuple.size() - 1);
31     } else {
32       base = tuple;
33     }
34     fieldNodeSet = new HashSet<FlowNode>();
35     descTuple = new NTuple<Descriptor>();
36     if (base != null) {
37       descTuple.addAll(base);
38     }
39     if (desc != null) {
40       descTuple.add(desc);
41     }
42     outEdgeSet = new HashSet<FlowEdge>();
43   }
44
45   public void addFieldNode(FlowNode node) {
46     fieldNodeSet.add(node);
47   }
48
49   public NTuple<Descriptor> getDescTuple() {
50     return descTuple;
51   }
52
53   public Descriptor getOwnDescriptor() {
54     return descTuple.get(descTuple.size() - 1);
55   }
56
57   public String toString() {
58     return "[FlowNode]::" + descTuple;
59   }
60
61   public Iterator<FlowEdge> iteratorOfOutEdges() {
62     return outEdgeSet.iterator();
63   }
64
65   public void addOutEdge(FlowEdge out) {
66     outEdgeSet.add(out);
67   }
68
69   public Set<FlowEdge> getOutEdgeSet() {
70     return outEdgeSet;
71   }
72
73   public int hashCode() {
74     return 7 + descTuple.hashCode();
75   }
76
77   public boolean equals(Object obj) {
78
79     if (obj instanceof FlowNode) {
80       FlowNode in = (FlowNode) obj;
81       if (descTuple.equals(in.getDescTuple())) {
82         return true;
83       }
84     }
85
86     return false;
87
88   }
89
90   public String getID() {
91     String id = "";
92     for (int i = 0; i < descTuple.size(); i++) {
93       id += descTuple.get(i).getSymbol();
94     }
95     return id;
96   }
97
98   public String getPrettyID() {
99     String id = "<";
100     for (int i = 0; i < descTuple.size(); i++) {
101       if (i != 0) {
102         id += ",";
103       }
104       id += descTuple.get(i).getSymbol();
105     }
106     id += ">";
107     return id;
108   }
109 }