From d76b37c334914c65d9bfc8fd7f3737bd113a4fbe Mon Sep 17 00:00:00 2001 From: Huell Date: Wed, 20 Nov 2024 00:43:32 +0100 Subject: [PATCH 1/2] Feat: Changing control flow naming to tilde --- .../converter/DataFlowDiagramConverter.java | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/bundles/org.dataflowanalysis.converter/src/org/dataflowanalysis/converter/DataFlowDiagramConverter.java b/bundles/org.dataflowanalysis.converter/src/org/dataflowanalysis/converter/DataFlowDiagramConverter.java index c06887a..8023807 100644 --- a/bundles/org.dataflowanalysis.converter/src/org/dataflowanalysis/converter/DataFlowDiagramConverter.java +++ b/bundles/org.dataflowanalysis.converter/src/org/dataflowanalysis/converter/DataFlowDiagramConverter.java @@ -39,6 +39,7 @@ public class DataFlowDiagramConverter extends Converter { private final Logger logger = Logger.getLogger(DataFlowDiagramConverter.class); protected final static String DELIMITER_PIN_NAME = "|"; protected final static String DELIMITER_MULTI_PIN = ","; + private final static String CONTROL_FLOW_NAME = "~"; private BehaviorConverter behaviorConverter; @@ -263,22 +264,50 @@ private void createNodes(DataFlowDiagram dataFlowDiagram, List children, } private void createFlows(DataFlowDiagram dataFlowDiagram, List children) { + var controlFlowNameMap = createControlFlowNameMap(dataFlowDiagram); for (Flow flow : dataFlowDiagram.getFlows()) { - fillPinToFlowNamesMap(inputPinToFlowNamesMap,flow); - children.add(createFlow(flow)); + fillPinToFlowNamesMap(inputPinToFlowNamesMap,flow, controlFlowNameMap); + children.add(createFlow(flow, controlFlowNameMap)); } } + + private HashMap createControlFlowNameMap(DataFlowDiagram dataFlowDiagram) { + var controlFlowNameMap = new HashMap(); + dataFlowDiagram.getNodes().forEach(node -> { + var controlFlows = dataFlowDiagram.getFlows().stream() + .filter(flow -> flow.getDestinationNode().equals(node)) + .filter(flow -> flow.getEntityName().equals("")).toList(); + + String controlFlowName = "" + CONTROL_FLOW_NAME; + for (var flow : controlFlows) { + controlFlowNameMap.put(flow, controlFlowName); + controlFlowName += CONTROL_FLOW_NAME; + } + }); + return controlFlowNameMap; + } - private Child createFlow(Flow flow) { + private Child createFlow(Flow flow, HashMap controlFlowNameMap) { String id = flow.getId(); String type = "edge:arrow"; String sourceId = flow.getSourcePin() .getId(); String targetId = flow.getDestinationPin() - .getId(); - String text = flow.getEntityName(); + .getId(); + String text = controlFlowNameMap.getOrDefault(flow, flow.getEntityName()); return new Child(text, null, null, id, type, sourceId, targetId, null, new ArrayList<>()); } + + private void fillPinToFlowNamesMap(Map> map,Flow flow, HashMap controlFlowNameMap) { + if (map.containsKey(flow.getDestinationPin())) { + map.get(flow.getDestinationPin()) + .add(controlFlowNameMap.getOrDefault(flow, flow.getEntityName())); + } else { + List flowNames = new ArrayList<>(); + flowNames.add(controlFlowNameMap.getOrDefault(flow, flow.getEntityName())); + map.put(flow.getDestinationPin(), flowNames); + } + } private Map> mapping(Node node) { Map> mapPinToAssignments = new HashMap<>(); @@ -344,15 +373,5 @@ private String getStringFromInputPins (List inputPins) { return String.join(DELIMITER_MULTI_PIN, pinNamesAsString); } - private void fillPinToFlowNamesMap(Map> map,Flow flow) { - if (map.containsKey(flow.getDestinationPin())) { - map.get(flow.getDestinationPin()) - .add(flow.getEntityName()); - } else { - List flowNames = new ArrayList<>(); - flowNames.add(flow.getEntityName()); - map.put(flow.getDestinationPin(), flowNames); - } - } } From 65eb0017da2214dc9e074953e52f9e00e46892c0 Mon Sep 17 00:00:00 2001 From: Huell Date: Tue, 3 Dec 2024 14:35:50 +0100 Subject: [PATCH 2/2] Refactor: Remove unnecessary String conc --- .../dataflowanalysis/converter/DataFlowDiagramConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.dataflowanalysis.converter/src/org/dataflowanalysis/converter/DataFlowDiagramConverter.java b/bundles/org.dataflowanalysis.converter/src/org/dataflowanalysis/converter/DataFlowDiagramConverter.java index 8023807..5062984 100644 --- a/bundles/org.dataflowanalysis.converter/src/org/dataflowanalysis/converter/DataFlowDiagramConverter.java +++ b/bundles/org.dataflowanalysis.converter/src/org/dataflowanalysis/converter/DataFlowDiagramConverter.java @@ -278,7 +278,7 @@ private HashMap createControlFlowNameMap(DataFlowDiagram dataFlowD .filter(flow -> flow.getDestinationNode().equals(node)) .filter(flow -> flow.getEntityName().equals("")).toList(); - String controlFlowName = "" + CONTROL_FLOW_NAME; + String controlFlowName = CONTROL_FLOW_NAME; for (var flow : controlFlows) { controlFlowNameMap.put(flow, controlFlowName); controlFlowName += CONTROL_FLOW_NAME;