use of org.eclipse.xpect.runner.Xpect in project n4js by eclipse.
the class AccessModifierXpectMethod method accessModifier.
/**
* This xpect method can evaluate the accessibility of {@link TMember}s. For example, given a field of a class or a
* {@link ParameterizedPropertyAccessExpression}, the xpect methods returns their explicit or implicit declared
* accessibility such as {@code public} or {@code private}.
*/
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
@Xpect
public void accessModifier(@StringExpectation IStringExpectation expectation, IEObjectCoveringRegion offset) {
EObject context = offset.getEObject();
String actual = calculateActual(context);
expectation.assertEquals(actual);
}
use of org.eclipse.xpect.runner.Xpect in project n4js by eclipse.
the class FormatterXpectMethod method formattedLines.
/**
*/
@Xpect
@ParameterParser(syntax = "arg1=INT")
public void formattedLines(@StringExpectation(whitespaceSensitive = true) IStringExpectation exp, // arg1
int lines, XpectInvocation inv, TargetSyntaxSupport syntax, ITextRegionAccess reg, ISetupInitializer<Preferences> prefInit) {
ITextSegment region = getRegionForLines(reg, syntax.findFirstSemanticCharAfterStatement(inv), lines);
Preferences prefs = new Preferences();
// First put some defaults
prefs.put(N4JSFormatterPreferenceKeys.FORMAT_PARENTHESIS, true);
prefs.put(FormatterPreferenceKeys.lineSeparator, "\n");
// Second init from concrete tests - will override defaults.
prefInit.initialize(prefs);
IFormatter2 formatter = formatterProvider.get();
FormatterRequest request = formatterRequestProvider.get();
request.setTextRegionAccess(reg);
request.setExceptionHandler(ExceptionAcceptor.THROWING);
// needed in case a check like this will be implemented:
// org.eclipse.xtext.testing.formatter.FormatterTester.assertAllWhitespaceIsFormatted()
request.setAllowIdentityEdits(true);
request.setFormatUndefinedHiddenRegionsOnly(false);
request.addRegion(region);
request.setPreferences(prefs);
List<ITextReplacement> replacements = formatter.format(request);
String fmt = reg.getRewriter().renderToString(replacements);
ITextSegment doc = reg.regionForDocument();
int endIndex = region.getEndOffset() + (fmt.length() - doc.getLength()) - 1;
String selection = fmt.substring(region.getOffset(), endIndex);
exp.assertEquals(selection);
}
use of org.eclipse.xpect.runner.Xpect 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);
}
use of org.eclipse.xpect.runner.Xpect in project n4js by eclipse.
the class FlowgraphsXpectMethod method allBranches.
/**
* This xpect method can evaluate all branches from a given start code element. If no start code element is
* specified, the first code element of the containing function.
*/
@ParameterParser(syntax = "('from' arg1=OFFSET)? ('direction' arg2=STRING)? ('pleaseNeverUseThisParameterSinceItExistsOnlyToGetAReferenceOffset' arg3=OFFSET)?")
@Xpect
public void allBranches(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion offset, String directionName, IEObjectCoveringRegion referenceOffset) {
AllBranchPrintVisitor appw = performBranchAnalysis(offset, directionName, referenceOffset);
List<String> branchStrings = appw.getBranchStrings();
expectation.assertEquals(branchStrings);
}
use of org.eclipse.xpect.runner.Xpect 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");
}
}
Aggregations