1 package Analysis.SSJava;
3 import java.util.HashMap;
4 import java.util.HashSet;
8 import IR.ClassDescriptor;
10 import IR.MethodDescriptor;
13 public class LocationInfo {
15 Map<String, Set<Descriptor>> mapLocSymbolToDescSet;
16 Map<String, Set<Pair<Descriptor, Descriptor>>> mapLocSymbolToRelatedInferLocSet;
17 Map<Descriptor, CompositeLocation> mapDescToInferCompositeLocation;
21 public LocationInfo() {
22 mapDescToInferCompositeLocation = new HashMap<Descriptor, CompositeLocation>();
23 mapLocSymbolToDescSet = new HashMap<String, Set<Descriptor>>();
24 mapLocSymbolToRelatedInferLocSet = new HashMap<String, Set<Pair<Descriptor, Descriptor>>>();
27 public LocationInfo(ClassDescriptor cd) {
32 public Descriptor getDescIdentifier() {
41 public Map<String, Set<Descriptor>> getMapLocSymbolToDescSet() {
42 return mapLocSymbolToDescSet;
45 public Map<Descriptor, CompositeLocation> getMapDescToInferLocation() {
46 return mapDescToInferCompositeLocation;
49 public void addMapLocSymbolToRelatedInferLoc(String locSymbol, Descriptor enclosingDesc,
51 if (!mapLocSymbolToRelatedInferLocSet.containsKey(locSymbol)) {
52 mapLocSymbolToRelatedInferLocSet.put(locSymbol, new HashSet<Pair<Descriptor, Descriptor>>());
54 mapLocSymbolToRelatedInferLocSet.get(locSymbol).add(
55 new Pair<Descriptor, Descriptor>(enclosingDesc, desc));
57 addMapLocSymbolToDescSet(locSymbol, desc);
60 public Set<Pair<Descriptor, Descriptor>> getRelatedInferLocSet(String locSymbol) {
62 if (!mapLocSymbolToRelatedInferLocSet.containsKey(locSymbol)) {
63 mapLocSymbolToRelatedInferLocSet.put(locSymbol, new HashSet<Pair<Descriptor, Descriptor>>());
65 return mapLocSymbolToRelatedInferLocSet.get(locSymbol);
68 public void mapDescriptorToLocation(Descriptor desc, CompositeLocation inferLoc) {
69 mapDescToInferCompositeLocation.put(desc, inferLoc);
72 public CompositeLocation getInferLocation(Descriptor desc) {
73 if (!mapDescToInferCompositeLocation.containsKey(desc)) {
74 CompositeLocation newInferLoc = new CompositeLocation();
76 Descriptor enclosingDesc;
83 loc = new Location(enclosingDesc, desc.getSymbol());
85 newInferLoc.addLocation(loc);
86 mapDescToInferCompositeLocation.put(desc, newInferLoc);
87 // addMapLocSymbolToDescSet(desc.getSymbol(), desc);
88 addMapLocSymbolToRelatedInferLoc(desc.getSymbol(), enclosingDesc, desc);
90 return mapDescToInferCompositeLocation.get(desc);
93 public void addMapLocSymbolToDescSet(String locSymbol, Descriptor desc) {
94 if (!mapLocSymbolToDescSet.containsKey(locSymbol)) {
95 mapLocSymbolToDescSet.put(locSymbol, new HashSet<Descriptor>());
97 mapLocSymbolToDescSet.get(locSymbol).add(desc);
100 public Location getFieldInferLocation(Descriptor desc) {
101 return getInferLocation(desc).get(0);
104 public Set<Descriptor> getDescSet(String locSymbol) {
105 if (!mapLocSymbolToDescSet.containsKey(locSymbol)) {
106 mapLocSymbolToDescSet.put(locSymbol, new HashSet<Descriptor>());
108 return mapLocSymbolToDescSet.get(locSymbol);
111 public void removeRelatedInferLocSet(String oldLocSymbol, String newSharedLoc) {
112 Set<Descriptor> descSet = getDescSet(oldLocSymbol);
113 getDescSet(newSharedLoc).addAll(descSet);
114 // getRelatedInferLocSet(newSharedLoc).addAll(getRelatedInferLocSet(oldLocSymbol));
115 mapLocSymbolToDescSet.remove(oldLocSymbol);
116 mapLocSymbolToRelatedInferLocSet.remove(oldLocSymbol);