Search in sources :

Example 6 with ParameterParser

use of org.eclipse.xpect.parameter.ParameterParser in project n4js by eclipse.

the class FlowgraphsXpectMethod method allEdges.

/**
 * This xpect method can evaluate all edges of the containing function.
 */
@ParameterParser(syntax = "('from' arg1=OFFSET)?")
@Xpect
public void allEdges(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion offset) {
    ControlFlowElement cfe = null;
    if (offset != null) {
        cfe = getCFE(offset);
    }
    cfe = FGUtils.getCFContainer(cfe);
    AllNodesAndEdgesPrintVisitor anaepw = new AllNodesAndEdgesPrintVisitor(cfe);
    getFlowAnalyzer(cfe).accept(anaepw);
    List<String> pathStrings = anaepw.getAllEdgeStrings();
    expectation.assertEquals(pathStrings);
}
Also used : AllNodesAndEdgesPrintVisitor(org.eclipse.n4js.flowgraphs.analysers.AllNodesAndEdgesPrintVisitor) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 7 with ParameterParser

use of org.eclipse.xpect.parameter.ParameterParser in project n4js by eclipse.

the class FlowgraphsXpectMethod method succs.

/**
 * This xpect method can evaluate the direct successors of a code element. The successors can be limited when
 * specifying the edge type.
 * <p>
 * <b>Attention:</b> The type parameter <i>does not</i> work on self loops!
 */
@ParameterParser(syntax = "('type' arg1=STRING)? ('at' arg2=OFFSET)?")
@Xpect
public void succs(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, String type, IEObjectCoveringRegion offset) {
    ControlFlowType cfType = getControlFlowType(type);
    ControlFlowElement cfe = getCFE(offset);
    Set<ControlFlowElement> succs = getFlowAnalyzer(cfe).getSuccessorsSkipInternal(cfe);
    filterByControlFlowType(cfe, succs, cfType);
    List<String> succTexts = new LinkedList<>();
    for (ControlFlowElement succ : succs) {
        String succText = FGUtils.getSourceText(succ);
        succTexts.add(succText);
    }
    expectation.assertEquals(succTexts);
}
Also used : ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 8 with ParameterParser

use of org.eclipse.xpect.parameter.ParameterParser 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)

Example 9 with ParameterParser

use of org.eclipse.xpect.parameter.ParameterParser in project n4js by eclipse.

the class FlowgraphsXpectMethod method preds.

/**
 * This xpect method can evaluate the direct predecessors of a code element. The predecessors can be limited when
 * specifying the edge type.
 * <p>
 * <b>Attention:</b> The type parameter <i>does not</i> work on self loops!
 */
@ParameterParser(syntax = "('type' arg1=STRING)? ('at' arg2=OFFSET)?")
@Xpect
public void preds(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, String type, IEObjectCoveringRegion offset) {
    ControlFlowType cfType = getControlFlowType(type);
    ControlFlowElement cfe = getCFE(offset);
    Set<ControlFlowElement> preds = getFlowAnalyzer(cfe).getPredecessorsSkipInternal(cfe);
    filterByControlFlowType(cfe, preds, cfType);
    List<String> predTexts = new LinkedList<>();
    for (ControlFlowElement succ : preds) {
        String predText = FGUtils.getSourceText(succ);
        predTexts.add(predText);
    }
    expectation.assertEquals(predTexts);
}
Also used : ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 10 with ParameterParser

use of org.eclipse.xpect.parameter.ParameterParser in project n4js by eclipse.

the class FlowgraphsXpectMethod method commonPreds.

/**
 * This xpect method can evaluate all common predecessors of two {@link ControlFlowElement}s.
 */
@ParameterParser(syntax = "'of' arg1=OFFSET 'and' arg2=OFFSET")
@Xpect
public void commonPreds(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion a, IEObjectCoveringRegion b) {
    ControlFlowElement aCFE = getCFE(a);
    ControlFlowElement bCFE = getCFE(b);
    Set<ControlFlowElement> commonPreds = getFlowAnalyzer(aCFE).getCommonPredecessors(aCFE, bCFE);
    List<String> commonPredStrs = new LinkedList<>();
    for (ControlFlowElement commonPred : commonPreds) {
        String commonPredStr = FGUtils.getSourceText(commonPred);
        commonPredStrs.add(commonPredStr);
    }
    expectation.assertEquals(commonPredStrs);
}
Also used : ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Aggregations

ParameterParser (org.eclipse.xpect.parameter.ParameterParser)30 Xpect (org.eclipse.xpect.runner.Xpect)30 EObject (org.eclipse.emf.ecore.EObject)11 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)9 LinkedList (java.util.LinkedList)6 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)6 ConsumedIssues (org.eclipse.xpect.xtext.lib.tests.ValidationTestModuleSetup.ConsumedIssues)5 ICrossEReferenceAndEObject (org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject)5 XtextResource (org.eclipse.xtext.resource.XtextResource)5 URI (org.eclipse.emf.common.util.URI)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)4 List (java.util.List)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 N4JSResource (org.eclipse.n4js.resource.N4JSResource)3 ThisResource (org.eclipse.xpect.xtext.lib.setup.ThisResource)3 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)3 Lists (com.google.common.collect.Lists)2 Inject (com.google.inject.Inject)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2