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) {
61 return mapLocSymbolToRelatedInferLocSet.get(locSymbol);
64 public void mapDescriptorToLocation(Descriptor desc, CompositeLocation inferLoc) {
65 mapDescToInferCompositeLocation.put(desc, inferLoc);
68 public CompositeLocation getInferLocation(Descriptor desc) {
69 if (!mapDescToInferCompositeLocation.containsKey(desc)) {
70 CompositeLocation newInferLoc = new CompositeLocation();
72 Descriptor enclosingDesc;
79 loc = new Location(enclosingDesc, desc.getSymbol());
81 newInferLoc.addLocation(loc);
82 mapDescToInferCompositeLocation.put(desc, newInferLoc);
83 // addMapLocSymbolToDescSet(desc.getSymbol(), desc);
84 addMapLocSymbolToRelatedInferLoc(desc.getSymbol(), enclosingDesc, desc);
86 return mapDescToInferCompositeLocation.get(desc);
89 public void addMapLocSymbolToDescSet(String locSymbol, Descriptor desc) {
90 if (!mapLocSymbolToDescSet.containsKey(locSymbol)) {
91 mapLocSymbolToDescSet.put(locSymbol, new HashSet<Descriptor>());
93 mapLocSymbolToDescSet.get(locSymbol).add(desc);
96 public Location getFieldInferLocation(Descriptor desc) {
97 return getInferLocation(desc).get(0);
100 public Set<Descriptor> getDescSet(String locSymbol) {
101 if (!mapLocSymbolToDescSet.containsKey(locSymbol)) {
102 mapLocSymbolToDescSet.put(locSymbol, new HashSet<Descriptor>());
104 return mapLocSymbolToDescSet.get(locSymbol);
107 public void removeRelatedInferLocSet(String oldLocSymbol, String newSharedLoc) {
108 Set<Descriptor> descSet = getDescSet(oldLocSymbol);
109 getDescSet(newSharedLoc).addAll(descSet);
110 // getRelatedInferLocSet(newSharedLoc).addAll(getRelatedInferLocSet(oldLocSymbol));
111 mapLocSymbolToDescSet.remove(oldLocSymbol);
112 mapLocSymbolToRelatedInferLocSet.remove(oldLocSymbol);