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);
}
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);
}
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));
}
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));
}
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);
}
Aggregations