diff --git a/src/org/ntlab/deltaExtractor/Alias.java b/src/org/ntlab/deltaExtractor/Alias.java index 054ecba..f62d75a 100644 --- a/src/org/ntlab/deltaExtractor/Alias.java +++ b/src/org/ntlab/deltaExtractor/Alias.java @@ -94,6 +94,10 @@ } } + public void setObjectId(String objectId) { + this.objectId = objectId; + } + @Override public int hashCode() { final int prime = 31; diff --git a/src/org/ntlab/deltaViewer/CollaborationObjectCallGraph.java b/src/org/ntlab/deltaViewer/CollaborationObjectCallGraph.java index ba4c972..fff5242 100644 --- a/src/org/ntlab/deltaViewer/CollaborationObjectCallGraph.java +++ b/src/org/ntlab/deltaViewer/CollaborationObjectCallGraph.java @@ -55,7 +55,8 @@ /** * Merge ExtractedStructure not to overlap reference. - * @param e ExtractedStructure to be merged into the field. + * + * @param e: ExtractedStructure to be merged into the field. */ public void merge(ExtractedStructure e) { // references.addAll(e.getDelta().getSrcSide()); @@ -123,11 +124,12 @@ } /** - * Search lowest common ancestor(lca) of p and q. + * Search lowest common ancestor(LCA) of p and q. + * * @param root * @param p * @param q - * @return Lca methodExecution. + * @return LCA MethodExecution */ public MethodExecution lowestCommonAncestor(MethodExecution root, MethodExecution p, MethodExecution q) { if(root == null || root == p || root == q) return root; @@ -147,9 +149,10 @@ } /** - * Sort tracePoint in time stamp order. - * @param tpList TracePoint List to sort. - * @return Sorted TracePoint List. + * Sort TracePoint in time stamp order. + * + * @param tpList: TracePoint list to sort. + * @return sorted TracePoint list */ private List sortTracePointByTimeStamp(List tpList) { List cloneTpList = new ArrayList<>(tpList); @@ -171,6 +174,7 @@ List collectionReferences = collectCollectionReferences(refs); List> collectionChains = collectCollectionChains(collectionReferences); refs = replaceCollectionChains(refs, collectionChains); + refs = replaceStaticObjectIds(refs); references = new HashSet<>(refs); // Convert to Set from List. relatedPoints = replaceRelatedPoints(relatedPoints, newToOldMethodExecutionMap); @@ -288,7 +292,27 @@ } /** - * Replace calledMethodExec in relatedPoints to newMethodExec. + * Replace objectId of {@code ObjectReference} of static object in references. + * + * @param references + * @return + */ + private List replaceStaticObjectIds(List references) { + List replacedReferences = new ArrayList<>(references); + for (Reference ref: replacedReferences) { + if (ref.getSrcObjectId().matches("0")) { + ref.setSrcObjectId(ref.getSrcObjectId() + ":" + ref.getSrcClassName()); + } + if (ref.getDstObjectId().matches("0")) { + ref.setDstObjectId(ref.getDstObjectId() + ":" + ref.getDstClassName()); + } + } + return replacedReferences; + } + + /** + * Replace called MethodExecution in relatedPoints to new MethodExecution. + * * @param relatedPoints * @param newToOldMethodExecutionMap * @return Replaced related points. diff --git a/src/org/ntlab/deltaViewer/CollaborationViewer.java b/src/org/ntlab/deltaViewer/CollaborationViewer.java index 84676cf..70a332e 100644 --- a/src/org/ntlab/deltaViewer/CollaborationViewer.java +++ b/src/org/ntlab/deltaViewer/CollaborationViewer.java @@ -360,11 +360,7 @@ String coordinatorObjId = coordinator.getThisObjId(); String coordinatorClassName = coordinator.getThisClassName(); mxICell vertex = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), coordinatorObjId, coordinatorClassName, 0, 0, DEFAULT_OBJECT_VERTEX_SIZE.getWidth(), DEFAULT_OBJECT_VERTEX_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. - if (!coordinatorObjId.matches("0")) { - objectToVertexMap.put(coordinatorObjId, new ObjectVertex(coordinatorClassName, vertex, 0, 0)); - } else { // When static class. - objectToVertexMap.put(coordinatorObjId + ":" + coordinatorClassName, new ObjectVertex(coordinatorClassName, vertex, 0, 0)); - } + objectToVertexMap.put(coordinatorObjId, new ObjectVertex(coordinatorClassName, vertex, 0, 0)); } for (int i = 0; i < refList.size(); i++) { @@ -378,9 +374,8 @@ if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); } - String srcKey = srcObjId.matches("0") ? srcObjId + ":" + srcClassName : srcObjId; // Static class or not. mxICell vertex = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), srcObjId, srcClassName, 0, 0, objecVertexWidth, ObjectVertexHeight, "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(srcKey, new ObjectVertex(ref.getSrcClassName(), vertex, 0, 0)); + objectToVertexMap.put(srcObjId, new ObjectVertex(ref.getSrcClassName(), vertex, 0, 0)); } // dstSide if (!objectToVertexMap.containsKey(ref.getDstObjectId())) { @@ -390,9 +385,8 @@ if (dstClassName.contains("[L")) { dstClassName = formatArrayName(dstClassName); } - String dstKey = dstObjId.matches("0") ? dstObjId + ":" + dstClassName : dstObjId; // Static class or not. mxICell vertex = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), dstObjId, dstClassName, 0, 0, objecVertexWidth, ObjectVertexHeight, "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(dstKey, new ObjectVertex(ref.getDstClassName(), vertex, 0, 0)); + objectToVertexMap.put(dstObjId, new ObjectVertex(ref.getDstClassName(), vertex, 0, 0)); } } else { if (!objectToVertexMap.containsKey(ref.getSrcObjectId())) { @@ -401,18 +395,16 @@ if (srcClassName.contains("[L")) { srcClassName = formatArrayName(srcClassName); } - String srcKey = srcObjId.matches("0") ? srcObjId + ":" + srcClassName : srcObjId; // Static class or not. mxICell vertex = (mxICell) mxgraph.insertDeltaVertex(getMxDefaultParent(), srcObjId, srcClassName, 0, 0, objecVertexWidth, ObjectVertexHeight, "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(srcKey, new ObjectVertex(ref.getSrcClassName(), vertex, 0, 0)); + objectToVertexMap.put(srcObjId, new ObjectVertex(ref.getSrcClassName(), vertex, 0, 0)); } String dstObjId = ref.getDstObjectId(); - String dstClassName = ref.getDstClassName(); - String dstKey = dstObjId.matches("0") ? dstObjId + ":" + dstClassName : dstObjId; // Static class or not. if (!objectToVertexMap.containsKey(dstObjId)) { - objectToVertexMap.put(dstKey, new ObjectVertex(dstClassName, null, 0, 0)); + String dstClassName = ref.getDstClassName(); + objectToVertexMap.put(dstObjId, new ObjectVertex(dstClassName, null, 0, 0)); } else { - mxgraph.removeCells(new Object[] {objectToVertexMap.get(dstKey).getCell()}); - objectToVertexMap.get(dstKey).setCell(null); + mxgraph.removeCells(new Object[] {objectToVertexMap.get(dstObjId).getCell()}); + objectToVertexMap.get(dstObjId).setCell(null); } } } diff --git a/src/org/ntlab/deltaViewer/DeltaAliasCollector.java b/src/org/ntlab/deltaViewer/DeltaAliasCollector.java index c55a93b..61409b2 100644 --- a/src/org/ntlab/deltaViewer/DeltaAliasCollector.java +++ b/src/org/ntlab/deltaViewer/DeltaAliasCollector.java @@ -90,7 +90,8 @@ aliasList = replaceInvocationChains(aliasList, invocationChains); Map> newToOldMethodExecMap = collectNewToOldMethodExecutionMap(oldAliasList, aliasList); aliasList = removeEnclosingInstanceAccessor(aliasList, newToOldMethodExecMap); - + aliasList = replaceStaticObjectIds(aliasList); + // for debug. System.out.println("standardMethodInvocations: "); for (Alias alias: standardMethodInvocations) { @@ -294,7 +295,23 @@ } } return replacedAliasList; - } + } + + /** + * Replace objectId of {@code Alias} of static object in aliasList. + * + * @param aliasList + * @return + */ + private List replaceStaticObjectIds(List aliasList) { + List replacedAliasList = new ArrayList<>(aliasList); + for (Alias alias: replacedAliasList) { + if (alias.getObjectId().matches("0")) { + alias.setObjectId(alias.getObjectId() + ":" + alias.getMethodExecution().getThisClassName()); + } + } + return replacedAliasList; + } private List removeEnclosingInstanceAccessor(List aliasList, Map> newToOldMethodExecMap) { List removedAliasList = new ArrayList<>(aliasList); diff --git a/src/org/ntlab/deltaViewer/MagnetRONViewer.java b/src/org/ntlab/deltaViewer/MagnetRONViewer.java index c991f1b..62be2ee 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONViewer.java +++ b/src/org/ntlab/deltaViewer/MagnetRONViewer.java @@ -1328,7 +1328,7 @@ for (Entry objectToVertexEntry: objectToVertexMap.entrySet()) { String key = objectToVertexEntry.getKey(); ObjectVertex ov = objectToVertexEntry.getValue(); - if (key.matches("0")) { + if (key.startsWith("0")) { staticObjectVertex.add(ov.getCell()); } else { objectVertex.add(ov.getCell());