Search in sources :

Example 1 with DummyForwardVisitor

use of org.eclipse.n4js.flowgraphs.analysers.DummyForwardVisitor in project n4js by eclipse.

the class FlowgraphsXpectMethod method allMergeBranches.

/**
 * This xpect method can evaluate all branches that are merged at the given node name.
 */
@ParameterParser(syntax = "('pleaseNeverUseThisParameterSinceItExistsOnlyToGetAReferenceOffset' arg1=OFFSET)?")
@Xpect
public void allMergeBranches(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion referenceOffset) {
    N4JSFlowAnalyserDataRecorder.setEnabled(true);
    GraphVisitor dfv = new DummyForwardVisitor();
    GraphVisitor dbv = new DummyBackwardVisitor();
    ControlFlowElement referenceCFE = getCFE(referenceOffset);
    getFlowAnalyzer(referenceCFE).accept(dfv, dbv);
    N4JSFlowAnalyserDataRecorder.setEnabled(false);
    performBranchAnalysis(referenceOffset, null, referenceOffset);
    List<String> edgeStrings = new LinkedList<>();
    int groupIdx = 0;
    List<Pair<Node, List<ControlFlowEdge>>> mergedEdges = N4JSFlowAnalyserDataRecorder.getMergedEdges();
    for (Pair<Node, List<ControlFlowEdge>> pair : mergedEdges) {
        Node startNode = pair.getKey();
        List<ControlFlowEdge> edges = pair.getValue();
        for (ControlFlowEdge edge : edges) {
            String c = edge.start == startNode ? "B" : "F";
            edgeStrings.add(c + groupIdx + ": " + edge.toString());
        }
        groupIdx++;
    }
    Collections.sort(edgeStrings);
    expectation.assertEquals(edgeStrings);
}
Also used : DummyBackwardVisitor(org.eclipse.n4js.flowgraphs.analysers.DummyBackwardVisitor) GraphVisitor(org.eclipse.n4js.flowgraphs.analysis.GraphVisitor) Node(org.eclipse.n4js.flowgraphs.model.Node) DummyForwardVisitor(org.eclipse.n4js.flowgraphs.analysers.DummyForwardVisitor) LinkedList(java.util.LinkedList) ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) LinkedList(java.util.LinkedList) List(java.util.List) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) Pair(org.eclipse.xtext.xbase.lib.Pair) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Aggregations

LinkedList (java.util.LinkedList)1 List (java.util.List)1 DummyBackwardVisitor (org.eclipse.n4js.flowgraphs.analysers.DummyBackwardVisitor)1 DummyForwardVisitor (org.eclipse.n4js.flowgraphs.analysers.DummyForwardVisitor)1 GraphVisitor (org.eclipse.n4js.flowgraphs.analysis.GraphVisitor)1 ControlFlowEdge (org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)1 Node (org.eclipse.n4js.flowgraphs.model.Node)1 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)1 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)1 Xpect (org.eclipse.xpect.runner.Xpect)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1