Search in sources :

Example 1 with EObjectCoveringRegion

use of org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.EObjectCoveringRegion in project n4js by eclipse.

the class FlowgraphsXpectMethod method performBranchAnalysis.

private AllBranchPrintVisitor performBranchAnalysis(IEObjectCoveringRegion offset, String directionName, IEObjectCoveringRegion referenceOffset) {
    EObjectCoveringRegion offsetImpl = (EObjectCoveringRegion) offset;
    EObjectCoveringRegion referenceOffsetImpl = (EObjectCoveringRegion) referenceOffset;
    ControlFlowElement startCFE = getCFEWithReference(offsetImpl, referenceOffsetImpl);
    ControlFlowElement referenceCFE = getCFE(referenceOffset);
    TraverseDirection direction = getDirection(directionName);
    ControlFlowElement container = FGUtils.getCFContainer(referenceCFE);
    AllBranchPrintVisitor appw = new AllBranchPrintVisitor(container, startCFE, direction);
    getFlowAnalyzer(referenceCFE).accept(appw);
    return appw;
}
Also used : AllBranchPrintVisitor(org.eclipse.n4js.flowgraphs.analysers.AllBranchPrintVisitor) IEObjectCoveringRegion(org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.IEObjectCoveringRegion) EObjectCoveringRegion(org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.EObjectCoveringRegion) TraverseDirection(org.eclipse.n4js.flowgraphs.analysis.TraverseDirection) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 2 with EObjectCoveringRegion

use of org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.EObjectCoveringRegion in project n4js by eclipse.

the class FlowgraphsXpectMethod method path.

/**
 * This xpect method can evaluate if the tested element is a transitive predecessor of the given element.
 */
@ParameterParser(syntax = "'from' arg0=OFFSET ('to' arg1=OFFSET)? ('notTo' arg2=OFFSET)? ('via' arg3=OFFSET)? ('notVia' arg4=OFFSET)? ('pleaseNeverUseThisParameterSinceItExistsOnlyToGetAReferenceOffset' arg5=OFFSET)?")
@Xpect
public void path(IEObjectCoveringRegion fromOffset, IEObjectCoveringRegion toOffset, IEObjectCoveringRegion notToOffset, IEObjectCoveringRegion viaOffset, IEObjectCoveringRegion notViaOffset, IEObjectCoveringRegion referenceOffset) {
    EObjectCoveringRegion toOffsetImpl = (EObjectCoveringRegion) toOffset;
    EObjectCoveringRegion notToOffsetImpl = (EObjectCoveringRegion) notToOffset;
    EObjectCoveringRegion viaOffsetImpl = (EObjectCoveringRegion) viaOffset;
    EObjectCoveringRegion notViaOffsetImpl = (EObjectCoveringRegion) notViaOffset;
    EObjectCoveringRegion referenceOffsetImpl = (EObjectCoveringRegion) referenceOffset;
    ControlFlowElement fromCFE = getCFE(fromOffset);
    ControlFlowElement toCFE = getCFEWithReference(toOffsetImpl, referenceOffsetImpl);
    ControlFlowElement notToCFE = getCFEWithReference(notToOffsetImpl, referenceOffsetImpl);
    ControlFlowElement viaCFE = getCFEWithReference(viaOffsetImpl, referenceOffsetImpl);
    ControlFlowElement notViaCFE = getCFEWithReference(notViaOffsetImpl, referenceOffsetImpl);
    ControlFlowElement targetCFE = (toCFE != null) ? toCFE : notToCFE;
    boolean expectPathExists = toCFE != null;
    if (fromCFE == null) {
        fail("Element 'from' could not be found");
    }
    if (targetCFE == null) {
        fail("Element 'to' or 'notTo' could not be found or before 'from'");
    }
    boolean actualPathExists;
    if (viaCFE != null) {
        actualPathExists = getFlowAnalyzer(fromCFE).isTransitiveSuccessor(fromCFE, viaCFE, notViaCFE);
        actualPathExists &= getFlowAnalyzer(fromCFE).isTransitiveSuccessor(viaCFE, targetCFE, notViaCFE);
    } else {
        actualPathExists = getFlowAnalyzer(fromCFE).isTransitiveSuccessor(fromCFE, targetCFE, notViaCFE);
    }
    if (expectPathExists && !actualPathExists) {
        fail("Path not found");
    }
    if (!expectPathExists && actualPathExists) {
        fail("A path was found");
    }
}
Also used : IEObjectCoveringRegion(org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.IEObjectCoveringRegion) EObjectCoveringRegion(org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.EObjectCoveringRegion) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Aggregations

ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)2 EObjectCoveringRegion (org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.EObjectCoveringRegion)2 IEObjectCoveringRegion (org.eclipse.n4js.xpect.common.N4JSOffsetAdapter.IEObjectCoveringRegion)2 AllBranchPrintVisitor (org.eclipse.n4js.flowgraphs.analysers.AllBranchPrintVisitor)1 TraverseDirection (org.eclipse.n4js.flowgraphs.analysis.TraverseDirection)1 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)1 Xpect (org.eclipse.xpect.runner.Xpect)1