Search in sources :

Example 1 with GuardAssertion

use of org.eclipse.n4js.flowgraphs.dataflow.guards.GuardAssertion in project n4js by eclipse.

the class FlowgraphsXpectMethod method instanceofguard.

/**
 * This xpect method can evaluate the control flow container of a given {@link ControlFlowElement}.
 */
@ParameterParser(syntax = "('of' arg1=OFFSET)? (arg2=STRING)?")
@Xpect
public void instanceofguard(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion offset, String holdsName) {
    ControlFlowElement cfe = getCFE(offset);
    GuardAssertion assertion = null;
    if (holdsName != null) {
        assertion = GuardAssertion.valueOf(holdsName);
    }
    InstanceofGuardAnalyser iga = new InstanceofGuardAnalyser();
    N4JSFlowAnalyser flowAnalyzer = getFlowAnalyzer(cfe);
    flowAnalyzer.accept(iga);
    Collection<InstanceofGuard> ioGuards = null;
    if (assertion == GuardAssertion.MayHolds) {
        ioGuards = iga.getMayHoldingTypes(cfe);
    } else if (assertion == GuardAssertion.NeverHolds) {
        ioGuards = iga.getNeverHoldingTypes(cfe);
    } else {
        ioGuards = iga.getAlwaysHoldingTypes(cfe);
    }
    List<String> commonPredStrs = new LinkedList<>();
    for (InstanceofGuard ioGuard : ioGuards) {
        String symbolText = FGUtils.getSourceText(ioGuard.symbolCFE);
        String typeText = FGUtils.getSourceText(ioGuard.typeIdentifier);
        commonPredStrs.add(symbolText + "<:" + typeText);
    }
    expectation.assertEquals(commonPredStrs);
}
Also used : InstanceofGuardAnalyser(org.eclipse.n4js.flowgraphs.analysers.InstanceofGuardAnalyser) InstanceofGuard(org.eclipse.n4js.flowgraphs.dataflow.guards.InstanceofGuard) N4JSFlowAnalyser(org.eclipse.n4js.flowgraphs.N4JSFlowAnalyser) GuardAssertion(org.eclipse.n4js.flowgraphs.dataflow.guards.GuardAssertion) 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 N4JSFlowAnalyser (org.eclipse.n4js.flowgraphs.N4JSFlowAnalyser)1 InstanceofGuardAnalyser (org.eclipse.n4js.flowgraphs.analysers.InstanceofGuardAnalyser)1 GuardAssertion (org.eclipse.n4js.flowgraphs.dataflow.guards.GuardAssertion)1 InstanceofGuard (org.eclipse.n4js.flowgraphs.dataflow.guards.InstanceofGuard)1 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)1 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)1 Xpect (org.eclipse.xpect.runner.Xpect)1