diff --git a/src/org/ntlab/deltaViewer/CollaborationLayout.java b/src/org/ntlab/deltaViewer/CollaborationLayout.java index 6b428c8..bf3aad3 100644 --- a/src/org/ntlab/deltaViewer/CollaborationLayout.java +++ b/src/org/ntlab/deltaViewer/CollaborationLayout.java @@ -21,6 +21,7 @@ import org.ntlab.trace.MethodInvocation; import org.ntlab.trace.Reference; import org.ntlab.trace.Statement; +import org.ntlab.trace.TracePoint; import com.mxgraph.model.mxICell; import com.mxgraph.util.mxPoint; @@ -37,37 +38,48 @@ padding = 200; // Extract the bottom reference. - Statement relatedSt = objectCallGraph.getRelatedPoints().get(objectCallGraph.getRelatedPoints().size() - 1).getStatement(); + TracePoint relatedPt = objectCallGraph.getRelatedPoints().get(objectCallGraph.getRelatedPoints().size() - 1); + Statement relatedSt = relatedPt.getStatement(); String bottomSrcObjId = null; String bottomDstObjId = null; - if (relatedSt instanceof FieldUpdate) { - // container to component - bottomSrcObjId = ((FieldUpdate) relatedSt).getContainerObjId(); - bottomDstObjId = ((FieldUpdate) relatedSt).getValueObjId(); - } else if (relatedSt instanceof ArrayUpdate) { - // container to component - bottomSrcObjId = ((ArrayUpdate) relatedSt).getArrayObjectId(); - bottomDstObjId = ((ArrayUpdate) relatedSt).getValueObjectId(); - } else if (relatedSt instanceof MethodInvocation) { - MethodInvocation methodInvStatement = (MethodInvocation) relatedSt; - MethodExecution calledMethodExec = methodInvStatement.getCalledMethodExecution(); - String methodSignature = calledMethodExec.getSignature(); - if (calledMethodExec.isCollectionType() - && (methodSignature.contains("add(") - || methodSignature.contains("set(") - || methodSignature.contains("put(") - || methodSignature.contains("push(") - || methodSignature.contains("addElement("))) { - // container to component - bottomSrcObjId = calledMethodExec.getThisObjId(); - bottomDstObjId = calledMethodExec.getArguments().get(0).getId(); - } else { - // this to another - bottomSrcObjId = methodInvStatement.getThisObjId(); - bottomDstObjId = calledMethodExec.getReturnValue().getId(); + if (relatedPt.isMethodEntry()) { + // this to another (parameter) + Alias lastAlias = aliasCollector.getAliasList().get(aliasCollector.getAliasList().size() - 1); + if (lastAlias.getAliasType() == Alias.AliasType.FORMAL_PARAMETER) { + bottomSrcObjId = relatedPt.getMethodExecution().getThisObjId(); + bottomDstObjId = lastAlias.getObjectId(); } - } else { - return; + } + if (bottomSrcObjId == null || bottomDstObjId == null) { + if (relatedSt instanceof FieldUpdate) { + // container to component + bottomSrcObjId = ((FieldUpdate) relatedSt).getContainerObjId(); + bottomDstObjId = ((FieldUpdate) relatedSt).getValueObjId(); + } else if (relatedSt instanceof ArrayUpdate) { + // container to component + bottomSrcObjId = ((ArrayUpdate) relatedSt).getArrayObjectId(); + bottomDstObjId = ((ArrayUpdate) relatedSt).getValueObjectId(); + } else if (relatedSt instanceof MethodInvocation) { + MethodInvocation methodInvStatement = (MethodInvocation) relatedSt; + MethodExecution calledMethodExec = methodInvStatement.getCalledMethodExecution(); + String methodSignature = calledMethodExec.getSignature(); + if (calledMethodExec.isCollectionType() + && (methodSignature.contains("add(") + || methodSignature.contains("set(") + || methodSignature.contains("put(") + || methodSignature.contains("push(") + || methodSignature.contains("addElement("))) { + // container to component + bottomSrcObjId = calledMethodExec.getThisObjId(); + bottomDstObjId = calledMethodExec.getArguments().get(0).getId(); + } else { + // this to another + bottomSrcObjId = methodInvStatement.getThisObjId(); + bottomDstObjId = calledMethodExec.getReturnValue().getId(); + } + } else { + return; + } } // Extract the reference access history. diff --git a/src/org/ntlab/deltaViewer/CollaborationViewer.java b/src/org/ntlab/deltaViewer/CollaborationViewer.java index 2483043..c47b7e7 100644 --- a/src/org/ntlab/deltaViewer/CollaborationViewer.java +++ b/src/org/ntlab/deltaViewer/CollaborationViewer.java @@ -534,7 +534,7 @@ // Judge AliasList contains relatedPoint. (If contains not to create edge.) if (rpIndex < relatedPoints.size() - 1) { TracePoint rp = relatedPoints.get(rpIndex); - Map.Entry rpInf = getRelatedInformation(rp); + Map.Entry rpInf = getRelatedInformation(rp, ac); if (srcClassName.equals(rpInf.getKey().getSrcClassName()) && fieldName.equals(rpInf.getValue()) && curAliasObjId.equals(rpInf.getKey().getSrcObjectId()) && nextAliasObjId.equals(rpInf.getKey().getDstObjectId())) { rpIndex++; continue; diff --git a/src/org/ntlab/deltaViewer/MagnetRONFrame.java b/src/org/ntlab/deltaViewer/MagnetRONFrame.java index 25b5126..fa86c7f 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONFrame.java +++ b/src/org/ntlab/deltaViewer/MagnetRONFrame.java @@ -565,7 +565,7 @@ if (objectCallGraph != null && aliasCollector != null) { List relatedPoints = objectCallGraph.getRelatedPoints(); TracePoint lastRP = relatedPoints.get(relatedPoints.size() - 1); - Map.Entry rpInf = MagnetRONViewer.getRelatedInformation(lastRP); + Map.Entry rpInf = MagnetRONViewer.getRelatedInformation(lastRP, aliasCollector); if (WINDOW_TITLE.contains("extract delta of")) { String[] splits = WINDOW_TITLE.split("extract delta of"); String featureName = splits[0]; @@ -631,7 +631,7 @@ if (ocg != null) { List relatedPoints = ocg.getRelatedPoints(); TracePoint lastRP = relatedPoints.get(relatedPoints.size() - 1); - Map.Entry rpInf = MagnetRONViewer.getRelatedInformation(lastRP); + Map.Entry rpInf = MagnetRONViewer.getRelatedInformation(lastRP, ac); WINDOW_TITLE = "extract delta of:" + rpInf.getKey().getSrcClassName() + "(" + rpInf.getKey().getSrcObjectId() + ")" + " -> " + rpInf.getKey().getDstClassName()+ "(" + rpInf.getKey().getDstObjectId()+ ")"; setTitle(WINDOW_TITLE); } diff --git a/src/org/ntlab/deltaViewer/MagnetRONViewer.java b/src/org/ntlab/deltaViewer/MagnetRONViewer.java index 743b3e9..0480dd2 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONViewer.java +++ b/src/org/ntlab/deltaViewer/MagnetRONViewer.java @@ -33,6 +33,7 @@ import org.ntlab.trace.FieldUpdate; import org.ntlab.trace.MethodExecution; import org.ntlab.trace.MethodInvocation; +import org.ntlab.trace.ObjectReference; import org.ntlab.trace.Reference; import org.ntlab.trace.Statement; import org.ntlab.trace.TracePoint; @@ -1549,7 +1550,7 @@ // TODO Auto-generated method stub } - public static Map.Entry getRelatedInformation(TracePoint relatedPoint) { + public static Map.Entry getRelatedInformation(TracePoint relatedPoint, IAliasCollector ac) { Statement rpStatement = relatedPoint.getStatement(); String rpSrcObjId = null; String rpDstObjId = null; @@ -1558,53 +1559,71 @@ String rpFieldName = null; // Search for relatedPoint objectReference srcClassName, fieldName. - if(rpStatement instanceof FieldUpdate) { - // Format fieldName. - FieldUpdate rpFieldUpdateStatement = (FieldUpdate) rpStatement; - rpSrcObjId = rpFieldUpdateStatement.getContainerObjId(); - rpDstObjId = rpFieldUpdateStatement.getValueObjId(); - if (rpFieldUpdateStatement.getFieldName() != null) { - String rpFieldNames[] = formatFieldName(rpFieldUpdateStatement.getFieldName()); - rpSrcClassName = rpFieldNames[0]; - rpFieldName = rpFieldNames[rpFieldNames.length-1]; - } else { - rpSrcClassName = rpFieldUpdateStatement.getContainerClassName(); + if (relatedPoint.isMethodEntry()) { + // this to another (parameter) + Alias lastAlias = ac.getAliasList().get(ac.getAliasList().size() - 1); + if (lastAlias.getAliasType() == Alias.AliasType.FORMAL_PARAMETER) { + rpSrcObjId = relatedPoint.getMethodExecution().getThisObjId(); + rpDstObjId = lastAlias.getObjectId(); rpFieldName = ""; - } - rpDstClassName = rpFieldUpdateStatement.getValueClassName(); - } else if (rpStatement instanceof ArrayUpdate) { - // container to component - ArrayUpdate rpArrayUpdateStatement = (ArrayUpdate) rpStatement; - rpSrcObjId = rpArrayUpdateStatement.getArrayObjectId(); - rpDstObjId = rpArrayUpdateStatement.getValueObjectId(); - rpSrcClassName = rpArrayUpdateStatement.getArrayClassName(); - rpDstClassName = rpArrayUpdateStatement.getValueClassName(); - rpFieldName = "[" + rpArrayUpdateStatement.getIndex() + "]"; - } else if(rpStatement instanceof MethodInvocation) { - MethodInvocation rpMethodInvStatement = (MethodInvocation) rpStatement; - MethodExecution rpCalledMethodExec = rpMethodInvStatement.getCalledMethodExecution(); - String rpMethodSig = rpCalledMethodExec.getSignature(); - - //Array��List�̂Ƃ��������x����t����i�m���ɕ������Ă�����̂Ƃ�)getSignature->contains("List.get(") || "Map.get(") <�z���C�g���X�g> -// if (rpMethodExec.getSignature().contains("List.add(") || -// rpMethodExec.getSignature().contains("Map.put(")) { - if (rpCalledMethodExec.isCollectionType() - && (rpMethodSig.contains("add(") - || rpMethodSig.contains("set(") - || rpMethodSig.contains("put(") - || rpMethodSig.contains("push(") - || rpMethodSig.contains("addElement("))) { - - rpSrcClassName = rpCalledMethodExec.getThisClassName(); - rpDstClassName = rpCalledMethodExec.getArguments().get(0).getActualType(); - rpSrcObjId = rpCalledMethodExec.getThisObjId(); - rpDstObjId = rpCalledMethodExec.getArguments().get(0).getId(); - } else { - // this to another - rpSrcClassName = rpMethodInvStatement.getThisClassName(); - rpDstClassName = rpCalledMethodExec.getReturnValue().getActualType(); - rpSrcObjId = rpMethodInvStatement.getThisObjId(); - rpDstObjId = rpCalledMethodExec.getReturnValue().getId(); + rpSrcClassName = relatedPoint.getMethodExecution().getThisClassName(); + for (ObjectReference r: lastAlias.getMethodExecution().getArguments()) { + if (r.getId().equals(rpDstObjId)) { + rpDstClassName = r.getActualType(); + break; + } + } + } + } + if (rpSrcObjId == null || rpDstObjId == null) { + if (rpStatement instanceof FieldUpdate) { + // Format fieldName. + FieldUpdate rpFieldUpdateStatement = (FieldUpdate) rpStatement; + rpSrcObjId = rpFieldUpdateStatement.getContainerObjId(); + rpDstObjId = rpFieldUpdateStatement.getValueObjId(); + if (rpFieldUpdateStatement.getFieldName() != null) { + String rpFieldNames[] = formatFieldName(rpFieldUpdateStatement.getFieldName()); + rpSrcClassName = rpFieldNames[0]; + rpFieldName = rpFieldNames[rpFieldNames.length-1]; + } else { + rpSrcClassName = rpFieldUpdateStatement.getContainerClassName(); + rpFieldName = ""; + } + rpDstClassName = rpFieldUpdateStatement.getValueClassName(); + } else if (rpStatement instanceof ArrayUpdate) { + // container to component + ArrayUpdate rpArrayUpdateStatement = (ArrayUpdate) rpStatement; + rpSrcObjId = rpArrayUpdateStatement.getArrayObjectId(); + rpDstObjId = rpArrayUpdateStatement.getValueObjectId(); + rpSrcClassName = rpArrayUpdateStatement.getArrayClassName(); + rpDstClassName = rpArrayUpdateStatement.getValueClassName(); + rpFieldName = "[" + rpArrayUpdateStatement.getIndex() + "]"; + } else if(rpStatement instanceof MethodInvocation) { + MethodInvocation rpMethodInvStatement = (MethodInvocation) rpStatement; + MethodExecution rpCalledMethodExec = rpMethodInvStatement.getCalledMethodExecution(); + String rpMethodSig = rpCalledMethodExec.getSignature(); + + //Array��List�̂Ƃ��������x����t����i�m���ɕ������Ă�����̂Ƃ�)getSignature->contains("List.get(") || "Map.get(") <�z���C�g���X�g> +// if (rpMethodExec.getSignature().contains("List.add(") || +// rpMethodExec.getSignature().contains("Map.put(")) { + if (rpCalledMethodExec.isCollectionType() + && (rpMethodSig.contains("add(") + || rpMethodSig.contains("set(") + || rpMethodSig.contains("put(") + || rpMethodSig.contains("push(") + || rpMethodSig.contains("addElement("))) { + + rpSrcClassName = rpCalledMethodExec.getThisClassName(); + rpDstClassName = rpCalledMethodExec.getArguments().get(0).getActualType(); + rpSrcObjId = rpCalledMethodExec.getThisObjId(); + rpDstObjId = rpCalledMethodExec.getArguments().get(0).getId(); + } else { + // this to another + rpSrcClassName = rpMethodInvStatement.getThisClassName(); + rpDstClassName = rpCalledMethodExec.getReturnValue().getActualType(); + rpSrcObjId = rpMethodInvStatement.getThisObjId(); + rpDstObjId = rpCalledMethodExec.getReturnValue().getId(); + } } } return new AbstractMap.SimpleEntry<>(new Reference(rpSrcObjId, rpDstObjId, rpSrcClassName, rpDstClassName), rpFieldName);