diff --git a/src/org/ntlab/deltaViewer/CollaborationObjectCallGraph.java b/src/org/ntlab/deltaViewer/CollaborationObjectCallGraph.java index 77852c3..ff118a1 100644 --- a/src/org/ntlab/deltaViewer/CollaborationObjectCallGraph.java +++ b/src/org/ntlab/deltaViewer/CollaborationObjectCallGraph.java @@ -5,12 +5,15 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.stream.Collectors; import org.ntlab.deltaExtractor.ExtractedStructure; import org.ntlab.trace.MethodExecution; +import org.ntlab.trace.MethodInvocation; import org.ntlab.trace.Reference; +import org.ntlab.trace.Statement; import org.ntlab.trace.TracePoint; /** @@ -123,12 +126,13 @@ return sortedTpList; } - public void shrinkAll() { + public void shrinkAll(Map> newToOldMethodExecutionMap) { List refs = getReferences(); List collectionReferences = collectCollectionReferences(refs); List> collectionChains = collectCollectionChains(collectionReferences); refs = replaceCollectionChains(refs, collectionChains); - references = new HashSet<>(refs); + references = new HashSet<>(refs); // Convert to Set from List. + relatedPoints = replaceRelatedPoints(relatedPoints, newToOldMethodExecutionMap); // For debug. System.out.println("collectionReferences: "); @@ -171,9 +175,9 @@ String srcClassName = ref.getSrcClassName(); String srcObjId = ref.getSrcObjectId(); boolean isFirstRef = true; - for (int j = 0; j < collectionRefs.size(); j++) { - if (i != j) { - Reference compareRef = collectionRefs.get(j); + for (int j = 0; j < collectionReferences.size(); j++) { + if (collectionReferences.indexOf(ref) != j) { + Reference compareRef = collectionReferences.get(j); if (srcClassName.equals(compareRef.getDstClassName()) && srcObjId.equals(compareRef.getDstObjectId())) { isFirstRef = false; @@ -238,7 +242,32 @@ replacedReferences.add(newRef); // Add new reference. } return replacedReferences; - + } + + /** + * Replace calledMethodExec in relatedPoints to newMethodExec. + * @param relatedPoints + * @param newToOldMethodExecutionMap + * @return Replaced related points. + */ + private List replaceRelatedPoints(List relatedPoints, Map> newToOldMethodExecutionMap) { + List replacedRp = new ArrayList<>(relatedPoints); + for (TracePoint rp: replacedRp) { + Statement st = rp.getStatement(); + if (st instanceof MethodInvocation) { + MethodInvocation methodInv = (MethodInvocation)st; + MethodExecution calledMethodExec = methodInv.getCalledMethodExecution(); + for (Entry> entry: newToOldMethodExecutionMap.entrySet()) { + MethodExecution newMethodExec = entry.getKey(); + Set oldMethodExecSet = entry.getValue(); + if (oldMethodExecSet.contains(calledMethodExec)) { + methodInv.setCalledMethodExecution(newMethodExec); + } + } + + } + } + return replacedRp; } }