| | package models.controlFlowModel; |
---|
| | |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.List; |
---|
| | |
---|
| | import javax.swing.event.ListDataEvent; |
---|
| | |
---|
| | import models.Edge; |
---|
| | import models.Node; |
---|
| | import models.dataFlowModel.DataFlowGraph; |
---|
| | import models.dataFlowModel.PushPullAttribute; |
---|
| | import models.dataFlowModel.PushPullValue; |
---|
| | |
---|
| | /**-------------------------------------------------------------------------------- |
---|
| | * it has Delegation of Control-Flow algorithm. |
---|
| | */ |
---|
| | public class ControlFlowDelegator { |
---|
| | |
---|
| | private ControlFlowGraph controlFlowGraph = null; |
---|
| | |
---|
| | /**-------------------------------------------------------------------------------- |
---|
| | * [ *public ] |
---|
| | /**-------------------------------------------------------------------------------- |
---|
| |
---|
| | * 1. object-nodeとmxCellを対応付ける |
---|
| | * 2. mxGraphを再構築? |
---|
| | * 3. mxGraphModelから委譲可能なmxCellのリストと |
---|
| | */ |
---|
| | public void changeControlFlowGraph() {} |
---|
| | public ControlFlowDelegator(final ControlFlowGraph controlFlowGraph) { |
---|
| | this.controlFlowGraph = controlFlowGraph; |
---|
| | } |
---|
| | |
---|
| | /**-------------------------------------------------------------------------------- |
---|
| | /************************************************************* |
---|
| | * [ *public ] |
---|
| | /************************************************************* |
---|
| | * |
---|
| | *@param callEdge |
---|
| | */ |
---|
| | public ArrayList<StatefulObjectNode> searchDelegatableNodes(final CallEdge callEdge){ |
---|
| | ArrayList<StatefulObjectNode> nodes = new ArrayList<>(); |
---|
| | public List<ObjectNode> searchDelegatableNodes(final CallEdge callEdge){ |
---|
| | List<ObjectNode> nodes = new ArrayList<>(); |
---|
| | |
---|
| | CallGraph callGraph = null; |
---|
| | if(callEdge.getSelectedOption().equals(PushPullValue.PUSH)) { |
---|
| | callGraph = controlFlowGraph.getPushCallGraph(); |
---|
| | } |
---|
| | else { |
---|
| | callGraph = controlFlowGraph.getPullCallGraph(); |
---|
| | } |
---|
| | |
---|
| | Node parentNode = callEdge.getSource(); |
---|
| | if(parentNode == null) return null; |
---|
| | // 1. adding parentNode |
---|
| | ObjectNode delegatingNode = callEdge.getSelectedOption().equals(PushPullValue.PUSH) |
---|
| | ? (ObjectNode) callEdge.getSource() |
---|
| | : (ObjectNode) callEdge.getDestination(); |
---|
| | |
---|
| | PushPullAttribute pushPullAttribute = (PushPullAttribute)callEdge.getAttribute(); |
---|
| | if( pushPullAttribute == null) return null; |
---|
| | if( !(pushPullAttribute instanceof PushPullAttribute) ) return null; |
---|
| | ObjectNode parentNode = callEdge.getSelectedOption().equals(PushPullValue.PUSH) |
---|
| | ? (ObjectNode) callEdge.getDestination() |
---|
| | : (ObjectNode) callEdge.getSource(); |
---|
| | |
---|
| | if(parentNode == null || delegatingNode == null) |
---|
| | throw new NullPointerException("parentNode is null."); |
---|
| | if( !(parentNode instanceof ObjectNode && delegatingNode instanceof ObjectNode)) |
---|
| | throw new ClassCastException("callEdge.getSource() is not ObjectNode"); |
---|
| | |
---|
| | nodes.add(parentNode); |
---|
| | |
---|
| | |
---|
| | // 2. searchinge and adding children node of parentNode |
---|
| | searchOutOfNodes(nodes, parentNode, delegatingNode, callEdge.getSelectedOption()); |
---|
| | |
---|
| | // add to nodes in PUSH |
---|
| | // if() return nodes; |
---|
| | |
---|
| | // switch objects by transfer type |
---|
| | return null; |
---|
| | return nodes; |
---|
| | } |
---|
| | |
---|
| | /************************************************************* |
---|
| | * |
---|
| | */ |
---|
| | private void searchOutOfNodes(List<ObjectNode> nodes, ObjectNode currentNode, final ObjectNode delegatingNode, final PushPullValue selectedOption){ |
---|
| | |
---|
| | switch(selectedOption) { |
---|
| | case PUSH: |
---|
| | if(currentNode.getInEdges().size() == 0) return; |
---|
| | // get child of base-node |
---|
| | for(Edge e : currentNode.getInEdges()) { |
---|
| | ObjectNode foundNode = (ObjectNode)e.getSource(); |
---|
| | |
---|
| | if(foundNode.equals(delegatingNode)) continue; |
---|
| | |
---|
| | nodes.add(foundNode); |
---|
| | searchOutOfNodes(nodes, foundNode, delegatingNode, selectedOption); |
---|
| | } |
---|
| | break; |
---|
| | |
---|
| | case PULL: |
---|
| | case PUSHorPULL: |
---|
| | if(currentNode.getOutEdges().size() == 0) return; |
---|
| | // get child of base-node |
---|
| | for(Edge e : currentNode.getOutEdges()) { |
---|
| | ObjectNode foundNode = (ObjectNode)e.getDestination(); |
---|
| | |
---|
| | if(foundNode.equals(delegatingNode)) continue; |
---|
| | |
---|
| | nodes.add(foundNode); |
---|
| | searchOutOfNodes(nodes, foundNode, delegatingNode, selectedOption); |
---|
| | } |
---|
| | break; |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |