diff --git a/src/org/ntlab/deltaViewer/CollaborationViewer.java b/src/org/ntlab/deltaViewer/CollaborationViewer.java index 16e1d4f..6a56873 100644 --- a/src/org/ntlab/deltaViewer/CollaborationViewer.java +++ b/src/org/ntlab/deltaViewer/CollaborationViewer.java @@ -14,6 +14,7 @@ import org.jgrapht.graph.DirectedWeightedPseudograph; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.ExtractedStructure; +import org.ntlab.deltaExtractor.IAliasCollector; import com.mxgraph.canvas.mxGraphics2DCanvas; import com.mxgraph.model.mxCell; @@ -29,7 +30,7 @@ public class CollaborationViewer extends MagnetRONViewer { private IObjectCallGraph objectCallGraph; - private DeltaAliasCollector deltaAliasCollector; + private IAliasCollector aliasCollector; private static Dimension VERTEX_OBJECT_SIZE = new Dimension(70, 70); private static Dimension VERTEX_METHOD_EXECUTION_SIZE = new Dimension(55, 20); @@ -40,16 +41,16 @@ super(); } - public void init(IObjectCallGraph objectCallGraph, DeltaAliasCollector deltaAliasCollector) { + public void init(IObjectCallGraph objectCallGraph, IAliasCollector deltaAliasCollector) { this.objectCallGraph = objectCallGraph; - this.deltaAliasCollector = deltaAliasCollector; + this.aliasCollector = deltaAliasCollector; + // Build a frame, create a graph, and add the graph to the frame so you can actually see the graph. + createObjectVertices(objectCallGraph); + createEdgeToObject(aliasCollector.getAliasList()); } /** Initialize JFrame, make vertex object and edge object. */ public void initAnimation() { - // Build a frame, create a graph, and add the graph to the frame so you can actually see the graph. - createObjectVertices(objectCallGraph); - createEdgeToObject(deltaAliasCollector.getAliasList()); // Fit graph size in visible JFrame. mxGraphView view = mxgraphComponent.getGraph().getView(); @@ -88,7 +89,7 @@ */ public void stepToAnimation(Alias alias) { try { - stepToAnimation(deltaAliasCollector.getAliasList().indexOf(alias)); + stepToAnimation(aliasCollector.getAliasList().indexOf(alias)); } catch (IndexOutOfBoundsException e) { stepToAnimation(-1); } diff --git a/src/org/ntlab/deltaViewer/DeltaAliasCollector.java b/src/org/ntlab/deltaViewer/DeltaAliasCollector.java index 6abcb99..ebad72e 100644 --- a/src/org/ntlab/deltaViewer/DeltaAliasCollector.java +++ b/src/org/ntlab/deltaViewer/DeltaAliasCollector.java @@ -1,30 +1,77 @@ package org.ntlab.deltaViewer; +import java.util.ArrayList; import java.util.List; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.IAliasTracker; +import org.ntlab.trace.MethodExecution; +import org.ntlab.trace.MethodInvocation; +/** + * Collect delta alias for MagnetRON.(Derived from DeltaAliasTracker.) + * + * @author Nitta Lab. + */ public class DeltaAliasCollector implements IAliasTracker { + // Reverse execution order. + private List aliasList = new ArrayList<>(); + + public DeltaAliasCollector() { + } @Override public void addAlias(Alias alias) { - // TODO Auto-generated method stub - + switch(alias.getAliasType()) { + case FORMAL_PARAMETER: + aliasList.add(0, alias); + break; + case THIS: + aliasList.add(0, alias); + break; + case METHOD_INVOCATION: + aliasList.add(0, alias); + break; + case CONSTRACTOR_INVOCATION: + aliasList.add(0, alias); + break; + case FIELD: + aliasList.add(0, alias); + break; + case ARRAY_ELEMENT: + aliasList.add(0, alias); + break; + case ARRAY: + aliasList.add(0, alias); + break; + case ACTUAL_ARGUMENT: + aliasList.add(0, alias); + break; + case RECEIVER: + aliasList.add(0, alias); + if (alias.getOccurrencePoint().getStatement() instanceof MethodInvocation) { + MethodExecution me = ((MethodInvocation) alias.getOccurrencePoint().getStatement()).getCalledMethodExecution(); + } + break; + case RETURN_VALUE: + aliasList.add(0, alias); + break; + default: + break; + } + System.out.println(alias.getObjectId() + ", " + alias.getMethodSignature() + " l." + alias.getLineNo() + " : " + alias.getAliasType().toString()); } @Override public List getAliasList() { - // TODO Auto-generated method stub - return null; + return this.aliasList; } /* - * �R�R�ɂ͉��������Ȃ� + * Don't write anything here. */ @Override public void changeTrackingObject(String from, String to, boolean isSrcSide) { - // TODO Auto-generated method stub } diff --git a/src/org/ntlab/deltaViewer/DeltaViewer.java b/src/org/ntlab/deltaViewer/DeltaViewer.java index 0bc014f..c255a26 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewer.java +++ b/src/org/ntlab/deltaViewer/DeltaViewer.java @@ -23,7 +23,7 @@ import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.Delta; import org.ntlab.deltaExtractor.ExtractedStructure; -import org.ntlab.deltaExtractor.AliasPair; +import org.ntlab.deltaExtractor.IAliasCollector; import org.ntlab.deltaViewer.Edge.TypeName; import org.ntlab.deltaExtractor.Alias.AliasType; import org.ntlab.trace.ArrayAccess; @@ -64,7 +64,7 @@ //BUG: ObjectVertex position when Resize ObjectVertex. O public class DeltaViewer extends MagnetRONViewer { private ExtractedStructure eStructure; - private DeltaAliasTracker deltaAliasCollector; + private IAliasCollector deltaAliasCollector; private static Dimension VERTEX_OBJECT_SIZE = new Dimension(70, 70); private static Dimension VERTEX_METHOD_EXECUTION_SIZE = new Dimension(55, 20); @@ -76,17 +76,16 @@ super(); } - public void init(ExtractedStructure extractedStructure, DeltaAliasTracker deltaAliasCollector) { + public void init(ExtractedStructure extractedStructure, IAliasCollector deltaAliasCollector) { this.eStructure = extractedStructure; this.deltaAliasCollector = deltaAliasCollector; + // Build a frame, create a graph, and add the graph to the frame so you can actually see the graph. + createObjectVertices(eStructure); + createEdgeToObject(deltaAliasCollector.getAliasList()); } /** Initialize JFrame, make vertex object and edge object. */ public void initAnimation() { - // Build a frame, create a graph, and add the graph to the frame so you can actually see the graph. - createObjectVertices(eStructure); - createEdgeToObject(deltaAliasCollector.getAliasList(), deltaAliasCollector.getAliasPairList()); - // Fit graph size in visible JFrame. mxGraphView view = mxgraphComponent.getGraph().getView(); int componentWidth = mxgraphComponent.getWidth() - 25; @@ -646,7 +645,7 @@ * @param alias */ private void createObjectVertexOnConstractor(Alias alias) { - ObjectVertex vertexObj = objectToVertexMap.get(alias.getObjectId()); + ObjectVertex objectVertex = objectToVertexMap.get(alias.getObjectId()); String sourceObjId = alias.getMethodExecution().getThisObjId(); mxICell sourceCell = (mxICell)objectToVertexMap.get(sourceObjId).getCell(); double sourceWidth = sourceCell.getGeometry().getWidth(); @@ -659,26 +658,16 @@ methodInvocation = (MethodInvocation)alias.getOccurrencePoint().getStatement(); fieldName = methodInvocation.getCallerSideMethodName(); } - List aliasPairListByAlias = deltaAliasCollector.getAliasPairListByAlias(alias); - AliasPair aliasPair = null; - if (aliasPairListByAlias.size() >= 1) { - aliasPair = aliasPairListByAlias.get(0); - } - boolean isSrcSideChanged = aliasPair.getIsSrcSideChanged(); - Point absolutePointSourceCell = getAbsolutePointforCell(sourceCell); + Point absPtSrcCell = getAbsolutePointforCell(sourceCell); mxgraph.getModel().beginUpdate(); try { - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, vertexObj.getLabel(), vertexObj.getLabel(), absolutePointSourceCell.getX() + overlapWidth, absolutePointSourceCell.getY() + overlapHeight, VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. - vertexObj.setCell(vertex); + Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, objectVertex.getLabel(), objectVertex.getLabel(), absPtSrcCell.getX() + overlapWidth, absPtSrcCell.getY() + overlapHeight, VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + objectVertex.setCell(vertex); Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, null, sourceCell, vertex); - if(isSrcSideChanged) { - ((mxCell)edge).setStyle("exitX=1;exitY=1;exitPerimeter=1;entryX=0;entryY=0;entryPerimeter=1;"); - } else { - ((mxCell)edge).setStyle("exitX=0;exitY=1;exitPerimeter=1;entryX=1;entryY=0;entryPerimeter=1;"); - } + setEdgePoint((mxCell)edge, absPtSrcCell, objectVertex.getInitialPoint()); edgeMap.put(alias.getMethodExecution().getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); setCellsStyle(); - deltaAnimation.setVertexAnimation((mxICell)vertex, new mxPoint(vertexObj.getInitialX(), vertexObj.getInitialY())); + deltaAnimation.setVertexAnimation((mxICell)vertex, new mxPoint(objectVertex.getInitialX(), objectVertex.getInitialY())); deltaAnimation.startVertexAnimation(); } finally { mxgraph.getModel().endUpdate(); @@ -701,26 +690,16 @@ Point absPtSrcCell = getAbsolutePointforCell(srcCell); MethodInvocation methodInv; String fieldName = null; - List aliasPairListByAlias = deltaAliasCollector.getAliasPairListByAlias(alias); - AliasPair aliasPair = null; if (!methodExec.isCollectionType() && alias.getOccurrencePoint().getStatement() != null) { methodInv = (MethodInvocation)alias.getOccurrencePoint().getStatement(); fieldName = methodInv.getCallerSideMethodName(); } - if (aliasPairListByAlias.size() >= 1) { - aliasPair = aliasPairListByAlias.get(0); - } - boolean isSrcSideChanged = aliasPair.getIsSrcSideChanged(); mxgraph.getModel().beginUpdate(); try { Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, objectVertex.getLabel(), objectVertex.getLabel(), absPtSrcCell.getX() + overlapWidth, absPtSrcCell.getY() + overlapHeight, VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. objectVertex.setCell(vertex); Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, null, srcCell, vertex); - if(isSrcSideChanged) { - ((mxCell)edge).setStyle("exitX=1;exitY=1;exitPerimeter=1;entryX=0;entryY=0;entryPerimeter=1;"); - } else { - ((mxCell)edge).setStyle("exitX=0;exitY=1;exitPerimeter=1;entryX=1;entryY=0;entryPerimeter=1;"); - } + setEdgePoint((mxCell)edge, absPtSrcCell, objectVertex.getInitialPoint()); edgeMap.put(methodExec.getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); setCellsStyle(); deltaAnimation.setVertexAnimation((mxICell)vertex, new mxPoint(objectVertex.getInitialX(), objectVertex.getInitialY())); @@ -1508,10 +1487,22 @@ // } // } + private void setEdgePoint(mxICell edge, Point absPtSrcCell, Point absPtTgtCell) { + if(absPtSrcCell.getX() < absPtTgtCell.getX()) { + // if(isSrcSideChanged) { + // �E�����獶��փG�b�W������ + edge.setStyle("exitX=1;exitY=1;exitPerimeter=1;entryX=0;entryY=0;entryPerimeter=1;"); + } else { + // ��������E��փG�b�W������ + edge.setStyle("exitX=0;exitY=1;exitPerimeter=1;entryX=1;entryY=0;entryPerimeter=1;"); + } + } + /** Make edge object in JGraphT and draw this in JGraphX. * @param map - * @param collection */ - private void createEdgeToObject(List aliasList, List aliasPairList) { + * @param collection + */ + private void createEdgeToObject(List aliasList) { for (int i = 0; i < aliasList.size()-1; i++) { Alias curAlias = aliasList.get(i); Alias nextAlias = aliasList.get(i+1); @@ -1526,11 +1517,11 @@ nextMethodExec.getSignature().contains("Map.get(")) { srcClassName = nextMethodExec.getThisClassName(); fieldName = nextMethodExec.getArguments().get(0).getId(); - System.out.println("rTHIS " + srcClassName + ", " +nextMethodExec.getArguments().get(0).getId()); + System.out.println("rTHIS " + srcClassName + ", " + nextMethodExec.getArguments().get(0).getId()); } } else { Statement statement = nextAlias.getOccurrencePoint().getStatement(); - if(statement instanceof FieldAccess) { + if(statement instanceof FieldAccess && curAlias.getObjectId().equals(((FieldAccess)statement).getContainerObjId())) { String fieldNames[] = formatFieldName(((FieldAccess)statement).getFieldName()); srcClassName = fieldNames[0]; fieldName = fieldNames[1]; @@ -1551,27 +1542,15 @@ // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); try { - List aliasPairListByAlias = deltaAliasCollector.getAliasPairListByAliasPair(curAlias, nextAlias); - AliasPair aliasPair = null; - if (aliasPairListByAlias.size() >= 1) { - aliasPair = aliasPairListByAlias.get(0); - } - String srcObjId = aliasPair.getAliasPair().getKey().getObjectId(); - String dstObjId = aliasPair.getAliasPair().getValue().getObjectId(); - boolean isSrcSideChanged = aliasPair.getIsSrcSideChanged(); - // String dstClassName = curAlias.getMethodExecution().getThisClassName(); - System.out.println(aliasPair.getAliasPair().getKey().getMethodExecution().isConstructor()); - Object srcCell = objectToVertexMap.get(srcObjId).getCell(); - Object dstCell = objectToVertexMap.get(dstObjId).getCell(); + Object srcCell = objectToVertexMap.get(curAlias.getObjectId()).getCell(); + Object dstCell = objectToVertexMap.get(nextAlias.getObjectId()).getCell(); if (srcCell != null && dstCell != null) { // isCreation() System.out.println("makeEdgeObject: " + fieldName + ", " + srcClassName + " (" + srcCell.hashCode() + "), " + " (" + dstCell.hashCode() + ")"/* + ", " + dstClassName*/); // BUG:NullPointerException Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, fieldName, srcCell, dstCell); - if(isSrcSideChanged) { - ((mxCell)edge).setStyle("exitX=1;exitY=1;exitPerimeter=1;entryX=0;entryY=0;entryPerimeter=1;"); - } else { - ((mxCell)edge).setStyle("exitX=0;exitY=1;exitPerimeter=1;entryX=1;entryY=0;entryPerimeter=1;"); - } + Point absPtSrcCell = getAbsolutePointforCell((mxICell)srcCell); + Point absPtDstCell = getAbsolutePointforCell((mxICell)dstCell); + setEdgePoint((mxICell)edge, absPtSrcCell, absPtDstCell); edgeMap.put(srcClassName + "." + fieldName, new Edge(fieldName, TypeName.Reference, edge)); } } finally { diff --git a/src/org/ntlab/deltaViewer/MagnetRONFrame.java b/src/org/ntlab/deltaViewer/MagnetRONFrame.java index 8f76e41..74e4b73 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONFrame.java +++ b/src/org/ntlab/deltaViewer/MagnetRONFrame.java @@ -14,6 +14,8 @@ import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.DeltaExtractorJSON; import org.ntlab.deltaExtractor.ExtractedStructure; +import org.ntlab.deltaExtractor.IAliasCollector; +import org.ntlab.deltaExtractor.IAliasTracker; import org.ntlab.trace.MethodExecution; import org.ntlab.trace.ObjectReference; import org.ntlab.trace.Reference; @@ -21,15 +23,13 @@ import org.ntlab.trace.TraceJSON; import org.ntlab.trace.TracePoint; -import javafx.beans.property.SimpleMapProperty; - public class MagnetRONFrame extends JFrame { // Delta Extract Type protected static final String CONTAINER_COMPONENT = "Container-Component"; protected static final String CONTAINER_COMPONENT_COLLECTION = "Container-Component(Collection)"; protected static final String THIS_ANOTHER = "This-Another"; - private DeltaViewer deltaViewer = null; + private DeltaViewer viewer = null; private static Dimension DEFAULT_SIZE = new Dimension(1300, 700); private static String WINDOW_TITLE = "Delta Viewer"; @@ -39,13 +39,13 @@ setSize(DEFAULT_SIZE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); - this.deltaViewer = new DeltaViewer(); - getContentPane().add(deltaViewer, BorderLayout.CENTER); + this.viewer = new DeltaViewer(); + getContentPane().add(viewer, BorderLayout.CENTER); pack(); } public void startAnimation() { - Map.Entry extracted = extract(); + Map.Entry extracted = extract(); new Thread() { public void run() { startDeltaViewer(extracted.getKey(), extracted.getValue()); @@ -53,7 +53,7 @@ }.start(); } - public Map.Entry extract() { + public Map.Entry extract() { // DeltaExtractorJSON dex = new DeltaExtractorJSON(trace); // HashMap threads = trace.getAllThreads(); // ThreadInstance thread = threads.values().iterator().next(); // �Ō�̃X���b�h�����Ă��邾���c @@ -62,7 +62,7 @@ // System.out.println("===== All Statements Backward ====="); // TracePoint tp = null; // ExtractedStructure e = null; -// DeltaAliasCollector dac = new DeltaAliasCollector(); +// IAliasTracker dac = new DeltaAliasCollector(); // long restart = 0L; // for(;;) { // tp = trace.traverseStatementsInTraceBackward(new IStatementVisitor() { @@ -158,12 +158,12 @@ HashMap threads = trace.getAllThreads(); List eList = new ArrayList<>(); - List dacList = new ArrayList<>(); + List dacList = new ArrayList<>(); if (threads.values().size() == 1) { ThreadInstance thread = threads.values().iterator().next(); // �Ō�̃X���b�h�����Ă��邾���c TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); Reference reference = new Reference(argsMap.get(argsKey)[0], argsMap.get(argsKey)[1], argsMap.get(argsKey)[2], argsMap.get(argsKey)[3]); - DeltaAliasTracker dac = new DeltaAliasTracker(); + IAliasTracker dac = new DeltaAliasCollector(); ExtractedStructure e = s.extract(reference, tp, dac); eList.add(e); dacList.add(dac); @@ -177,7 +177,7 @@ // reference.setArray(true); // reference.setFinalLocal(true); // reference.setCreation(true); - DeltaAliasTracker dac = new DeltaAliasTracker(); + IAliasTracker dac = new DeltaAliasCollector(); ExtractedStructure e = s.extract(reference, tp, dac); System.out.println(e); if (e != null) { @@ -191,7 +191,7 @@ return new AbstractMap.SimpleEntry(eList.get(0), dacList.get(0)); // startDeltaViewer(eList.get(0), dacList.get(0)); } else { - DeltaAliasTracker dac = new DeltaAliasTracker(); + IAliasTracker dac = new DeltaAliasCollector(); MethodExecution me = trace.getLastMethodExecution(argsMap.get(argsKey)[2]); Map refs = me.getObjectReferences(argsMap.get(argsKey)[3]); ObjectReference ref = refs.keySet().iterator().next(); @@ -202,7 +202,7 @@ } } - public void startDeltaViewer(ExtractedStructure e, DeltaAliasTracker dac) { + public void startDeltaViewer(ExtractedStructure e, IAliasCollector dac) { // Build a frame, create a graph, and add the graph to the frame so you can actually see the graph. if(e != null) { List srcSide = e.getDelta().getSrcSide(); @@ -212,16 +212,16 @@ setTitle(WINDOW_TITLE); } } - deltaViewer.init(e, dac); + viewer.init(e, dac); List aliasList = new ArrayList<>(dac.getAliasList()); // dv.setCoordinatorPoint(1200, 100); - deltaViewer.initAnimation(); + viewer.initAnimation(); // for(int i = 0; i < aliasList.size(); i++) { // System.out.println(aliasList.get(i).getObjectId() + ", " + aliasList.get(i).getMethodSignature() + " l." + aliasList.get(i).getLineNo() + " : " + aliasList.get(i).getAliasType().toString()); // } for (int i = 0; i <= aliasList.size(); i++) { - deltaViewer.stepToAnimation(i); + viewer.stepToAnimation(i); } }