Search in sources :

Example 1 with ASTIterator

use of org.eclipse.n4js.flowgraphs.ASTIterator in project n4js by eclipse.

the class FlowgraphsXpectMethod method astOrder.

/**
 * 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 = "('of' arg2=OFFSET)?")
@Xpect
public void astOrder(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion offset) {
    EObject context = offset.getEObject();
    Iterator<ControlFlowElement> astIter = new ASTIterator(context);
    int idx = 0;
    List<String> astElements = new LinkedList<>();
    while (astIter.hasNext()) {
        ControlFlowElement cfe = astIter.next();
        String elem = idx + ": " + FGUtils.getSourceText(cfe);
        astElements.add(elem);
        idx++;
    }
    expectation.assertEquals(astElements);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ASTIterator(org.eclipse.n4js.flowgraphs.ASTIterator) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Aggregations

LinkedList (java.util.LinkedList)1 EObject (org.eclipse.emf.ecore.EObject)1 ASTIterator (org.eclipse.n4js.flowgraphs.ASTIterator)1 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)1 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)1 Xpect (org.eclipse.xpect.runner.Xpect)1