use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method evaluatesWithException.
protected void evaluatesWithException(final String expression, final Procedure1<? super ConstantExpressionEvaluationException> exceptionAssertions) {
try {
final XtendFunction function = this.function((("def void testFoo() { " + expression) + " }"));
XExpression _expression = function.getExpression();
final XExpression expr = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
try {
this.interpreter.evaluate(expr, null);
Assert.fail("exception expected");
} catch (final Throwable _t) {
if (_t instanceof ConstantExpressionEvaluationException) {
final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException) _t;
exceptionAssertions.apply(e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method evaluatesTo.
protected void evaluatesTo(final Pair<String, String> typeAndExpression, final Procedure1<? super Object> assertions) {
try {
final String type = typeAndExpression.getKey();
final String expression = typeAndExpression.getValue();
String _elvis = null;
if (type != null) {
_elvis = type;
} else {
_elvis = "void";
}
String _plus = ("def " + _elvis);
String _plus_1 = (_plus + " testFoo() { ");
String _plus_2 = (_plus_1 + expression);
String _plus_3 = (_plus_2 + " }");
final XtendFunction function = this.function(_plus_3);
XExpression _expression = function.getExpression();
final XExpression expr = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
JvmTypeReference _xifexpression = null;
if ((type != null)) {
_xifexpression = function.getReturnType();
}
final Object value = this.interpreter.evaluate(expr, _xifexpression);
assertions.apply(value);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class AssignmentFeatureCallArgumentsTest method test_02.
@Test
public void test_02() {
final AssignmentFeatureCallArguments arguments = this.toArguments("String s", "\"\"");
Assert.assertTrue(arguments.hasUnprocessedArguments());
Assert.assertEquals(1, arguments.getArgumentCount());
final IFeatureCallArgumentSlot singleSlot = arguments.getNextUnprocessedArgumentSlot();
Assert.assertEquals("String", singleSlot.getDeclaredType().getSimpleName());
Assert.assertFalse(singleSlot.isVarArg());
Assert.assertFalse(singleSlot.isSuperfluous());
XExpression _argumentExpression = singleSlot.getArgumentExpression();
Assert.assertTrue((_argumentExpression instanceof XStringLiteral));
singleSlot.markProcessed();
Assert.assertFalse(arguments.hasUnprocessedArguments());
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class AssignmentFeatureCallArgumentsTest method test_01.
@Test
public void test_01() {
final AssignmentFeatureCallArguments arguments = this.toArguments("", "null");
Assert.assertTrue(arguments.hasUnprocessedArguments());
final IFeatureCallArgumentSlot singleSlot = arguments.getNextUnprocessedArgumentSlot();
Assert.assertNull(singleSlot.getDeclaredType());
Assert.assertFalse(singleSlot.isVarArg());
Assert.assertFalse(singleSlot.isSuperfluous());
XExpression _argumentExpression = singleSlot.getArgumentExpression();
Assert.assertTrue((_argumentExpression instanceof XNullLiteral));
singleSlot.markProcessed();
Assert.assertFalse(arguments.hasUnprocessedArguments());
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendCompiler method _toJavaStatement.
@Override
protected void _toJavaStatement(final XConstructorCall expr, ITreeAppendable b, final boolean isReferenced) {
for (XExpression arg : expr.getArguments()) {
prepareExpression(arg, b);
}
if (!isReferenced) {
b.newLine();
constructorCallToJavaExpression(expr, b);
if (expr.eContainer() instanceof AnonymousClass) {
JvmConstructor constructor = expr.getConstructor();
JvmDeclaredType declaringType = constructor.getDeclaringType();
compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, b);
}
b.append(";");
} else if (isVariableDeclarationRequired(expr, b, true)) {
Later later = new Later() {
@Override
public void exec(ITreeAppendable appendable) {
constructorCallToJavaExpression(expr, appendable);
if (expr.eContainer() instanceof AnonymousClass) {
JvmConstructor constructor = expr.getConstructor();
JvmDeclaredType declaringType = constructor.getDeclaringType();
compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, appendable);
}
}
};
declareFreshLocalVariable(expr, b, later);
}
}
Aggregations