Search in sources :

Example 26 with ParameterParser

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

Example 27 with ParameterParser

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

the class FlowgraphsXpectMethod method cfContainer.

/**
 * This xpect method can evaluate the control flow container of a given {@link ControlFlowElement}.
 */
@ParameterParser(syntax = "('of' arg1=OFFSET)?")
@Xpect
public void cfContainer(@StringExpectation IStringExpectation expectation, IEObjectCoveringRegion offset) {
    ControlFlowElement cfe = getCFE(offset);
    ControlFlowElement container = getFlowAnalyzer(cfe).getContainer(cfe);
    EObject containerContainer = container.eContainer();
    String ccString = (containerContainer != null) ? FGUtils.getClassName(containerContainer) + "::" : "";
    String containerStr = ccString + FGUtils.getClassName(container);
    expectation.assertEquals(containerStr);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 28 with ParameterParser

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

the class ScopeXpectMethod method scopeWithPosition.

/**
 * Compares scope including resource name and line number.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public // 
void scopeWithPosition(// 
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, // 
ICrossEReferenceAndEObject arg1) {
    EObject eobj = arg1.getEObject();
    IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
    for (IEObjectDescription eo : scope.getAllElements()) {
        eo.getEObjectURI();
    }
    URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(new ScopeAwareIterable(uri, true, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, true, scope));
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 29 with ParameterParser

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

the class ScopeXpectMethod method scopeWithResource.

/**
 * Compares scope including resource name but not line number.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public // 
void scopeWithResource(// 
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, // 
ICrossEReferenceAndEObject arg1) {
    EObject eobj = arg1.getEObject();
    IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
    for (IEObjectDescription eo : scope.getAllElements()) {
        eo.getEObjectURI();
    }
    URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(new ScopeAwareIterable(uri, false, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, false, scope));
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 30 with ParameterParser

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

the class SpecADocXpectMethod method specADoc.

/**
 * Checks that an element/expression produces a certain specification string. Usage:
 *
 * <pre>
 * /* X-PECT specADoc at 'location' ---
 * expected spec output
 * --- * /
 * </pre>
 *
 * The location (at) is optional.
 *
 * Note that the X-PECT comment must be written <b>before</b> the JSDoc comment of the element.
 *
 * @param arg1
 *            the location identified by the offset.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=STRING)?")
public void specADoc(@StringExpectation(caseSensitive = true) IStringExpectation expectation, IEObjectCoveringRegion arg1) {
    if (expectation == null) {
        throw new IllegalStateException("No expectation specified, add '--- expected expectation ---");
    }
    IdentifiableElement element = getIdentifiableElement(arg1);
    SpecIdentifiableElementSection src = new SpecIdentifiableElementSection(element, repoPathHolder);
    String actual = formatter.createSpecRegionString(src, Collections.emptyMap()).toString();
    expectation.assertEquals(actual);
}
Also used : IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) SpecIdentifiableElementSection(org.eclipse.n4js.jsdoc2spec.adoc.SpecIdentifiableElementSection) 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