diff --git a/src/org/ntlab/deltaExtractor/ObjectIdPair.java b/src/org/ntlab/deltaExtractor/ObjectIdPair.java new file mode 100644 index 0000000..b9bc5ae --- /dev/null +++ b/src/org/ntlab/deltaExtractor/ObjectIdPair.java @@ -0,0 +1,21 @@ +package org.ntlab.deltaExtractor; + +import java.util.AbstractMap.SimpleEntry; + +public class ObjectIdPair { + private SimpleEntry objIdPair; + private boolean isSrcSideChanged; + + public ObjectIdPair(String fromObjId, String toObjId, boolean isSrcSideChanged) { + this.objIdPair = new SimpleEntry<>(fromObjId, toObjId); + this.isSrcSideChanged = isSrcSideChanged; + } + + public SimpleEntry getObjIdPair() { + return this.objIdPair; + } + + public boolean getIsSrcSideChanged() { + return this.isSrcSideChanged; + } +} \ No newline at end of file diff --git a/src/org/ntlab/deltaExtractor/Test.java b/src/org/ntlab/deltaExtractor/Test.java index b15354d..939c9ca 100644 --- a/src/org/ntlab/deltaExtractor/Test.java +++ b/src/org/ntlab/deltaExtractor/Test.java @@ -31,8 +31,8 @@ System.out.println(alias.getAliasType().toString() + ":" + alias.getObjectId() +"," + alias.getIndex() + "," + alias.getMethodSignature() + "," + alias.getLineNo()); } @Override - public void changeTrackingObject(String from, String to) { - System.out.println("Change:" + from + "�@=>�@" + to); + public void changeTrackingObject(String from, String to, boolean isSrcSide) { + System.out.println("Change:" + from + "�@=>�@" + to); } }); diff --git a/src/org/ntlab/deltaViewer/DeltaAliasCollector.java b/src/org/ntlab/deltaViewer/DeltaAliasCollector.java index a7f6083..9f4f44f 100644 --- a/src/org/ntlab/deltaViewer/DeltaAliasCollector.java +++ b/src/org/ntlab/deltaViewer/DeltaAliasCollector.java @@ -2,9 +2,13 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.IAliasCollector; +import org.ntlab.deltaExtractor.ObjectIdPair; import org.ntlab.trace.MethodExecution; import org.ntlab.trace.MethodInvocation; @@ -14,14 +18,17 @@ * @author Nitta Lab. */ public class DeltaAliasCollector implements IAliasCollector { - + // Reverse execution order. private String srcObjId; private String dstObjId; - private ArrayList aliasList = new ArrayList<>(); - + private List aliasList = new ArrayList<>(); + private Map aliasToObjIdPairMap = new HashMap<>(); + + private Alias curAlias; + public DeltaAliasCollector() { } - + /** * @param srcObjId * @param dstObjId @@ -30,54 +37,65 @@ this.srcObjId = srcObjId; this.dstObjId = dstObjId; } - + @Override public void addAlias(Alias alias) { switch(alias.getAliasType()) { - case FORMAL_PARAMETER: - aliasList.add(0, alias); - alias.getOccurrencePoint().getMethodExecution().getThisObjId(); - 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: - 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; + 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; } + curAlias = alias; System.out.println(alias.getObjectId() + ", " + alias.getMethodSignature() + " l." + alias.getLineNo() + " : " + alias.getAliasType().toString()); } @Override - public void changeTrackingObject(String fromObjId, String toObjId, boolean isSrcSide) { - System.out.println(fromObjId + " -> " + toObjId); + public void changeTrackingObject(String fromObjId, String toObjId, boolean isSrcSideChanged) { + aliasToObjIdPairMap.put(curAlias, new ObjectIdPair(toObjId, fromObjId, isSrcSideChanged)); + System.out.println(fromObjId + " -> " + toObjId + " " + isSrcSideChanged); } - - public Collection getAliasList() { + + public List getAliasList() { return this.aliasList; } + public Map getAliasToObjectPair() { + return aliasToObjIdPairMap; + } + + public ObjectIdPair getObjectPairByAlias(Alias alias) { + return aliasToObjIdPairMap.get(alias); + } } diff --git a/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java b/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java index dab520b..f19a666 100644 --- a/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java +++ b/src/org/ntlab/deltaViewer/DeltaGraphAdapter.java @@ -5,6 +5,7 @@ import org.jgrapht.graph.DefaultEdge; import org.jgrapht.graph.DirectedWeightedPseudograph; +import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; import com.mxgraph.model.mxICell; import com.mxgraph.util.mxConstants; @@ -15,94 +16,94 @@ * @author Nitta Lab. */ public class DeltaGraphAdapter extends JGraphXAdapter { - protected Graph graphT; + protected Graph graphT; public DeltaGraphAdapter(DirectedWeightedPseudograph graphT) { super(graphT); this.graphT = graphT; } - - /** - * Draw new vertex into the graph. - * - * @param vertex Vertex to be added to the graph. - */ - private mxICell addJGraphTVertex(Object vertex) { - getModel().beginUpdate(); - try { - // create a new JGraphX vertex at position 0 - mxICell cell = (mxICell) super.insertVertex(defaultParent, null, vertex, 0, 0, 0, 0); + /** + * Draw new vertex into the graph. + * + * @param vertex Vertex to be added to the graph. + */ + private mxICell addJGraphTVertex(Object vertex) { + getModel().beginUpdate(); - // update cell size so cell isn't "above" graph - updateCellSize(cell); + try { + // create a new JGraphX vertex at position 0 + mxICell cell = (mxICell) super.insertVertex(defaultParent, null, vertex, 0, 0, 0, 0); - // Save reference between vertex and cell. - getVertexToCellMap().put(vertex, cell); - getCellToVertexMap().put(cell, vertex); - return cell; - } finally { - getModel().endUpdate(); - } - } + // update cell size so cell isn't "above" graph + updateCellSize(cell); - /** - * Draw new egde into the graph. - * - * @param edge Edge to be added to the graph. Source and target vertices are needed. - */ - private mxICell addJGraphTEdge(Object sourceVertex, Object targetVertex, Object edge) { - getModel().beginUpdate(); + // Save reference between vertex and cell. + getVertexToCellMap().put(vertex, cell); + getCellToVertexMap().put(cell, vertex); + return cell; + } finally { + getModel().endUpdate(); + } + } - try { - // if the one of the vertices is not drawn, don't draw the edge - if (!(getVertexToCellMap().containsKey(sourceVertex) && getVertexToCellMap().containsKey(targetVertex))) { - return null; - } + /** + * Draw new egde into the graph. + * + * @param edge Edge to be added to the graph. Source and target vertices are needed. + */ + private mxICell addJGraphTEdge(Object sourceVertex, Object targetVertex, Object edge) { + getModel().beginUpdate(); - // get mxICells - Object sourceCell = getVertexToCellMap().get(sourceVertex); - Object targetCell = getVertexToCellMap().get(targetVertex); + try { + // if the one of the vertices is not drawn, don't draw the edge + if (!(getVertexToCellMap().containsKey(sourceVertex) && getVertexToCellMap().containsKey(targetVertex))) { + return null; + } - // add edge between mxICells - mxICell cell = (mxICell) super.insertEdge(defaultParent, null, edge, sourceCell, targetCell); + // get mxICells + Object sourceCell = getVertexToCellMap().get(sourceVertex); + Object targetCell = getVertexToCellMap().get(targetVertex); - // update cell size so cell isn't "above" graph - updateCellSize(cell); + // add edge between mxICells + mxICell cell = (mxICell) super.insertEdge(defaultParent, null, edge, sourceCell, targetCell); - // Save reference between vertex and cell. - getEdgeToCellMap().put(edge, cell); - getCellToEdgeMap().put(cell, edge); - return cell; - } finally { - getModel().endUpdate(); - } - } + // update cell size so cell isn't "above" graph + updateCellSize(cell); - /** - * - * @param parent - * @param id Edge id - * @param value Value to display - * @param source - * @param target - * @return - */ + // Save reference between vertex and cell. + getEdgeToCellMap().put(edge, cell); + getCellToEdgeMap().put(cell, edge); + return cell; + } finally { + getModel().endUpdate(); + } + } + + /** + * + * @param parent + * @param id Edge id + * @param value Value to display + * @param source + * @param target + * @return + */ public Object insertDeltaEdge(Object parent, String id, Object value, Object source, Object target) { - // find vertices of edge - Object sourceVertex = getCellToVertexMap().get(source); - Object targetVertex = getCellToVertexMap().get(target); + // find vertices of edge + Object sourceVertex = getCellToVertexMap().get(source); + Object targetVertex = getCellToVertexMap().get(target); - if (value == null) { - graphT.addEdge(sourceVertex, targetVertex); - } else { - graphT.addEdge(sourceVertex, targetVertex, value); - } + if (value == null) { + graphT.addEdge(sourceVertex, targetVertex); + } else { + graphT.addEdge(sourceVertex, targetVertex, value); + } mxICell cellEdge = addJGraphTEdge(sourceVertex, targetVertex, value); cellEdge.setId(id); return cellEdge; } - + /** * @param parent * @param id Vertex id @@ -128,10 +129,11 @@ public Object insertDeltaVertex(Object parent, String id, Object value, double x, double y, double width, double height, String style) { graphT.addVertex(value); mxICell cell = addJGraphTVertex(value); - + cell.setId(id); + ((mxCell) parent).insert(cell); cell.setParent((mxICell) parent); - ((mxICell) parent).insert(cell); + getCellGeometry(cell).setX(x); getCellGeometry(cell).setY(y); getCellGeometry(cell).setWidth(width); @@ -145,7 +147,7 @@ } return cell; } - + public Graph getGraph() { return graphT; } diff --git a/src/org/ntlab/deltaViewer/DeltaViewer.java b/src/org/ntlab/deltaViewer/DeltaViewer.java index 46370e9..a9f1c3d 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewer.java +++ b/src/org/ntlab/deltaViewer/DeltaViewer.java @@ -21,6 +21,7 @@ import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.Delta; import org.ntlab.deltaExtractor.ExtractedStructure; +import org.ntlab.deltaExtractor.ObjectIdPair; import org.ntlab.deltaViewer.Edge.TypeName; import org.ntlab.deltaExtractor.Alias.AliasType; import org.ntlab.trace.ArrayAccess; @@ -48,51 +49,51 @@ //BUG: methodExecution Id. O //BUG: Move ObjectVertex position sometimes. O //BUG: Resize ObjectVertex sometimes. O -//BUG: finally field refrence. +//BUG: finally field reference. O //BUG: edge drawing order. -> parent +//BUG: methodExecution drawing order. -> parent +//BUG: ObjectVertex position when Resize ObjectVertex. public class DeltaViewer { - private static Dimension DEFAULT_SIZE = new Dimension(700, 700); - private static String WINDOW_TITLE = "Delta Viewer"; + private static Dimension DEFAULT_SIZE = new Dimension(700, 700); + private static String WINDOW_TITLE = "Delta Viewer"; - private ExtractedStructure eStructure; - private DeltaAliasCollector deltaAliasCollector; - private List aliasList; - - private Map objectToVertexMap = new HashMap<>(); - private Map methodExecToVertexMap = new LinkedHashMap<>(); + private ExtractedStructure eStructure; + private DeltaAliasCollector deltaAliasCollector; + + private Map objectToVertexMap = new HashMap<>(); + private Map methodExecToVertexMap = new LinkedHashMap<>(); private Map edgeMap = new HashMap<>(); - + private JFrame frame; private DeltaGraphAdapter mxgraph; // No clue what this does but it is needed. private mxICell mxDefaultParent; private mxGraphComponent mxgraphComponent; - - private int curNumFrame = 0; - private static Dimension VERTEX_OBJECT_SIZE = new Dimension(70, 70); - private static Dimension VERTEX_METHOD_EXECUTION_SIZE = new Dimension(55, 20); - private mxPoint coordinatorPoint = new mxPoint(DEFAULT_SIZE.getWidth() / 2 - 50, 100); - private DeltaAnimation deltaAnimation; - - private double scale = 1; - + private int curFrame = 0; + private static Dimension VERTEX_OBJECT_SIZE = new Dimension(70, 70); + private static Dimension VERTEX_METHOD_EXECUTION_SIZE = new Dimension(55, 20); + private mxPoint coordinatorPoint = new mxPoint(DEFAULT_SIZE.getWidth() / 2 - 50, 100); + + private DeltaAnimation deltaAnimation; + + private double scale = 1; + public DeltaViewer() { - mxgraph = new DeltaGraphAdapter(new DirectedWeightedPseudograph(DefaultEdge.class)); - mxDefaultParent = (mxCell)mxgraph.getDefaultParent(); - mxgraphComponent = new mxGraphComponent(mxgraph); - deltaAnimation = new DeltaAnimation(mxgraph, mxgraphComponent); + mxgraph = new DeltaGraphAdapter(new DirectedWeightedPseudograph(DefaultEdge.class)); + mxDefaultParent = (mxCell)mxgraph.getDefaultParent(); + mxgraphComponent = new mxGraphComponent(mxgraph); + deltaAnimation = new DeltaAnimation(mxgraph, mxgraphComponent); } public DeltaViewer(ExtractedStructure extractedStructure, DeltaAliasCollector deltaAliasCollector) { this(); this.eStructure = extractedStructure; this.deltaAliasCollector = deltaAliasCollector; - aliasList = new ArrayList<>(deltaAliasCollector.getAliasList()); -// init(); + // init(); } - + /** Initialize JFrame, make vertex object and edge object. */ public void init() { // Build a frame, create a graph, and add the graph to the frame so you can actually see the graph. @@ -100,54 +101,51 @@ WINDOW_TITLE = "extract delta of:" + eStructure.getDelta().getSrcSide().get(0).getDstClassName() + "(" + eStructure.getDelta().getSrcSide().get(0).getDstObjectId() + ")" + " -> " + eStructure.getDelta().getDstSide().get(0).getDstClassName() + "(" + eStructure.getDelta().getDstSide().get(0).getDstObjectId() + ")"; } - frame = new JFrame(WINDOW_TITLE); - frame.setSize(DEFAULT_SIZE); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame = new JFrame(WINDOW_TITLE); + frame.setSize(DEFAULT_SIZE); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.add(mxgraphComponent, BorderLayout.CENTER); - frame.setVisible(true); - - System.out.println(eStructure.getDelta().getDstSide()); + frame.add(mxgraphComponent, BorderLayout.CENTER); + frame.setVisible(true); - while(coordinatorPoint.getX() - (150 * (eStructure.getDelta().getDstSide().size())) < 0) { - coordinatorPoint.setX(coordinatorPoint.getX() + 150); - } - - makeVertexObjects(); - makeEdgeObject(); + createObjectVertices(eStructure); + createEdgeToObject(deltaAliasCollector.getAliasList(), deltaAliasCollector.getAliasToObjectPair()); // Fit graph size in visible JFrame. mxGraphView view = mxgraphComponent.getGraph().getView(); int componentWidth = mxgraphComponent.getWidth(); - int viewWidth = (int) view.getGraphBounds().getWidth(); + double viewWidth = (double) view.getGraphBounds().getWidth(); + System.out.print("Scale " + componentWidth + ", " + viewWidth + ", " + coordinatorPoint.getX()); + if (viewWidth < coordinatorPoint.getX()) { + viewWidth += coordinatorPoint.getX(); + } scale = (double)componentWidth/viewWidth; + System.out.println(", " + scale); view.setScale(scale); deltaAnimation.setScale(scale); - System.out.println(componentWidth + ", " + viewWidth + ", " + scale); + update(); } - - /** Display graph on JFrame. */ + + /** Update graph on JFrame and set Cell style. */ public void update() { - setCellStyles(); - mxgraphComponent.refresh(); + setStyleOfCells(); + mxgraphComponent.refresh(); try { - System.out.println("updateThread.sleep()"); Thread.sleep(1000); - System.out.println("updateThread.start()"); } catch (InterruptedException e) { e.printStackTrace(); } - } - + } + public void setExtractedStructure(ExtractedStructure extractedStructure) { this.eStructure = extractedStructure; } - + public void setDeltaAliasCollector(DeltaAliasCollector deltaAliasCollector) { this.deltaAliasCollector = deltaAliasCollector; } - + public void setFrameSize(int width, int height) { DEFAULT_SIZE.setSize(width, height); } @@ -156,110 +154,116 @@ coordinatorPoint.setX(x); coordinatorPoint.setY(y); } - - /** Set cell styles. */ - private void setCellStyles() { - List vertexObject = new ArrayList<>(); - List alignMiddleVertex = new ArrayList<>(); - List alignTopVertex = new ArrayList<>(); - List edgeObject = new ArrayList<>(); - List edgeMethodExec = new ArrayList<>(); - List roundEdge = new ArrayList<>(); - for (VertexObject vertex: objectToVertexMap.values()) { + /** Set style of All cells. */ + private void setStyleOfCells() { + List vertexObject = new ArrayList<>(); + List alignMiddleVertex = new ArrayList<>(); + List alignTopVertex = new ArrayList<>(); + List edgeObject = new ArrayList<>(); + List edgeObjectCreate = new ArrayList<>(); + List edgeMethodExec = new ArrayList<>(); + List roundEdge = new ArrayList<>(); + + for (ObjectVertex vertex: objectToVertexMap.values()) { vertexObject.add(vertex.getCell()); if(vertex.getVertexMethodExecutions().size() == 0) { alignMiddleVertex.add(vertex.getCell()); } else { alignTopVertex.add(vertex.getCell()); } - } - - List vertexMethodExecList = new ArrayList<>(methodExecToVertexMap.values()); - Collections.reverse(vertexMethodExecList); - for (int i = 0; i < vertexMethodExecList.size(); i++) { - switch(i) { + } + + List vertexMethodExecList = new ArrayList<>(methodExecToVertexMap.values()); + Collections.reverse(vertexMethodExecList); + for (int i = 0; i < vertexMethodExecList.size(); i++) { + switch(i) { case 0: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff7fbf"); + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff7fbf"); break; case 1: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff99cc"); + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff99cc"); break; case 2: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffb2d8"); + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffb2d8"); break; case 3: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffcce5"); + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffcce5"); break; case 4: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffe0ef"); + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffe0ef"); break; default: break; - } - } - - for (Edge edge: edgeMap.values()) { - roundEdge.add(edge.getCell()); - switch(edge.getTypeName()) { - case Reference: - edgeObject.add(edge.getCell()); - break; - case Call: - edgeMethodExec.add(edge.getCell()); - break; - default: - break; - } - } - /*Given a cell, we can change it's style attributes, for example the color. NOTE that you have to call the graphComponent.refresh() function, otherwise you won't see the difference! */ - mxgraph.setCellStyles(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_UNDERLINE, true, vertexObject.toArray(new Object[vertexObject.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE, alignMiddleVertex.toArray(new Object[alignMiddleVertex.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, alignTopVertex.toArray(new Object[alignTopVertex.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_TOPTOBOTTOM, edgeObject.toArray(new Object[edgeObject.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ENTITY_RELATION, edgeObject.toArray(new Object[edgeObject.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeObject.toArray(new Object[edgeObject.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_ROUNDED, 1, true, roundEdge.toArray(new Object[roundEdge.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, roundEdge.toArray(new Object[roundEdge.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_BOTTOM, roundEdge.toArray(new Object[roundEdge.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.SHAPE_CURVE, edgeObject.toArray(new Object[edgeObject.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_STROKECOLOR, "#008000", edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); -// mxgraph.setCellStyleFlags(mxConstants.STYLE_AUTOSIZE, 1, true, vertexObject.toArray(new Object[vertexObject.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_ELBOW, mxConstants.ELBOW_VERTICAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); - } - - private double getXForCell(String id) { - double res = -1; - if (objectToVertexMap.containsKey(id)) { - Object cell = objectToVertexMap.get(id).getCell(); - res = mxgraph.getCellGeometry(cell).getX(); - } - return res; - } - - private double getYForCell(String id) { - double res = -1; - if (objectToVertexMap.containsKey(id)) { - Object cell = objectToVertexMap.get(id).getCell(); - res = mxgraph.getCellGeometry(cell).getY(); - } - return res; - } - - private mxICell getRootParentCell(Object object) { - mxICell cell = (mxICell) object; - if(cell.getParent().getValue() == null) { - return cell; + } } - return getRootParentCell(cell.getParent()); + + for (Edge edge: edgeMap.values()) { + roundEdge.add(edge.getCell()); + switch(edge.getTypeName()) { + case Reference: + edgeObject.add(edge.getCell()); + break; + case Create: + edgeObject.add(edge.getCell()); + edgeObjectCreate.add(edge.getCell()); + break; + case Call: + edgeMethodExec.add(edge.getCell()); + break; + default: + break; + } + } + + /*Given a cell, we can change it's style attributes, for example the color. NOTE that you have to call the graphComponent.refresh() function, otherwise you won't see the difference! */ + mxgraph.setCellStyles(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_UNDERLINE, true, vertexObject.toArray(new Object[vertexObject.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE, alignMiddleVertex.toArray(new Object[alignMiddleVertex.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, alignTopVertex.toArray(new Object[alignTopVertex.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_TOPTOBOTTOM, edgeObject.toArray(new Object[edgeObject.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, edgeObjectCreate.toArray(new Object[edgeObjectCreate.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ENTITY_RELATION, edgeObject.toArray(new Object[edgeObject.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeObject.toArray(new Object[edgeObject.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_ROUNDED, 1, true, roundEdge.toArray(new Object[roundEdge.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, roundEdge.toArray(new Object[roundEdge.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_BOTTOM, roundEdge.toArray(new Object[roundEdge.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.SHAPE_CURVE, edgeObject.toArray(new Object[edgeObject.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_STROKECOLOR, "#008000", edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); + // mxgraph.setCellStyleFlags(mxConstants.STYLE_AUTOSIZE, 1, true, vertexObject.toArray(new Object[vertexObject.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_ELBOW, mxConstants.ELBOW_VERTICAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); } - - private Point getAbsolutePointforCell(Object object) { - mxICell cell = (mxICell) object; + + // private double getXForCell(String id) { + // double res = -1; + // if (objectToVertexMap.containsKey(id)) { + // Object cell = objectToVertexMap.get(id).getCell(); + // res = mxgraph.getCellGeometry(cell).getX(); + // } + // return res; + // } + + // private double getYForCell(String id) { + // double res = -1; + // if (objectToVertexMap.containsKey(id)) { + // Object cell = objectToVertexMap.get(id).getCell(); + // res = mxgraph.getCellGeometry(cell).getY(); + // } + // return res; + // } + + // private mxICell getRootParentCell(Object object) { + // mxICell cell = (mxICell) object; + // if(cell.getParent().getValue() == null) { + // return cell; + // } + // return getRootParentCell(cell.getParent()); + // } + + private Point getAbsolutePointforCell(mxICell cell) { Point p1 = cell.getGeometry().getPoint(); if(cell.getParent().getValue() == null) { return p1; @@ -267,18 +271,18 @@ Point p2 = getAbsolutePointforCell(cell.getParent()); return new Point((int) (p1.getX() + p2.getX()), (int) (p1.getY() + p2.getY())); } - + /** * Step to animation of specified alias. * - * @param alias Alias type and occurance point etc. + * @param alias Alias type and occurrence point etc. */ public void stepToAnimation(Alias alias) { - try { - stepToAnimation(aliasList.indexOf(alias)); - } catch (IndexOutOfBoundsException e) { - stepToAnimation(-1); - } + try { + stepToAnimation(deltaAliasCollector.getAliasList().indexOf(alias)); + } catch (IndexOutOfBoundsException e) { + stepToAnimation(-1); + } } /** @@ -287,28 +291,25 @@ * @param numFrame Current animation frame. */ public void stepToAnimation(int numFrame) { - try { - Alias alias = aliasList.get(numFrame); - doAnimation(aliasList.get(curNumFrame), alias); - curNumFrame = aliasList.indexOf(alias) + 1; - } catch (IndexOutOfBoundsException e) { - if (numFrame == - 1) { - System.out.println("ERROR : Not exist alias."); - } else { - System.out.println("\r\nLast Animation."); - doLastAnimation(aliasList.get(aliasList.size() - 1)); - } - } + if (deltaAliasCollector.getAliasList().size() > numFrame) { + doAnimation(curFrame, numFrame); + } else if (deltaAliasCollector.getAliasList().size() == numFrame){ + System.out.println("\r\nLast Animation."); + doLastAnimation(numFrame); + } else { + System.out.println("ERROR : Not exist alias."); + } } - + /** - * Do animation from fromAlias to toAlias. + * Do animation from fromFrame to toFrame. * - * @param fromAlias - * @param toAlias + * @param fromFrame + * @param toFrame */ - private void doAnimation(Alias fromAlias, Alias toAlias) { - for (int i = aliasList.indexOf(fromAlias); i <= aliasList.indexOf(toAlias); i++) { + private void doAnimation(int fromFrame, int toFrame) { + for (int i = fromFrame; i <= toFrame; i++) { + List aliasList = new ArrayList<>(deltaAliasCollector.getAliasList()); Alias alias = aliasList.get(i); System.out.println("\r\n" + i + ": " + alias.getObjectId() + ", " + alias.getMethodSignature() + " l." + alias.getLineNo() + " : " + alias.getAliasType().toString()); switch(alias.getAliasType()) { @@ -317,14 +318,15 @@ update(); break; case METHOD_INVOCATION: - removeVertexMethodExecution(alias); + removeMethodExecutionVertex(alias); moveObjectVertex(alias); update(); break; case CONSTRACTOR_INVOCATION: - Object vertex = objectToVertexMap.get(alias.getObjectId()).getCell(); - ((mxICell)vertex).setStyle("fillColor=#ffffff;strokeColor=#194bff;"); - ((mxICell)vertex).setValue(((mxICell)vertex).getId()); + createObjectVertexOnConstractor(alias); + createMethodExecutionVertex(alias, ((MethodInvocation)alias.getOccurrencePoint().getStatement()).getCallerSideMethodName(), ((MethodInvocation)alias.getOccurrencePoint().getStatement()).getCalledMethodExecution()); + update(); + removeMethodExecutionVertex(alias); update(); break; case FORMAL_PARAMETER: @@ -336,8 +338,8 @@ update(); break; case THIS: - if (curNumFrame == 0) { - makeVertexMethodExecution(alias); + if (curFrame == 0) { + createMethodExecutionVertex(alias); update(); } break; @@ -345,147 +347,132 @@ // Make VertexMethodExecution of called method execution. MethodExecution calledMethodExec = ((MethodInvocation) alias.getOccurrencePoint().getStatement()).getCalledMethodExecution(); if (!methodExecToVertexMap.containsKey(calledMethodExec)) { - makeVertexMethodExecution(alias, calledMethodExec.getSignature(), calledMethodExec); + createMethodExecutionVertex(alias, calledMethodExec.getSignature(), calledMethodExec); update(); } break; default: break; } + curFrame = i + 1; + outputLog(); } } - + /** * Make last animation of extracted delta. * - * @param alias Last index alias. + * @param numFrame AliasList size. */ - private void doLastAnimation(Alias alias) { - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); - try { - // Make ObjectEdge and reset position of vertexObject, remove vertexMethodExecution. - for(Statement statement: alias.getMethodExecution().getStatements()) { - if(statement instanceof FieldUpdate) { - FieldUpdate fieldUpdateStatement = (FieldUpdate) statement; -// String fieldNames[] = fieldUpdateStatement.getFieldName().split("\\."); -// String fieldName = fieldNames[fieldNames.length-1]; - String fieldNames[] = formatFieldName(fieldUpdateStatement.getFieldName()); - String fieldName = fieldNames[fieldNames.length-1]; - String sourceObjectId = fieldUpdateStatement.getContainerObjId(); - String targetObjectId = fieldUpdateStatement.getValueObjId(); - mxICell sourceCell = (mxICell)objectToVertexMap.get(sourceObjectId).getCell(); - mxICell targetCell = (mxICell)objectToVertexMap.get(targetObjectId).getCell(); - Point absolutePointTargetCell = getAbsolutePointforCell(targetCell); - show(mxDefaultParent); - targetCell.getParent().remove(targetCell); - targetCell.setParent(mxDefaultParent); - targetCell.getGeometry().setX(absolutePointTargetCell.getX()); - targetCell.getGeometry().setY(absolutePointTargetCell.getY()); - Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldUpdateStatement.getFieldName(), fieldName, objectToVertexMap.get(sourceObjectId).getCell(), objectToVertexMap.get(targetObjectId).getCell()); - ((mxCell)edge).setStyle("exitX=0;exitY=0.5;exitPerimeter=1;entryX=1;entryY=0.5;entryPerimeter=1;"); - edgeMap.put(fieldUpdateStatement.getFieldName(), new Edge(fieldName, TypeName.Reference, edge)); -// System.out.println("last" + objectToVertexMap.get(targetObjectId).getInitialX() + ", " + objectToVertexMap.get(targetObjectId).getInitialY()); - deltaAnimation.setVertexAnimation(targetCell, new mxPoint(objectToVertexMap.get(targetObjectId).getInitialX(), objectToVertexMap.get(targetObjectId).getInitialY())); - deltaAnimation.startVertexAnimation(); - targetCell.getGeometry().setX(objectToVertexMap.get(targetObjectId).getInitialX()); - targetCell.getGeometry().setY(objectToVertexMap.get(targetObjectId).getInitialY()); - removeCalledVertexMethodExecution(objectToVertexMap.get(sourceObjectId), alias.getMethodExecution().getCallerMethodExecution(), alias.getMethodExecution()); - updateVertexObjectSize(); - } + private void doLastAnimation(int numFrame) { + curFrame = numFrame; + Alias alias = deltaAliasCollector.getAliasList().get(numFrame - 1); + // Make ObjectEdge and reset position of vertexObject, remove vertexMethodExecution. + for(Statement statement: alias.getMethodExecution().getStatements()) { + if(statement instanceof FieldUpdate) { + // Format fieldName. + FieldUpdate fieldUpdateStatement = (FieldUpdate) statement; + String fieldNames[] = formatFieldName(fieldUpdateStatement.getFieldName()); + String fieldName = fieldNames[fieldNames.length-1]; + String sourceObjectId = fieldUpdateStatement.getContainerObjId(); + + createObjectRefrence(fieldUpdateStatement, fieldName); + removeCalledMethodExecutionVertex(objectToVertexMap.get(sourceObjectId), alias.getMethodExecution().getCallerMethodExecution(), alias.getMethodExecution()); + updateObjectVerticesSize(); } - } finally { - mxgraph.getModel().endUpdate(); } // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); try { List methodExecList = new ArrayList<>(methodExecToVertexMap.keySet()); - System.out.println(methodExecToVertexMap.size()); - Collections.reverse(methodExecList); - for(int i = 0; i < methodExecList.size(); i++) { - String objectId = methodExecList.get(i).getThisObjId(); - VertexObject sourceVertexObject = objectToVertexMap.get(objectId); // sourceVertex - MethodExecution methodExec = methodExecList.get(i); - if (i != methodExecList.size()-1) { - for(Statement statement: methodExec.getStatements()) { - if(statement instanceof MethodInvocation) { - MethodExecution calledMethodExec = ((MethodInvocation) statement).getCalledMethodExecution(); - String calledObjectId = calledMethodExec.getThisObjId(); + Collections.reverse(methodExecList); + for(int i = 0; i < methodExecList.size(); i++) { + String objectId = methodExecList.get(i).getThisObjId(); + ObjectVertex sourceVertexObject = objectToVertexMap.get(objectId); // sourceVertex + MethodExecution methodExec = methodExecList.get(i); + if (i != methodExecList.size()-1) { + for(Statement statement: methodExec.getStatements()) { + if(statement instanceof MethodInvocation) { + MethodExecution calledMethodExec = ((MethodInvocation) statement).getCalledMethodExecution(); + String calledObjectId = calledMethodExec.getThisObjId(); mxICell calledCell = (mxICell)objectToVertexMap.get(calledObjectId).getCell(); Point absolutePointCalledCell = getAbsolutePointforCell(calledCell); System.out.println(objectId + ", " + methodExec.getSignature()); - // objectToVertexMap.get(calledObjectId).resetCellPosition(); + // objectToVertexMap.get(calledObjectId).resetCellPosition(); if (methodExecToVertexMap.get(methodExec).getArguments().contains(objectToVertexMap.get(calledObjectId)) || methodExecToVertexMap.get(methodExec).getLocals().contains(objectToVertexMap.get(calledObjectId))) { - calledCell.getParent().remove(calledCell); + calledCell.getParent().remove(calledCell); calledCell.setParent(mxDefaultParent); calledCell.getGeometry().setX(absolutePointCalledCell.getX()); calledCell.getGeometry().setY(absolutePointCalledCell.getY()); deltaAnimation.setVertexAnimation(calledCell, new mxPoint(objectToVertexMap.get(calledObjectId).getInitialX(), objectToVertexMap.get(calledObjectId).getInitialY())); deltaAnimation.startVertexAnimation(); } - removeCalledVertexMethodExecution(sourceVertexObject, methodExec.getCallerMethodExecution(), methodExec); - updateVertexObjectSize(); - // removeVertexMethodExecution(sourceVertexObject, methodExec); - // update(); - break; - } - } - } else { - List arguments = new ArrayList<>(methodExecToVertexMap.get(methodExec).getArguments()); - List locals = new ArrayList<>(methodExecToVertexMap.get(methodExec).getLocals()); - if (arguments.size() != 0) { - for (VertexObject vo: arguments) { - mxICell cell = (mxICell)vo.getCell(); - Point absolutePointCell = getAbsolutePointforCell(cell); - cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); - cell.getGeometry().setX(absolutePointCell.getX()); - cell.getGeometry().setY(absolutePointCell.getY()); + removeCalledMethodExecutionVertex(sourceVertexObject, methodExec.getCallerMethodExecution(), methodExec); + updateObjectVerticesSize(); + // removeVertexMethodExecution(sourceVertexObject, methodExec); + // update(); + break; + } + } + } else { + List arguments = new ArrayList<>(methodExecToVertexMap.get(methodExec).getArguments()); + List locals = new ArrayList<>(methodExecToVertexMap.get(methodExec).getLocals()); + if (arguments.size() != 0) { + for (ObjectVertex vo: arguments) { + mxICell cell = (mxICell)vo.getCell(); + Point absolutePointCell = getAbsolutePointforCell(cell); + cell.getParent().remove(cell); + cell.setParent(mxDefaultParent); + cell.getGeometry().setX(absolutePointCell.getX()); + cell.getGeometry().setY(absolutePointCell.getY()); deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); deltaAnimation.startVertexAnimation(); methodExecToVertexMap.get(methodExec).getArguments().remove(vo); - } - }else if (locals.size() != 0) { - for (VertexObject vo: locals) { - mxICell cell = (mxICell)vo.getCell(); - Point absolutePointCell = getAbsolutePointforCell(cell); - cell.getParent().remove(cell); - cell.setParent(mxDefaultParent); - cell.getGeometry().setX(absolutePointCell.getX()); - cell.getGeometry().setY(absolutePointCell.getY()); + } + }else if (locals.size() != 0) { + for (ObjectVertex vo: locals) { + mxICell cell = (mxICell)vo.getCell(); + Point absolutePointCell = getAbsolutePointforCell(cell); + cell.getParent().remove(cell); + cell.setParent(mxDefaultParent); + cell.getGeometry().setX(absolutePointCell.getX()); + cell.getGeometry().setY(absolutePointCell.getY()); deltaAnimation.setVertexAnimation(cell, new mxPoint(vo.getInitialX(), vo.getInitialY())); deltaAnimation.startVertexAnimation(); methodExecToVertexMap.get(methodExec).getLocals().remove(vo); - } - } - updateVertexObjectSize(); - } - } + } + } + updateObjectVerticesSize(); + } + } } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } update(); } - /** Make VertexObjects. */ - private void makeVertexObjects() { - //Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. + /** Create ObjectVertices. */ + private void createObjectVertices(ExtractedStructure eStructure) { + while(coordinatorPoint.getX() - (150 * (eStructure.getDelta().getDstSide().size())) < 0) { + coordinatorPoint.setX(coordinatorPoint.getX() + 150); + } + // ����(0, 0) - double xCor = coordinatorPoint.getX(); + double xCor = coordinatorPoint.getX(); double yCor = coordinatorPoint.getY(); double time = 150; + //Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); - try { + try { // Draw vertex object. - // srcSide + // srcSide Delta delta = eStructure.getDelta(); int srcSideSize = delta.getSrcSide().size(); for (int i = srcSideSize - 1; i >= 0; i--) { Reference ref = delta.getSrcSide().get(i); - System.out.println("srcSide: " + ref.getSrcClassName() + ", " + ref.isCreation()); + // System.out.println("srcSide: " + ref.getSrcClassName() + ", " + ref.isCreation()); if (!ref.isCreation() && !ref.getSrcObjectId().equals(ref.getDstObjectId())) { if(!objectToVertexMap.containsKey(ref.getSrcObjectId())) { String srcClassName = ref.getSrcClassName(); @@ -493,16 +480,16 @@ srcClassName = formatArrayName(srcClassName); } Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getSrcClassName(), srcClassName, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)), VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(ref.getSrcObjectId(), new VertexObject(ref.getSrcClassName(), vertex, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)))); + objectToVertexMap.put(ref.getSrcObjectId(), new ObjectVertex(ref.getSrcClassName(), vertex, xCor + (time * ((srcSideSize - 1) - i)), yCor + (time * ((srcSideSize - 1) - i)))); } if(!objectToVertexMap.containsKey(ref.getDstObjectId())) { -// System.out.println(ref.getDstClassName() + ", " + ref.isCreation()); + // System.out.println(ref.getDstClassName() + ", " + ref.isCreation()); String dstClassName = ref.getDstClassName(); if (dstClassName.contains("[L")) { dstClassName = formatArrayName(dstClassName); } Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getDstClassName(), dstClassName, xCor + (time * (srcSideSize - i)), yCor + (time * (srcSideSize - i)), VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(ref.getDstObjectId(), new VertexObject(ref.getDstClassName(), vertex, xCor + (time * (srcSideSize - i)), yCor + (time * (srcSideSize - i)))); + objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), vertex, xCor + (time * (srcSideSize - i)), yCor + (time * (srcSideSize - i)))); } } } @@ -511,26 +498,78 @@ int dstSideSize = delta.getDstSide().size(); for (int i = dstSideSize - 1; i >= 0; i--) { Reference ref = delta.getDstSide().get(i); -// System.out.println("dstSide: " + ref.getDstClassName() + ", " + ref.isCreation()); + // System.out.println("dstSide: " + ref.getDstClassName() + ", " + ref.isCreation()); if (!ref.isCreation() && !ref.getSrcObjectId().equals(ref.getDstObjectId())) { String dstClassName = ref.getDstClassName(); if (dstClassName.contains("[L")) { dstClassName = formatArrayName(dstClassName); } Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getDstClassName(), dstClassName, xCor - (time * (dstSideSize - i)), yCor + (time * (dstSideSize - i)), VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(ref.getDstObjectId(), new VertexObject(ref.getDstClassName(), vertex, xCor - (time * (dstSideSize - i)), yCor + (time * (dstSideSize - i)))); + objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), vertex, xCor - (time * (dstSideSize - i)), yCor + (time * (dstSideSize - i)))); } else { - Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, ref.getDstClassName(), ref.getDstClassName(), xCor - (time * (dstSideSize - i)), yCor + (time * (dstSideSize - i)), VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. - objectToVertexMap.put(ref.getDstObjectId(), new VertexObject(ref.getDstClassName(), vertex, xCor - (time * (dstSideSize - i)), yCor + (time * (dstSideSize - i)))); - ((mxICell)vertex).setStyle("fillColor=none;strokeColor=none;"); - ((mxICell)vertex).setValue(null); + objectToVertexMap.put(ref.getDstObjectId(), new ObjectVertex(ref.getDstClassName(), null, xCor - (time * (dstSideSize - i)), yCor + (time * (dstSideSize - i)))); } } - } finally { - mxgraph.getModel().endUpdate(); - } - } - + } finally { + mxgraph.getModel().endUpdate(); + } + } + + /** + * Create ObjectVertex when CONSTRACTOR_INVOCATION. + * @param alias + */ + private void createObjectVertexOnConstractor(Alias alias) { + ObjectVertex vertexObj = objectToVertexMap.get(alias.getObjectId()); + String souceObjId = alias.getMethodExecution().getThisObjId(); + mxICell sourceCell = (mxICell)objectToVertexMap.get(souceObjId).getCell(); + double sourceWidth = sourceCell.getGeometry().getWidth(); + double sourceHeight = sourceCell.getGeometry().getHeight(); + double overlapWidth = sourceWidth * Math.sqrt(2) * 0.1; + double overlapHeight = sourceHeight - (sourceHeight * Math.sqrt(2) * 0.1); + MethodInvocation methodInvocation = (MethodInvocation)alias.getOccurrencePoint().getStatement(); + String fieldName = methodInvocation.getCallerSideMethodName(); + ObjectIdPair objIdPair = deltaAliasCollector.getObjectPairByAlias(alias); + boolean isSrcSideChanged = objIdPair.getIsSrcSideChanged(); + mxgraph.getModel().beginUpdate(); + try { + Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, vertexObj.getLabel(), vertexObj.getLabel(), sourceCell.getGeometry().getX() + overlapWidth, sourceCell.getGeometry().getY() + overlapHeight, VERTEX_OBJECT_SIZE.getWidth(), VERTEX_OBJECT_SIZE.getHeight(), "fillColor=white"); //creates a white vertex. + vertexObj.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;"); + } + edgeMap.put(alias.getMethodExecution().getThisClassName() + "." + fieldName, new Edge(fieldName, TypeName.Create, edge)); + setStyleOfCells(); + deltaAnimation.setVertexAnimation((mxICell)vertex, new mxPoint(vertexObj.getInitialX(), vertexObj.getInitialY())); + deltaAnimation.startVertexAnimation(); + } finally { + mxgraph.getModel().endUpdate(); + } + } + + private void createObjectRefrence(FieldUpdate fieldUpdateStatement, String fieldName) { + String sourceObjectId = fieldUpdateStatement.getContainerObjId(); + String targetObjectId = fieldUpdateStatement.getValueObjId(); + mxICell targetCell = (mxICell)objectToVertexMap.get(targetObjectId).getCell(); + Point absolutePointTargetCell = getAbsolutePointforCell(targetCell); + + targetCell.getParent().remove(targetCell); + targetCell.setParent(mxDefaultParent); + targetCell.getGeometry().setX(absolutePointTargetCell.getX()); + targetCell.getGeometry().setY(absolutePointTargetCell.getY()); + Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldUpdateStatement.getFieldName(), fieldName, objectToVertexMap.get(sourceObjectId).getCell(), objectToVertexMap.get(targetObjectId).getCell()); + ((mxCell)edge).setStyle("exitX=0;exitY=0.5;exitPerimeter=1;entryX=1;entryY=0.5;entryPerimeter=1;"); + edgeMap.put(fieldUpdateStatement.getFieldName(), new Edge(fieldName, TypeName.Reference, edge)); + // System.out.println("last" + objectToVertexMap.get(targetObjectId).getInitialX() + ", " + objectToVertexMap.get(targetObjectId).getInitialY()); + deltaAnimation.setVertexAnimation(targetCell, new mxPoint(objectToVertexMap.get(targetObjectId).getInitialX(), objectToVertexMap.get(targetObjectId).getInitialY())); + deltaAnimation.startVertexAnimation(); + targetCell.getGeometry().setX(objectToVertexMap.get(targetObjectId).getInitialX()); + targetCell.getGeometry().setY(objectToVertexMap.get(targetObjectId).getInitialY()); + } + /** * SourceVertex move targetVertex. * @@ -538,12 +577,12 @@ */ private void moveObjectVertex(Alias alias) { // sourceVertex - VertexObject sourceVertexObject = objectToVertexMap.get(alias.getObjectId()); + ObjectVertex sourceObjectVertex = objectToVertexMap.get(alias.getObjectId()); // targetVertex - VertexMethodExecution targetVertexMethodExec = methodExecToVertexMap.get(alias.getMethodExecution()); - - moveObjectVertex(alias, sourceVertexObject, targetVertexMethodExec); - updateVertexObjectSize(); + MethodExecutionVertex targetMethodExecVertex = methodExecToVertexMap.get(alias.getMethodExecution()); + + moveObjectVertex(alias, sourceObjectVertex, targetMethodExecVertex); + updateObjectVerticesSize(); } /** @@ -553,7 +592,7 @@ * @param sourceVertexObject Source VertexObject. * @param targetVertexMethodExec Target VertexMethodExecution. */ - private void moveObjectVertex(Alias alias, VertexObject sourceVertexObject, VertexMethodExecution targetVertexMethodExec) { + private void moveObjectVertex(Alias alias, ObjectVertex sourceVertexObject, MethodExecutionVertex targetVertexMethodExec) { MethodExecution methodExec = alias.getMethodExecution(); if (alias.getAliasType().equals(AliasType.RETURN_VALUE) || alias.getAliasType().equals(AliasType.METHOD_INVOCATION)) { moveLocalObjectVertex(methodExec, sourceVertexObject, targetVertexMethodExec); @@ -571,23 +610,23 @@ * @param sourceVertexObject * @param targetVertexMethodExec */ - private void moveLocalObjectVertex(MethodExecution callerMethodExec, VertexObject sourceVertexObject, VertexMethodExecution targetVertexMethodExec) { + private void moveLocalObjectVertex(MethodExecution callerMethodExec, ObjectVertex sourceVertexObject, MethodExecutionVertex targetVertexMethodExec) { mxICell sourceCell = (mxICell)sourceVertexObject.getCell(); mxICell targetCell = (mxICell) targetVertexMethodExec.getCell(); -// mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); + // mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); // Remove sourceVertex from Locals and Arguments Vertex of MethodExecution's Vertex. -// MethodExecution callercallerMethodExec = callerMethodExec.getCallerMethodExecution(); - System.out.println(callerMethodExec.getSignature()); -// if (methodExecToVertexMap.containsKey(callercallerMethodExec) && methodExecToVertexMap.get(callercallerMethodExec).getLocals().contains(sourceVertexObject)) { -// methodExecToVertexMap.get(callercallerMethodExec).getLocals().remove(sourceVertexObject); -// System.out.println(methodExecToVertexMap.get(callercallerMethodExec).getLabel() + " :removeLocal: " + sourceVertexObject.getLabel()); -// } -// -// if (methodExecToVertexMap.containsKey(callercallerMethodExec) && methodExecToVertexMap.get(callercallerMethodExec).getArguments().contains(sourceVertexObject)) { -// methodExecToVertexMap.get(callercallerMethodExec).getArguments().remove(sourceVertexObject); -// System.out.println(methodExecToVertexMap.get(callercallerMethodExec).getLabel() + " :removeArgument: " + sourceVertexObject.getLabel()); -// } + // MethodExecution callercallerMethodExec = callerMethodExec.getCallerMethodExecution(); + // System.out.println(callerMethodExec.getSignature()); + // if (methodExecToVertexMap.containsKey(callercallerMethodExec) && methodExecToVertexMap.get(callercallerMethodExec).getLocals().contains(sourceVertexObject)) { + // methodExecToVertexMap.get(callercallerMethodExec).getLocals().remove(sourceVertexObject); + // System.out.println(methodExecToVertexMap.get(callercallerMethodExec).getLabel() + " :removeLocal: " + sourceVertexObject.getLabel()); + // } + // + // if (methodExecToVertexMap.containsKey(callercallerMethodExec) && methodExecToVertexMap.get(callercallerMethodExec).getArguments().contains(sourceVertexObject)) { + // methodExecToVertexMap.get(callercallerMethodExec).getArguments().remove(sourceVertexObject); + // System.out.println(methodExecToVertexMap.get(callercallerMethodExec).getLabel() + " :removeArgument: " + sourceVertexObject.getLabel()); + // } if (methodExecToVertexMap.containsKey(callerMethodExec) && methodExecToVertexMap.get(callerMethodExec).getLocals().contains(sourceVertexObject)) { methodExecToVertexMap.get(callerMethodExec).getLocals().remove(sourceVertexObject); System.out.println(methodExecToVertexMap.get(callerMethodExec).getLabel() + " :removeLocal: " + sourceVertexObject.getLabel()); @@ -605,18 +644,18 @@ double sourceX = sourceCell.getGeometry().getX(); double sourceY = sourceCell.getGeometry().getY(); -// System.out.println(time); - + // System.out.println(time); + if(sourceCell.getParent().getValue() != null) { Point absolutePointSourceCell = getAbsolutePointforCell(sourceCell); sourceX = absolutePointSourceCell.getX(); sourceY = absolutePointSourceCell.getY(); sourceCell.getParent().remove(sourceCell); } - + sourceCell.setParent(targetCell.getParent()); targetCell.getParent().insert(sourceCell); - + Point absolutePointTargetCell = getAbsolutePointforCell(sourceCell.getParent()); sourceCell.getGeometry().setX(sourceX - absolutePointTargetCell.getX()); sourceCell.getGeometry().setY(sourceY - absolutePointTargetCell.getY()); @@ -636,10 +675,10 @@ targetVertexMethodExec.getLocals().add(sourceVertexObject); System.out.println("moveLocalObjectVertex: " + targetVertexMethodExec.getLabel() + " :Local: " + sourceVertexObject.getLabel()); } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } } - + /** * Source VertexObject move target VertexMethodExecution to Argument position from MethodExecution. * @@ -647,10 +686,10 @@ * @param sourceVertexObject * @param targetVertexMethodExec */ - private void moveArgumentObjectVertex(MethodExecution methodExec, VertexObject sourceVertexObject, VertexMethodExecution targetVertexMethodExec) { + private void moveArgumentObjectVertex(MethodExecution methodExec, ObjectVertex sourceVertexObject, MethodExecutionVertex targetVertexMethodExec) { mxICell sourceCell = (mxICell)sourceVertexObject.getCell(); mxICell targetCell = (mxICell) targetVertexMethodExec.getCell(); -// mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); + // mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); // Remove sourceVertex from Locals and Arguments Vertex of MethodExecution's Vertex. MethodExecution callerMethodExecution = methodExec.getCallerMethodExecution(); @@ -671,7 +710,7 @@ double sourceX = sourceCell.getGeometry().getX(); double sourceY = sourceCell.getGeometry().getY(); -// System.out.println(time); + // System.out.println(time); if(sourceCell.getParent().getValue() != null) { Point absolutePointSourceCell = getAbsolutePointforCell(sourceCell); @@ -679,7 +718,7 @@ sourceY = absolutePointSourceCell.getY(); sourceCell.getParent().remove(sourceCell); } - + sourceCell.setParent(targetCell.getParent()); targetCell.getParent().insert(sourceCell); sourceCell.getGeometry().setX(sourceX - sourceCell.getParent().getGeometry().getX()); @@ -689,21 +728,21 @@ double sourceHeight = sourceCell.getGeometry().getHeight(); double overlapWidth = sourceWidth - (sourceWidth * Math.sqrt(2) * 0.1); double overlapHeight = sourceHeight - (sourceHeight * Math.sqrt(2) * 0.1); - + deltaAnimation.setVertexAnimation(sourceCell, new mxPoint(targetCell.getGeometry().getX() - overlapWidth, targetCell.getGeometry().getY() - overlapHeight + (sourceHeight * time))); deltaAnimation.startVertexAnimation(); -// sourceCell.setParent(targetCell.getParent()); -// targetCell.getParent().insert(sourceCell); + // sourceCell.setParent(targetCell.getParent()); + // targetCell.getParent().insert(sourceCell); sourceCell.getGeometry().setX(targetCell.getGeometry().getX() - overlapWidth); sourceCell.getGeometry().setY(targetCell.getGeometry().getY() - overlapHeight + (sourceHeight * time)); targetVertexMethodExec.getArguments().add(sourceVertexObject); System.out.println("moveArgumentObejctVertex" + targetVertexMethodExec.getLabel() + " :Argument: " + sourceVertexObject.getLabel()); } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } } - + /** * Source VertexObject move target VertexMethodExecution to Argument position from MethodExecution. * @@ -711,24 +750,24 @@ * @param sourceVertexObject * @param targetVertexMethodExec */ - private void moveActualArgumentObjectVertex(MethodExecution methodExec, VertexObject sourceVertexObject, VertexMethodExecution targetVertexMethodExec) { + private void moveActualArgumentObjectVertex(MethodExecution methodExec, ObjectVertex sourceVertexObject, MethodExecutionVertex targetVertexMethodExec) { mxICell sourceCell = (mxICell)sourceVertexObject.getCell(); mxICell targetCell = (mxICell) targetVertexMethodExec.getCell(); -// mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); + // mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); // Remove sourceVertex from Locals and Arguments Vertex of MethodExecution's Vertex. -// MethodExecution callerMethodExecution = methodExec.getCallerMethodExecution(); + // MethodExecution callerMethodExecution = methodExec.getCallerMethodExecution(); System.out.println(methodExec.getSignature()); System.out.println(sourceVertexObject.getLabel()); -// if (methodExecToVertexMap.containsKey(callerMethodExecution) && methodExecToVertexMap.get(callerMethodExecution).getLocals().contains(sourceVertexObject)) { -// methodExecToVertexMap.get(callerMethodExecution).getLocals().remove(sourceVertexObject); -// System.out.println(methodExecToVertexMap.get(callerMethodExecution).getLabel() + " :removeLocal: " + sourceVertexObject.getLabel()); -// } -// -// if (methodExecToVertexMap.containsKey(callerMethodExecution) && methodExecToVertexMap.get(callerMethodExecution).getArguments().contains(sourceVertexObject)) { -// methodExecToVertexMap.get(callerMethodExecution).getArguments().remove(sourceVertexObject); -// System.out.println(methodExecToVertexMap.get(callerMethodExecution).getLabel() + " :removeArgument: " + sourceVertexObject.getLabel()); -// } + // if (methodExecToVertexMap.containsKey(callerMethodExecution) && methodExecToVertexMap.get(callerMethodExecution).getLocals().contains(sourceVertexObject)) { + // methodExecToVertexMap.get(callerMethodExecution).getLocals().remove(sourceVertexObject); + // System.out.println(methodExecToVertexMap.get(callerMethodExecution).getLabel() + " :removeLocal: " + sourceVertexObject.getLabel()); + // } + // + // if (methodExecToVertexMap.containsKey(callerMethodExecution) && methodExecToVertexMap.get(callerMethodExecution).getArguments().contains(sourceVertexObject)) { + // methodExecToVertexMap.get(callerMethodExecution).getArguments().remove(sourceVertexObject); + // System.out.println(methodExecToVertexMap.get(callerMethodExecution).getLabel() + " :removeArgument: " + sourceVertexObject.getLabel()); + // } if (methodExecToVertexMap.containsKey(methodExec) && methodExecToVertexMap.get(methodExec).getLocals().contains(sourceVertexObject)) { methodExecToVertexMap.get(methodExec).getLocals().remove(sourceVertexObject); System.out.println(methodExecToVertexMap.get(methodExec).getLabel() + " :removeLocal: " + sourceVertexObject.getLabel()); @@ -742,13 +781,13 @@ // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. mxgraph.getModel().beginUpdate(); try { -// int time = targetVertexMethodExec.getArguments().size(); + // int time = targetVertexMethodExec.getArguments().size(); int time = targetVertexMethodExec.getLocals().size() + 1; double sourceX = sourceCell.getGeometry().getX(); double sourceY = sourceCell.getGeometry().getY(); System.out.println(time + ", " + targetVertexMethodExec.getLocals().size()); -// if (time == 0) time = 1; + // if (time == 0) time = 1; if(sourceCell.getParent().getValue() != null) { Point absolutePointSourceCell = getAbsolutePointforCell(sourceCell); @@ -756,7 +795,7 @@ sourceY = absolutePointSourceCell.getY(); sourceCell.getParent().remove(sourceCell); } - + sourceCell.setParent(targetCell.getParent()); targetCell.getParent().insert(sourceCell); sourceCell.getGeometry().setX(sourceX - sourceCell.getParent().getGeometry().getX()); @@ -766,7 +805,7 @@ double sourceHeight = sourceCell.getGeometry().getHeight(); double overlapWidth = sourceWidth - (sourceWidth * Math.sqrt(2) * 0.1); double overlapHeight = sourceHeight - (sourceHeight * Math.sqrt(2) * 0.1); - + deltaAnimation.setVertexAnimation(sourceCell, new mxPoint(targetCell.getGeometry().getX() - overlapWidth, targetCell.getGeometry().getY() - overlapHeight + (sourceHeight * time))); deltaAnimation.startVertexAnimation(); sourceCell.getGeometry().setX(targetCell.getGeometry().getX() - overlapWidth); @@ -774,35 +813,61 @@ targetVertexMethodExec.getArguments().add(sourceVertexObject); System.out.println("moveActualArgumentObjectVertex: " + targetVertexMethodExec.getLabel() + " :Argument: " + sourceVertexObject.getLabel()); } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } } - - /** Update VertexObject size. */ - private void updateVertexObjectSize() { - // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology -// mxgraph.getModel().beginUpdate(); -// try { - for (VertexObject vertexObject: objectToVertexMap.values()) { + + // private void moveInitialObjectVertex(MethodExecution methodExecution) { + // for(Statement statement: methodExecution.getStatements()) { + // if(statement instanceof MethodInvocation) { + // // moveInitialVertexObject((MethodInvocation) statement); + // MethodExecution calledMethodExec = ((MethodInvocation)statement).getCalledMethodExecution(); + // String calledObjectId = calledMethodExec.getThisObjId(); + // mxICell calledCell = (mxICell)objectToVertexMap.get(calledObjectId).getCell(); + // Point absolutePointCalledCell = getAbsolutePointforCell(calledCell); + // // System.out.println(objectId + ", " + methodExec.getSignature()); + // // objectToVertexMap.get(calledObjectId).resetCellPosition(); + // if (methodExecToVertexMap.get(methodExecution).getArguments().contains(objectToVertexMap.get(calledObjectId)) || methodExecToVertexMap.get(methodExecution).getLocals().contains(objectToVertexMap.get(calledObjectId))) { + // calledCell.getParent().remove(calledCell); + // calledCell.setParent(mxDefaultParent); + // calledCell.getGeometry().setX(absolutePointCalledCell.getX()); + // calledCell.getGeometry().setY(absolutePointCalledCell.getY()); + // deltaAnimation.setVertexAnimation(calledCell, new mxPoint(objectToVertexMap.get(calledObjectId).getInitialX(), objectToVertexMap.get(calledObjectId).getInitialY())); + // deltaAnimation.startVertexAnimation(); + // break; + // } + // } + // } + // } + + /** Update ObjectVertices size. */ + private void updateObjectVerticesSize() { + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology + mxgraph.getModel().beginUpdate(); + try { + for (ObjectVertex vertexObject: objectToVertexMap.values()) { mxCell vertexObjectCell = ((mxCell) vertexObject.getCell()); - int time = vertexObjectCell.getChildCount(); - if (time == 0) { - time = 1; - } -// System.out.println("updateVertexObjectSize: " + vertexObjectCell.getGeometry().getWidth() + "->" + VERTEX_OBJECT_SIZE.getWidth() * time+ ", " + vertexObjectCell.getId()); - if(vertexObjectCell.getGeometry().getWidth() != VERTEX_OBJECT_SIZE.getWidth() * time) { - System.out.println("updateVertexObjectSize: " + vertexObjectCell.getGeometry().getWidth() + "->" + VERTEX_OBJECT_SIZE.getWidth() * time+ ", " + vertexObjectCell.getId()); - Dimension targetDimension = new Dimension(); - targetDimension.setSize(VERTEX_OBJECT_SIZE.getWidth() * time, VERTEX_OBJECT_SIZE.getHeight() * time); - deltaAnimation.setResizeVertexAnimation(vertexObjectCell, targetDimension); - deltaAnimation.startResizeVertexAnimation(); - } + int time = vertexObjectCell.getChildCount(); + if (time == 0) { + time = 1; + } + // System.out.println("updateVertexObjectSize: " + vertexObjectCell.getGeometry().getWidth() + "->" + VERTEX_OBJECT_SIZE.getWidth() * time+ ", " + vertexObjectCell.getId()); + if(vertexObjectCell.getGeometry().getWidth() != VERTEX_OBJECT_SIZE.getWidth() * time) { + System.out.println("updateVertexObjectSize: " + vertexObjectCell.getGeometry().getWidth() + "->" + VERTEX_OBJECT_SIZE.getWidth() * time+ ", " + vertexObjectCell.getId()); + Dimension targetDimension = new Dimension(); + targetDimension.setSize(VERTEX_OBJECT_SIZE.getWidth() * time, VERTEX_OBJECT_SIZE.getHeight() * time); + // if (vertexObjectCell.getParent() != mxDefaultParent && vertexObjectCell.getChildCount() != 0) { + // mxPoint targetPoint = new mxPoint(vertexObjectCell.getGeometry().getX() - (targetDimension.getWidth() - vertexObjectCell.getGeometry().getWidth()) / 2, vertexObjectCell.getGeometry().getY() + (targetDimension.getHeight() - vertexObjectCell.getGeometry().getHeight()) / 2); + // deltaAnimation.setVertexAnimation(vertexObjectCell, targetPoint); + // deltaAnimation.startVertexAnimation(); + // } + deltaAnimation.setResizeVertexAnimation(vertexObjectCell, targetDimension); + deltaAnimation.startResizeVertexAnimation(); + } } -// }finally { -// mxgraph.getModel().endUpdate(); -// } - - show(mxDefaultParent); + }finally { + mxgraph.getModel().endUpdate(); + } } /** @@ -811,222 +876,91 @@ * @param sourceObjectCell * @param targetMethodExecCell */ - private void updateVertexObjectSize(mxICell sourceObjectCell, mxICell targetMethodExecCell) { - mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); - - //Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); - try { - double preX = parentTargetMethodExecCell.getGeometry().getX(); - double preY = parentTargetMethodExecCell.getGeometry().getY(); - double preCenterX = parentTargetMethodExecCell.getGeometry().getCenterX(); - double preCenterY = parentTargetMethodExecCell.getGeometry().getCenterY(); - parentTargetMethodExecCell.getGeometry().setWidth(parentTargetMethodExecCell.getGeometry().getWidth() * 1.8); - parentTargetMethodExecCell.getGeometry().setHeight(parentTargetMethodExecCell.getGeometry().getHeight() * 1.8); - parentTargetMethodExecCell.getGeometry().setX(preX - (parentTargetMethodExecCell.getGeometry().getCenterX() - preCenterX)); - parentTargetMethodExecCell.getGeometry().setY(preY - (parentTargetMethodExecCell.getGeometry().getCenterY() - preCenterY)); - } finally { - mxgraph.getModel().endUpdate(); - } - } - - private void show(mxICell cell) { - for (Object object: mxgraph.getChildCells(cell)) { - System.out.println(object); - for (int i = 0; i < ((mxICell)object).getChildCount(); i++) { - System.out.println(" " + ((mxICell)object).getChildAt(i)); - } - } - for (VertexObject vo: objectToVertexMap.values()) { - System.out.println(vo.getLabel()); - for (VertexMethodExecution vme: vo.getVertexMethodExecutions()) { - System.out.println(" " + vme.getLabel()); - for (VertexObject vmevo: vme.getArguments()) { - System.out.println(" Argument: " + vmevo.getLabel()); - } - for (VertexObject vmevo: vme.getLocals()) { - System.out.println(" Local: " + vmevo.getLabel()); - } - } - } - for (Edge e: edgeMap.values()) { - System.out.println(e.getLabel() + ", " + e.getCell() + ", " + ((mxICell)e.getCell()).getParent()); - } - } + // private void updateVertexObjectSize(mxICell sourceObjectCell, mxICell targetMethodExecCell) { + // mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); + // + // //Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. + // mxgraph.getModel().beginUpdate(); + // try { + // double preX = parentTargetMethodExecCell.getGeometry().getX(); + // double preY = parentTargetMethodExecCell.getGeometry().getY(); + // double preCenterX = parentTargetMethodExecCell.getGeometry().getCenterX(); + // double preCenterY = parentTargetMethodExecCell.getGeometry().getCenterY(); + // parentTargetMethodExecCell.getGeometry().setWidth(parentTargetMethodExecCell.getGeometry().getWidth() * 1.8); + // parentTargetMethodExecCell.getGeometry().setHeight(parentTargetMethodExecCell.getGeometry().getHeight() * 1.8); + // parentTargetMethodExecCell.getGeometry().setX(preX - (parentTargetMethodExecCell.getGeometry().getCenterX() - preCenterX)); + // parentTargetMethodExecCell.getGeometry().setY(preY - (parentTargetMethodExecCell.getGeometry().getCenterY() - preCenterY)); + // } finally { + // mxgraph.getModel().endUpdate(); + // } + // } - /** Make edge object in JGraphT and draw this in JGraphX. */ - private void makeEdgeObject() { - Map> fieldNameMap = new HashMap<>(); - Map> aliasEntryMap = new HashMap<>(); - - // Format field name. - for (int i = 0; i < aliasList.size()-1; i++) { - Alias curAlias = aliasList.get(i); - Alias nextAlias = aliasList.get(i+1); - - if (curAlias.getAliasType().equals(AliasType.THIS) /*&& nextAlias.getAliasType().equals(AliasType.FIELD)*/) { - String className = null; - String fieldName = null; - if (nextAlias.getAliasType().equals(AliasType.RETURN_VALUE)) { - className = curAlias.getMethodExecution().getThisClassName(); - fieldName = curAlias.getOccurrencePoint().getMethodExecution().getArguments().get(0).getId(); - System.out.println("rTHIS " + className + ", " +curAlias.getOccurrencePoint().getMethodExecution().getArguments().get(0).getId()); - } else { - Statement statement = curAlias.getOccurrencePoint().getStatement(); - if(statement instanceof FieldAccess) { - String fieldNames[] = formatFieldName(((FieldAccess)statement).getFieldName()); - className = fieldNames[0]; - fieldName = fieldNames[1]; - } - } - if (className != null && fieldName != null) { - if(fieldNameMap.get(className) == null) { - fieldNameMap.put(className, new HashSet()); - } - fieldNameMap.get(className).add(fieldName); - aliasEntryMap.put(fieldName, new SimpleEntry(curAlias.getObjectId(), nextAlias.getObjectId())); - System.out.println("THIS " + className + ", " + fieldName); - System.out.println("THIS " + curAlias.getObjectId() + ", " + nextAlias.getObjectId()); - } - } - if(curAlias.getAliasType().equals(AliasType.ARRAY)) { - Statement statement= curAlias.getOccurrencePoint().getStatement(); - if(statement instanceof ArrayAccess) { - System.out.println("ARRAY " + ((ArrayAccess)statement).getArrayClassName() + ", " + ((ArrayAccess)statement).getIndex()); - String arrayClassName = ((ArrayAccess)statement).getArrayClassName(); - int index = ((ArrayAccess)statement).getIndex(); - String arrayIndex = formatArrayIndex(index); - if(fieldNameMap.get(arrayClassName) == null) { - fieldNameMap.put(arrayClassName, new HashSet()); - } - fieldNameMap.get(arrayClassName).add(arrayIndex); - aliasEntryMap.put(arrayIndex, new SimpleEntry(curAlias.getObjectId(), nextAlias.getObjectId())); - System.out.println("ARRAY " + arrayClassName + ", " + arrayIndex); - System.out.println("ARRAY " + curAlias.getObjectId() + ", " + nextAlias.getObjectId()); - } - } - } - - mxgraph.getModel().beginUpdate(); - try { - // Make object edge in JGraphT and draw this in JGraphX. - Delta delta = eStructure.getDelta(); - int srcSideSize = delta.getSrcSide().size(); - int dstSideSize = delta.getDstSide().size(); - for (int i = srcSideSize - 1; i >= 0; i--) { - Reference ref = delta.getSrcSide().get(i); - String srcObjId = ref.getSrcObjectId(); - String dstObjId = ref.getDstObjectId(); - if (!ref.isCreation() || !srcObjId.equals(dstObjId)) { - String srcClassName = ref.getSrcClassName(); - String dstClassName = ref.getDstClassName(); - for(String fieldName: fieldNameMap.get(srcClassName)) { - System.out.println(fieldName + ", " + srcClassName + ", " + dstClassName); - // ?BUG : contains -> equals - if(srcObjId.contains(aliasEntryMap.get(fieldName).getKey()) && dstObjId.contains(aliasEntryMap.get(fieldName).getValue())) { - System.out.println("makeEdgeObject: " + fieldName + ", " + srcClassName + ", " + dstClassName); - Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, fieldName, objectToVertexMap.get(srcObjId).getCell(), objectToVertexMap.get(dstObjId).getCell()); - ((mxCell)edge).setStyle("exitX=1;exitY=1;exitPerimeter=1;entryX=0;entryY=0;entryPerimeter=1;"); - edgeMap.put(srcClassName + "." + fieldName, new Edge(fieldName, TypeName.Reference, edge)); - break; - } - } - } - } - - for (int i = dstSideSize - 1; i >= 0; i--) { - Reference ref = delta.getDstSide().get(i); - String srcObjId = ref.getSrcObjectId(); - String dstObjId = ref.getDstObjectId(); - if ((!ref.isCreation() || !srcObjId.equals(dstObjId)) /*&& fieldNameMap.containsKey(ref.getSrcClassName())*/) { - String srcClassName = ref.getSrcClassName(); - String dstClassName = ref.getDstClassName(); - if (fieldNameMap.get(srcClassName) != null) { - for (String fieldName: fieldNameMap.get(srcClassName)) { - System.out.println(fieldName + ", " + srcClassName + ", " + dstClassName); - // ?BUG : contains -> equals - if (srcObjId.contains(aliasEntryMap.get(fieldName).getKey()) && dstObjId.contains(aliasEntryMap.get(fieldName).getValue())) { - System.out.println("makeEdgeObject: " + fieldName + ", " + srcObjId + ", " + dstObjId); - Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, fieldName, objectToVertexMap.get(srcObjId).getCell(), objectToVertexMap.get(dstObjId).getCell()); - ((mxCell)edge).setStyle("exitX=0;exitY=1;exitPerimeter=1;entryX=1;entryY=0;entryPerimeter=1;"); - edgeMap.put(ref.getSrcClassName() + "." + fieldName, new Edge(fieldName, TypeName.Reference, edge)); - break; - } - } - } - } - } - } finally { - mxgraph.getModel().endUpdate(); - } + /** + * Create MethodExecutionVertex. + * + * @param alias + */ + private void createMethodExecutionVertex(Alias alias) { + createMethodExecutionVertex(alias, alias.getMethodSignature(), alias.getMethodExecution()); } /** - * Make VertexMethodExecution. - * - * @param alias - */ - private void makeVertexMethodExecution(Alias alias) { - makeVertexMethodExecution(alias, alias.getMethodSignature(), alias.getMethodExecution()); - } - - /** - * Parent : Make VertexMethodExecution. + * Parent : Create MethodExecutionVertex. * * @param alias * @param methodSignature Called or this MethodSignature. * @param methodExec Called or this MethodExecution. */ - private void makeVertexMethodExecution(Alias alias, String methodSignature, MethodExecution methodExec) { - - if (methodSignature.contains(" ")) { - System.out.println(methodSignature); - methodSignature = formatMethodSignature(methodSignature); - } + private void createMethodExecutionVertex(Alias alias, String methodSignature, MethodExecution methodExec) { + + if (methodSignature.contains(" ")) { + System.out.println(methodSignature); + methodSignature = formatMethodSignature(methodSignature); + } // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. - mxgraph.getModel().beginUpdate(); - try { - String objectId = alias.getObjectId(); - Object object = objectToVertexMap.get(objectId).getCell(); - double xCor = VERTEX_OBJECT_SIZE.getWidth() * 0.1; - double yCor = VERTEX_OBJECT_SIZE.getHeight() * 0.5; - int time = objectToVertexMap.get(objectId).getVertexMethodExecutions().size(); - - Object vertex = mxgraph.insertDeltaVertex(object, methodSignature, methodSignature, "fillColor=white"); //creates a white vertex. - System.out.println("makeVertexMethodExecution: " + ((mxICell)vertex).getId()); + mxgraph.getModel().beginUpdate(); + try { + String objectId = alias.getObjectId(); + Object object = objectToVertexMap.get(objectId).getCell(); + double xCor = VERTEX_OBJECT_SIZE.getWidth() * 0.1; + double yCor = VERTEX_OBJECT_SIZE.getHeight() * 0.5; + int time = objectToVertexMap.get(objectId).getVertexMethodExecutions().size(); - VertexMethodExecution vertexMethodExecution = new VertexMethodExecution(methodSignature, vertex, xCor * (time + 1), yCor * (time + 1), VERTEX_METHOD_EXECUTION_SIZE.getWidth(), VERTEX_METHOD_EXECUTION_SIZE.getHeight()); -// Object vertex = mxgraph.insertVertex(object, methodSignature, methodSignature, 0, 0, 0, 0, "fillColor=white", true); //creates a white vertex. -// Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, methodSignature, methodSignature, "fillColor=white"); //creates a white vertex. -// VertexMethodExecution vertexMethodExecution = new VertexMethodExecution(methodSignature, vertex, getXForCell(objectId) + (xCor * (time + 1)), getYForCell(objectId) + (yCor * (time + 1)), VERTEX_METHOD_EXECUTION_SIZE.getWidth(), VERTEX_METHOD_EXECUTION_SIZE.getHeight()); + Object vertex = mxgraph.insertDeltaVertex(object, methodSignature, methodSignature, "fillColor=white"); //creates a white vertex. + System.out.println("makeVertexMethodExecution: " + ((mxICell)vertex).getId() + " (" + xCor * (time + 1) + ", " + yCor * (time + 1) + ")"); + + MethodExecutionVertex vertexMethodExecution = new MethodExecutionVertex(methodSignature, vertex, xCor , yCor * (time + 1), VERTEX_METHOD_EXECUTION_SIZE.getWidth(), VERTEX_METHOD_EXECUTION_SIZE.getHeight()); + // Object vertex = mxgraph.insertVertex(object, methodSignature, methodSignature, 0, 0, 0, 0, "fillColor=white", true); //creates a white vertex. + // Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, methodSignature, methodSignature, "fillColor=white"); //creates a white vertex. + // VertexMethodExecution vertexMethodExecution = new VertexMethodExecution(methodSignature, vertex, getXForCell(objectId) + (xCor * (time + 1)), getYForCell(objectId) + (yCor * (time + 1)), VERTEX_METHOD_EXECUTION_SIZE.getWidth(), VERTEX_METHOD_EXECUTION_SIZE.getHeight()); methodExecToVertexMap.put(methodExec, vertexMethodExecution); if(methodExecToVertexMap.size() > 1) { ((mxICell)vertex).setVisible(false); - makeEdgeMethodExecution(); - show(mxDefaultParent); + createEdgeToMethodExecution(); } objectToVertexMap.get(objectId).addMethodExecution(vertexMethodExecution); - } finally { - mxgraph.getModel().endUpdate(); - } + } finally { + mxgraph.getModel().endUpdate(); + } + setStyleOfCells(); } - + /** * Remove VertexMethodExecution on AliasType is MethodInvocation of alias. * * @param alias */ - private void removeVertexMethodExecution(Alias alias) { + private void removeMethodExecutionVertex(Alias alias) { // sourceVertex - VertexObject sourceVertexObject = objectToVertexMap.get(alias.getObjectId()); + ObjectVertex sourceVertexObject = objectToVertexMap.get(alias.getObjectId()); MethodExecution methodExec = alias.getMethodExecution(); - - if(alias.getAliasType().equals(AliasType.METHOD_INVOCATION)) { + + if(alias.getAliasType().equals(AliasType.METHOD_INVOCATION) || alias.getAliasType().equals(AliasType.CONSTRACTOR_INVOCATION)) { MethodExecution calledMethodExec = ((MethodInvocation) alias.getOccurrencePoint().getStatement()).getCalledMethodExecution(); - removeCalledVertexMethodExecution(sourceVertexObject, methodExec, calledMethodExec); + removeCalledMethodExecutionVertex(sourceVertexObject, methodExec, calledMethodExec); } else { - removeVertexMethodExecution(sourceVertexObject, methodExec); + removeMethodExecutionVertex(sourceVertexObject, methodExec); } } @@ -1036,7 +970,7 @@ * @param sourceVertexObject * @param methodExec */ - private void removeVertexMethodExecution(VertexObject sourceVertexObject, MethodExecution methodExec) { + private void removeMethodExecutionVertex(ObjectVertex sourceVertexObject, MethodExecution methodExec) { // Remove sourceVertex from Locals and Arguments Vertex of CalledMethodExecution's Vertex. if (methodExecToVertexMap.containsKey(methodExec)) { mxCell targetVertexCell = (mxCell)methodExecToVertexMap.get(methodExec).getCell(); @@ -1046,7 +980,7 @@ objectToVertexMap.get(methodExec.getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(methodExec)); methodExecToVertexMap.remove(methodExec); edgeMap.remove(methodExec.getSignature()); - updateVertexObjectSize(); + updateObjectVerticesSize(); } } @@ -1057,7 +991,7 @@ * @param methodExec * @param calledMethodExec */ - private void removeCalledVertexMethodExecution(VertexObject sourceVertexObject, MethodExecution methodExec, MethodExecution calledMethodExec) { + private void removeCalledMethodExecutionVertex(ObjectVertex sourceVertexObject, MethodExecution methodExec, MethodExecution calledMethodExec) { // Remove sourceVertex from Locals and Arguments Vertex of CalledMethodExecution's Vertex. if (methodExecToVertexMap.containsKey(calledMethodExec)) { @@ -1069,43 +1003,131 @@ mxgraph.getModel().beginUpdate(); try { mxgraph.removeCells(mxgraph.getEdgesBetween(sourceVertexCell, targetVertexCell)); - try { - mxICell cloneTargetVertexCell = (mxICell) mxgraph.addCell(targetVertexCell.clone()); - Point absolutPointTargetVertexCell = getAbsolutePointforCell(targetVertexCell); - cloneTargetVertexCell.getGeometry().setX(absolutPointTargetVertexCell.getX()); - cloneTargetVertexCell.getGeometry().setY(absolutPointTargetVertexCell.getY()); - cloneTargetVertexCell.setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); - cloneTargetVertexCell.setValue(null); - Object tempEdge = mxgraph.insertEdge(mxDefaultParent, null, null, sourceVertexCell, cloneTargetVertexCell); - ((mxCell)tempEdge).setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); - deltaAnimation.setReductionEdgeAnimation(cloneTargetVertexCell, new mxPoint(absolutPointSourceVertexCell.getX(), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight())); - deltaAnimation.startReductionEdgeAnimation(); -// deltaAnimation.setReductionEdgeAnimation(new mxPoint(absolutPointSourceVertexCell.getX() + (sourceVertexCell.getGeometry().getWidth() / 2), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(absolutPointTargetVertexCell.getX() + (targetVertexCell.getGeometry().getWidth() / 2), absolutPointTargetVertexCell.getY())); -// deltaAnimation.startReductionEdgeAnimation(); - mxgraph.removeCells(new Object[]{cloneTargetVertexCell}); - } catch (CloneNotSupportedException e) { - e.printStackTrace(); - } + try { + mxICell cloneTargetVertexCell = (mxICell) mxgraph.addCell(targetVertexCell.clone()); + Point absolutPointTargetVertexCell = getAbsolutePointforCell(targetVertexCell); + cloneTargetVertexCell.getGeometry().setX(absolutPointTargetVertexCell.getX()); + cloneTargetVertexCell.getGeometry().setY(absolutPointTargetVertexCell.getY()); + cloneTargetVertexCell.setStyle("fillColor=none;strokeColor=none;fontColor=#008000;"); + cloneTargetVertexCell.setValue(null); + Object tempEdge = mxgraph.insertEdge(mxDefaultParent, null, null, sourceVertexCell, cloneTargetVertexCell); + ((mxCell)tempEdge).setStyle("dashed=1;strokeColor=#008000;exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;endArrow=none"); + deltaAnimation.setReductionEdgeAnimation(cloneTargetVertexCell, new mxPoint(absolutPointSourceVertexCell.getX(), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight())); + deltaAnimation.startReductionEdgeAnimation(); + // deltaAnimation.setReductionEdgeAnimation(new mxPoint(absolutPointSourceVertexCell.getX() + (sourceVertexCell.getGeometry().getWidth() / 2), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(absolutPointTargetVertexCell.getX() + (targetVertexCell.getGeometry().getWidth() / 2), absolutPointTargetVertexCell.getY())); + // deltaAnimation.startReductionEdgeAnimation(); + mxgraph.removeCells(new Object[]{cloneTargetVertexCell}); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } - - targetVertexCell.getParent().remove(targetVertexCell); + ((mxCell)targetVertexCell.getParent()).remove(targetVertexCell); targetVertexCell.setParent(mxDefaultParent); mxgraph.removeCells(new Object[] {targetVertexCell}); objectToVertexMap.get(calledMethodExec.getThisObjId()).getVertexMethodExecutions().remove(methodExecToVertexMap.get(calledMethodExec)); methodExecToVertexMap.get(calledMethodExec).getLocals().remove(sourceVertexObject); methodExecToVertexMap.remove(calledMethodExec); edgeMap.remove(methodExec.getSignature()); -// updateVertexObjectSize(); + // moveInitialVertexObject(methodExec); + // updateObjectVerticesSize(); } } + /** + * Update VertexObject of targetMethodExecCell size have sourceObjectCell. + * + * @param sourceObjectCell + * @param targetMethodExecCell + */ + // private void updateVertexObjectSize(mxICell sourceObjectCell, mxICell targetMethodExecCell) { + // mxICell parentTargetMethodExecCell = targetMethodExecCell.getParent(); + // + // //Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. + // mxgraph.getModel().beginUpdate(); + // try { + // double preX = parentTargetMethodExecCell.getGeometry().getX(); + // double preY = parentTargetMethodExecCell.getGeometry().getY(); + // double preCenterX = parentTargetMethodExecCell.getGeometry().getCenterX(); + // double preCenterY = parentTargetMethodExecCell.getGeometry().getCenterY(); + // parentTargetMethodExecCell.getGeometry().setWidth(parentTargetMethodExecCell.getGeometry().getWidth() * 1.8); + // parentTargetMethodExecCell.getGeometry().setHeight(parentTargetMethodExecCell.getGeometry().getHeight() * 1.8); + // parentTargetMethodExecCell.getGeometry().setX(preX - (parentTargetMethodExecCell.getGeometry().getCenterX() - preCenterX)); + // parentTargetMethodExecCell.getGeometry().setY(preY - (parentTargetMethodExecCell.getGeometry().getCenterY() - preCenterY)); + // } finally { + // mxgraph.getModel().endUpdate(); + // } + // } + + /** Make edge object in JGraphT and draw this in JGraphX. + * @param map + * @param collection */ + private void createEdgeToObject(List aliasList, Map aliasToObjIdPair) { + for (int i = 0; i < aliasList.size()-1; i++) { + Alias curAlias = aliasList.get(i); + Alias nextAlias = aliasList.get(i+1); + String srcClassName = null; + String fieldName = null; + + if (curAlias.getAliasType().equals(AliasType.THIS) /*&& nextAlias.getAliasType().equals(AliasType.FIELD)*/) { + if (nextAlias.getAliasType().equals(AliasType.RETURN_VALUE)) { + MethodExecution nextMethodExec = nextAlias.getMethodExecution(); + //Array��List�̂Ƃ��������x����t����i�m���ɕ������Ă�����̂Ƃ�)getSignature->contains("List.get(") || "Map.get(") <�z���C�g���X�g> + if (nextMethodExec.getSignature().contains("List.get(") || + nextMethodExec.getSignature().contains("Map.get(")) { + srcClassName = nextMethodExec.getThisClassName(); + fieldName = 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) { + String fieldNames[] = formatFieldName(((FieldAccess)statement).getFieldName()); + srcClassName = fieldNames[0]; + fieldName = fieldNames[1]; + } + } + System.out.println("THIS " + srcClassName + "(" + curAlias.getObjectId() + ") -> " + "(" + nextAlias.getObjectId() + "), "+ fieldName); + } + if(curAlias.getAliasType().equals(AliasType.ARRAY)) { + Statement statement= nextAlias.getOccurrencePoint().getStatement(); + if(statement instanceof ArrayAccess) { + srcClassName = ((ArrayAccess)statement).getArrayClassName(); + int index = ((ArrayAccess)statement).getIndex(); + fieldName = formatArrayIndex(index); + System.out.println("ARRAY " + srcClassName + "(" + curAlias.getObjectId() + ") -> " + "(" + nextAlias.getObjectId() + "), " + fieldName); + } + } + if (srcClassName != null && fieldName != null && srcClassName != null) { + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. + mxgraph.getModel().beginUpdate(); + try { + ObjectIdPair objIdPair = aliasToObjIdPair.get(nextAlias); + String srcObjId = objIdPair.getObjIdPair().getKey(); + String dstObjId = objIdPair.getObjIdPair().getValue(); + boolean isSrcSideChanged = objIdPair.getIsSrcSideChanged(); + // String dstClassName = curAlias.getMethodExecution().getThisClassName(); + System.out.println("makeEdgeObject: " + fieldName + ", " + srcClassName/* + ", " + dstClassName*/); + Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, fieldName, fieldName, objectToVertexMap.get(srcObjId).getCell(), objectToVertexMap.get(dstObjId).getCell()); + 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;"); + } + edgeMap.put(srcClassName + "." + fieldName, new Edge(fieldName, TypeName.Reference, edge)); + } finally { + mxgraph.getModel().endUpdate(); + } + } + } + } + /** Make EdgeMethodExecution. */ - private void makeEdgeMethodExecution() { + private void createEdgeToMethodExecution() { List methodExecList = new ArrayList<>(methodExecToVertexMap.keySet()); - + // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology mxgraph.getModel().beginUpdate(); try { @@ -1115,43 +1137,43 @@ MethodExecution targetMethodExec = methodExecList.get(i + 1); String methodSignature = sourceMethodExec.getSignature(); if (!edgeMap.containsKey(methodSignature)) { - mxICell sourceVertexCell = (mxICell)methodExecToVertexMap.get(sourceMethodExec).getCell(); - mxICell targetVertexCell = (mxICell)methodExecToVertexMap.get(targetMethodExec).getCell(); - Point absolutPointSourceVertexCell = getAbsolutePointforCell(sourceVertexCell); - Point absolutPointTargetVertexCell = getAbsolutePointforCell(targetVertexCell); + mxICell sourceVertexCell = (mxICell)methodExecToVertexMap.get(sourceMethodExec).getCell(); + mxICell targetVertexCell = (mxICell)methodExecToVertexMap.get(targetMethodExec).getCell(); + Point absolutPointSourceVertexCell = getAbsolutePointforCell(sourceVertexCell); + Point absolutPointTargetVertexCell = getAbsolutePointforCell(targetVertexCell); -// System.out.println("start : " + sourceVertexCell.getGeometry().getCenterX() + ", " + (sourceVertexCell.getGeometry().getY() + sourceVertexCell.getGeometry().getHeight()) + ", " + targetVertexCell.getGeometry().getCenterX() + ", " + targetVertexCell.getGeometry().getY()); -// deltaAnimation.setEdgeAnimation(new mxPoint(sourceVertexCell.getGeometry().getCenterX(), sourceVertexCell.getGeometry().getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(targetVertexCell.getGeometry().getCenterX(), targetVertexCell.getGeometry().getY())); - deltaAnimation.setExpandEdgeAnimation(new mxPoint(absolutPointSourceVertexCell.getX() + (sourceVertexCell.getGeometry().getWidth() / 2), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(absolutPointTargetVertexCell.getX() + (targetVertexCell.getGeometry().getWidth() / 2), absolutPointTargetVertexCell.getY())); - deltaAnimation.startExpandEdgeAnimation(); - targetVertexCell.setVisible(true); - Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, methodSignature, null, sourceVertexCell, targetVertexCell); - ((mxCell)edge).setStyle("exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;"); - edgeMap.put(methodSignature, new Edge(methodSignature, TypeName.Call, edge)); - } + // System.out.println("start : " + sourceVertexCell.getGeometry().getCenterX() + ", " + (sourceVertexCell.getGeometry().getY() + sourceVertexCell.getGeometry().getHeight()) + ", " + targetVertexCell.getGeometry().getCenterX() + ", " + targetVertexCell.getGeometry().getY()); + // deltaAnimation.setEdgeAnimation(new mxPoint(sourceVertexCell.getGeometry().getCenterX(), sourceVertexCell.getGeometry().getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(targetVertexCell.getGeometry().getCenterX(), targetVertexCell.getGeometry().getY())); + deltaAnimation.setExpandEdgeAnimation(new mxPoint(absolutPointSourceVertexCell.getX() + (sourceVertexCell.getGeometry().getWidth() / 2), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(absolutPointTargetVertexCell.getX() + (targetVertexCell.getGeometry().getWidth() / 2), absolutPointTargetVertexCell.getY())); + deltaAnimation.startExpandEdgeAnimation(); + targetVertexCell.setVisible(true); + Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, methodSignature, null, sourceVertexCell, targetVertexCell); + ((mxCell)edge).setStyle("exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;"); + edgeMap.put(methodSignature, new Edge(methodSignature, TypeName.Call, edge)); } + } } finally { - mxgraph.getModel().endUpdate(); + mxgraph.getModel().endUpdate(); } } - - private int countChildVertex(VertexObject vertexObject) { - int time = vertexObject.getVertexMethodExecutions().size(); - if(time == 0) { - return 1; - } - for(VertexMethodExecution vertexMethodExecution: vertexObject.getVertexMethodExecutions()) { - for(VertexObject vo: vertexMethodExecution.getLocals()) { - time += countChildVertex(vo); - } - for(VertexObject vo: vertexMethodExecution.getArguments()) { - return countChildVertex(vo); - } - } - System.out.println(vertexObject.getLabel() + ": " + time); + + private int countChildVertex(ObjectVertex vertexObject) { + int time = vertexObject.getVertexMethodExecutions().size(); + if(time == 0) { + return 1; + } + for(MethodExecutionVertex vertexMethodExecution: vertexObject.getVertexMethodExecutions()) { + for(ObjectVertex vo: vertexMethodExecution.getLocals()) { + time += countChildVertex(vo); + } + for(ObjectVertex vo: vertexMethodExecution.getArguments()) { + return countChildVertex(vo); + } + } + System.out.println(vertexObject.getLabel() + ": " + time); return time; } - + private String[] formatFieldName(String fieldName) { String fieldNames[] = fieldName.split("\\."); String names[] = new String[] {fieldNames[0], fieldNames[fieldNames.length - 1]}; @@ -1160,7 +1182,7 @@ } return names; } - + private String formatMethodSignature(String methodSignature) { // Step1 : split "(" String[] methodSignatures = methodSignature.split("\\("); @@ -1188,4 +1210,31 @@ sb.append("]"); return sb.toString(); } + + private void outputLog() { + for (Object object: mxgraph.getChildCells(mxDefaultParent)) { + System.out.println(object); + for (int i = 0; i < ((mxICell)object).getChildCount(); i++) { + System.out.println(" " + ((mxICell)object).getChildAt(i)); + } + } + System.out.println("\nObject"); + for (ObjectVertex vo: objectToVertexMap.values()) { + System.out.println(vo.getLabel()); + for (MethodExecutionVertex vme: vo.getVertexMethodExecutions()) { + System.out.println(" " + vme.getLabel()); + for (ObjectVertex vmevo: vme.getArguments()) { + System.out.println(" Argument: " + vmevo.getLabel()); + } + for (ObjectVertex vmevo: vme.getLocals()) { + System.out.println(" Local: " + vmevo.getLabel()); + } + } + } + System.out.println("\nEdge"); + for (Edge e: edgeMap.values()) { + System.out.println(e.getLabel()); + System.out.println(" " + ((mxICell)e.getCell()).getParent().getId()); + } + } } diff --git a/src/org/ntlab/deltaViewer/DeltaViewerSample.java b/src/org/ntlab/deltaViewer/DeltaViewerSample.java index 4fcf9a1..ad803b4 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewerSample.java +++ b/src/org/ntlab/deltaViewer/DeltaViewerSample.java @@ -46,8 +46,8 @@ // TraceJSON trace = new TraceJSON("traces/_worstCase.txt"); // TraceJSON trace = new TraceJSON("traces/sample1.trace"); // TraceJSON trace = new TraceJSON("traces/sampleArray.trace"); - TraceJSON trace = new TraceJSON("traces/sampleCollection.trace"); -// TraceJSON trace = new TraceJSON("traces/sampleCreate.trace"); +// TraceJSON trace = new TraceJSON("traces/sampleCollection.trace"); + TraceJSON trace = new TraceJSON("traces/sampleCreate.trace"); // TraceJSON trace = new TraceJSON("traces/sampleStatic.trace"); // Error display MagnetRON. @@ -64,8 +64,8 @@ // ExtractedStructure e = s.extract(new Reference(null, null, "worstCase.P", "worstCase.M"), tp, dac); // ExtractedStructure e = s.extract(new Reference(null, null, "sample1.D", "sample1.C"), tp, dac); // ExtractedStructure e = s.extract(new Reference(null, null, "sampleArray.D", "sampleArray.C"), tp, dac); - ExtractedStructure e = s.extract(new Reference(null, null, "sampleCollection.D", "sampleCollection.C"), tp, dac); -// ExtractedStructure e = s.extract(new Reference(null, null, "sampleCreate.D", "sampleCreate.C"), tp, dac); +// ExtractedStructure e = s.extract(new Reference(null, null, "sampleCollection.D", "sampleCollection.C"), tp, dac); + ExtractedStructure e = s.extract(new Reference(null, null, "sampleCreate.D", "sampleCreate.C"), tp, dac); // ExtractedStructure e = s.extract(new Reference(null, null, "sampleStatic.D", "sampleStatic.C"), tp, dac); // HashSet marked = trace.getMarkedMethodSignatures(1255991806833871L, 1255991808597322L); diff --git a/src/org/ntlab/deltaViewer/Edge.java b/src/org/ntlab/deltaViewer/Edge.java index 6e33dd1..bcc3c95 100644 --- a/src/org/ntlab/deltaViewer/Edge.java +++ b/src/org/ntlab/deltaViewer/Edge.java @@ -12,6 +12,7 @@ protected enum TypeName { Reference, // object reference + Create, // create object reference Call // method call } diff --git a/src/org/ntlab/deltaViewer/MethodExecutionVertex.java b/src/org/ntlab/deltaViewer/MethodExecutionVertex.java new file mode 100644 index 0000000..7d30f84 --- /dev/null +++ b/src/org/ntlab/deltaViewer/MethodExecutionVertex.java @@ -0,0 +1,40 @@ +package org.ntlab.deltaViewer; + +import java.util.ArrayList; +import java.util.List; + +/** + * Method execution vertex. + * + * @author Nitta Lab. + */ +public class MethodExecutionVertex extends Vertex { + protected List locals = new ArrayList<>(); // Return value + protected List arguments = new ArrayList<>(); + + + public MethodExecutionVertex(String label, Object cell) { + super(label, cell); + } + + public MethodExecutionVertex(String label, Object cell, double x, double y, double width, double height) { + super(label, cell, x, y, width, height); + } + + public List getLocals() { + return locals; + } + + public void setLocals(List locals) { + this.locals = locals; + } + + public List getArguments() { + return arguments; + } + + public void setArguments(List arguments) { + this.arguments = arguments; + } + +} diff --git a/src/org/ntlab/deltaViewer/ObjectVertex.java b/src/org/ntlab/deltaViewer/ObjectVertex.java new file mode 100644 index 0000000..d161d3b --- /dev/null +++ b/src/org/ntlab/deltaViewer/ObjectVertex.java @@ -0,0 +1,39 @@ +package org.ntlab.deltaViewer; + +import java.util.ArrayList; +import java.util.List; + +import com.mxgraph.model.mxICell; + +/** + * Object vertex. + * + * @author Nitta Lab. + */ +public class ObjectVertex extends Vertex { + protected List vertexMethodExecutions = new ArrayList<>(); + + public ObjectVertex(String label, Object cell) { + super(label, cell); + } + + public ObjectVertex(String label, Object cell, double initialX, double initialY) { + super(label, cell, initialX, initialY); + } + + public ObjectVertex(String label, Object cell, double x, double y, double width, double height) { + super(label, cell, x, y, width, height); + } + + public List getVertexMethodExecutions() { + return vertexMethodExecutions; + } + + public void setVertexMethodExecutions(List vertexMethodExecutions) { + this.vertexMethodExecutions = vertexMethodExecutions; + } + + public void addMethodExecution(MethodExecutionVertex vertexMethodExecution) { + this.vertexMethodExecutions.add(vertexMethodExecution); + } +} diff --git a/src/org/ntlab/deltaViewer/VertexMethodExecution.java b/src/org/ntlab/deltaViewer/VertexMethodExecution.java deleted file mode 100644 index 8f310e7..0000000 --- a/src/org/ntlab/deltaViewer/VertexMethodExecution.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.ntlab.deltaViewer; - -import java.util.ArrayList; -import java.util.List; - -/** - * Method execution vertex. - * - * @author Nitta Lab. - */ -public class VertexMethodExecution extends Vertex { - protected List locals = new ArrayList<>(); // Return value - protected List arguments = new ArrayList<>(); - - - public VertexMethodExecution(String label, Object cell) { - super(label, cell); - } - - public VertexMethodExecution(String label, Object cell, double x, double y, double width, double height) { - super(label, cell, x, y, width, height); - } - - public List getLocals() { - return locals; - } - - public void setLocals(List locals) { - this.locals = locals; - } - - public List getArguments() { - return arguments; - } - - public void setArguments(List arguments) { - this.arguments = arguments; - } - -} diff --git a/src/org/ntlab/deltaViewer/VertexObject.java b/src/org/ntlab/deltaViewer/VertexObject.java deleted file mode 100644 index 97d372d..0000000 --- a/src/org/ntlab/deltaViewer/VertexObject.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.ntlab.deltaViewer; - -import java.util.ArrayList; -import java.util.List; - -import com.mxgraph.model.mxICell; - -/** - * Object vertex. - * - * @author Nitta Lab. - */ -public class VertexObject extends Vertex { - protected List vertexMethodExecutions = new ArrayList<>(); - - public VertexObject(String label, Object cell) { - super(label, cell); - } - - public VertexObject(String label, Object cell, double initialX, double initialY) { - super(label, cell, initialX, initialY); - } - - public VertexObject(String label, Object cell, double x, double y, double width, double height) { - super(label, cell, x, y, width, height); - } - - public List getVertexMethodExecutions() { - return vertexMethodExecutions; - } - - public void setVertexMethodExecutions(List vertexMethodExecutions) { - this.vertexMethodExecutions = vertexMethodExecutions; - } - - public void addMethodExecution(VertexMethodExecution vertexMethodExecution) { - this.vertexMethodExecutions.add(vertexMethodExecution); - } -}