1 package Analysis.SSJava;
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Iterator;
9 import IR.ClassDescriptor;
11 import IR.MethodDescriptor;
14 public class LocationInfo {
16 Map<String, Set<Descriptor>> mapLocSymbolToDescSet;
17 Map<String, Set<Pair<Descriptor, Descriptor>>> mapLocSymbolToRelatedInferLocSet;
18 Map<Descriptor, CompositeLocation> mapDescToInferCompositeLocation;
22 public LocationInfo() {
23 mapDescToInferCompositeLocation = new HashMap<Descriptor, CompositeLocation>();
24 mapLocSymbolToDescSet = new HashMap<String, Set<Descriptor>>();
25 mapLocSymbolToRelatedInferLocSet = new HashMap<String, Set<Pair<Descriptor, Descriptor>>>();
28 public LocationInfo(ClassDescriptor cd) {
33 public Map<String, Set<Descriptor>> getMapLocSymbolToDescSet() {
34 return mapLocSymbolToDescSet;
37 public Map<Descriptor, CompositeLocation> getMapDescToInferLocation() {
38 return mapDescToInferCompositeLocation;
41 public void addMapLocSymbolToRelatedInferLoc(String locSymbol, Descriptor enclosingDesc,
43 if (!mapLocSymbolToRelatedInferLocSet.containsKey(locSymbol)) {
44 mapLocSymbolToRelatedInferLocSet.put(locSymbol, new HashSet<Pair<Descriptor, Descriptor>>());
46 mapLocSymbolToRelatedInferLocSet.get(locSymbol).add(
47 new Pair<Descriptor, Descriptor>(enclosingDesc, desc));
50 public Set<Pair<Descriptor, Descriptor>> getRelatedInferLocSet(String locSymbol) {
51 return mapLocSymbolToRelatedInferLocSet.get(locSymbol);
54 public void mapDescriptorToLocation(Descriptor desc, CompositeLocation inferLoc) {
55 mapDescToInferCompositeLocation.put(desc, inferLoc);
58 public CompositeLocation getInferLocation(Descriptor desc) {
59 if (!mapDescToInferCompositeLocation.containsKey(desc)) {
60 CompositeLocation newInferLoc = new CompositeLocation();
62 Descriptor enclosingDesc;
69 loc = new Location(enclosingDesc, desc.getSymbol());
71 newInferLoc.addLocation(loc);
72 mapDescToInferCompositeLocation.put(desc, newInferLoc);
73 addMapLocSymbolToDescSet(desc.getSymbol(), desc);
74 addMapLocSymbolToRelatedInferLoc(desc.getSymbol(), enclosingDesc, desc);
76 return mapDescToInferCompositeLocation.get(desc);
79 public void addMapLocSymbolToDescSet(String locSymbol, Descriptor desc) {
80 if (!mapLocSymbolToDescSet.containsKey(locSymbol)) {
81 mapLocSymbolToDescSet.put(locSymbol, new HashSet<Descriptor>());
83 mapLocSymbolToDescSet.get(locSymbol).add(desc);
86 public Location getFieldInferLocation(Descriptor desc) {
87 return getInferLocation(desc).get(0);
90 public Set<Descriptor> getDescSet(String locSymbol) {
91 if (!mapLocSymbolToDescSet.containsKey(locSymbol)) {
92 mapLocSymbolToDescSet.put(locSymbol, new HashSet<Descriptor>());
94 return mapLocSymbolToDescSet.get(locSymbol);
97 public void removeRelatedInferLocSet(String oldLocSymbol, String newSharedLoc) {
98 Set<Descriptor> descSet = getDescSet(oldLocSymbol);
99 getDescSet(newSharedLoc).addAll(descSet);
100 mapLocSymbolToDescSet.remove(oldLocSymbol);
101 mapLocSymbolToRelatedInferLocSet.remove(oldLocSymbol);