use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method testNonConstant.
@Test
public void testNonConstant() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C { ");
_builder.newLine();
_builder.append("\t");
_builder.append("public final static Class<?> REF = D.testFoo;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class D {");
_builder.newLine();
_builder.append("\t");
_builder.append("public final static Class<?> testFoo = Object");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
Resource _eResource = file.eResource();
((BatchLinkableResource) _eResource).resolveLazyCrossReferences(null);
final XtendField field = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
try {
this.interpreter.evaluate(field.getInitialValue(), field.getType());
Assert.fail("exception expected");
} catch (final Throwable _t) {
if (_t instanceof ConstantExpressionEvaluationException) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method testConstants_RecursionFails.
@Test
public void testConstants_RecursionFails() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static MyConstants.*");
_builder.newLine();
_builder.newLine();
_builder.append("class C { ");
_builder.newLine();
_builder.append("\t");
_builder.append("val someString = MY_CONST");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class MyConstants {");
_builder.newLine();
_builder.append("\t");
_builder.append("static val MY_CONST = STRING_CONSTANT");
_builder.newLine();
_builder.append("\t");
_builder.append("static val STRING_CONSTANT = MY_CONST");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final XtendField stringField = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
try {
InputOutput.<Object>println(this.interpreter.evaluate(stringField.getInitialValue(), null));
Assert.fail("Exception expected");
} catch (final Throwable _t) {
if (_t instanceof ConstantExpressionEvaluationException) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method assertEvaluatesTo.
protected void assertEvaluatesTo(final Object expectation, final Pair<String, String> left, final Pair<String, String> right, final String op) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static MyConstants.*");
_builder.newLine();
_builder.newLine();
_builder.append("class C { ");
_builder.newLine();
_builder.append("\t");
_builder.append("static val result = A ");
_builder.append(op, "\t");
_builder.append(" B");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
_builder.append("class MyConstants {");
_builder.newLine();
_builder.append("\t");
_builder.append("static val ");
String _value = left.getValue();
_builder.append(_value, "\t");
_builder.append(" A = ");
String _key = left.getKey();
_builder.append(_key, "\t");
_builder.append(" as ");
String _value_1 = left.getValue();
_builder.append(_value_1, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("static val ");
String _value_2 = right.getValue();
_builder.append(_value_2, "\t");
_builder.append(" B = ");
String _key_1 = right.getKey();
_builder.append(_key_1, "\t");
_builder.append(" as ");
String _value_3 = right.getValue();
_builder.append(_value_3, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final XtendField stringField = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
Assert.assertEquals(expectation, this.interpreter.evaluate(stringField.getInitialValue(), null));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_017.
@Test
public void testErrorModel_017() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static extension Throwables.*");
_builder.newLine();
_builder.append("import java.net.URI");
_builder.newLine();
_builder.newLine();
_builder.append("class Throwables {");
_builder.newLine();
_builder.append("\t");
_builder.append("def static <T> T propagate(()=>T proc, (Exception)=>Exception handler) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("try {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("proc.apply");
_builder.newLine();
_builder.append("\t\t");
_builder.append("} catch(Exception e) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw handler.apply(e)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class Client {");
_builder.newLine();
_builder.append("\t");
_builder.append("valuri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration client = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
XtendMember _head = IterableExtensions.<XtendMember>head(client.getMembers());
final XtendField field = ((XtendField) _head);
XExpression _initialValue = field.getInitialValue();
final XMemberFeatureCall initializer = ((XMemberFeatureCall) _initialValue);
XExpression _head_1 = IterableExtensions.<XExpression>head(initializer.getMemberCallArguments());
final XClosure closure = ((XClosure) _head_1);
final JvmFormalParameter implicit = IterableExtensions.<JvmFormalParameter>head(closure.getImplicitFormalParameters());
Assert.assertNotNull(implicit);
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(implicit);
Assert.assertNotNull(resolvedTypes.getActualType(implicit));
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_019.
@Test
public void testErrorModel_019() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package x");
_builder.newLine();
_builder.append("import bug396879.*");
_builder.newLine();
_builder.append("class Z {");
_builder.newLine();
_builder.append(" \t");
_builder.append("def addListeners(BooleanProperty prop) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val ChangeListenerBoolean> listener = [ p, oldValue, newValue | ]\t\tprop.addListener(listener)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration z = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _get = z.getMembers().get(1);
final XtendField field = ((XtendField) _get);
XExpression _initialValue = field.getInitialValue();
final XClosure closure = ((XClosure) _initialValue);
final JvmFormalParameter param = IterableExtensions.<JvmFormalParameter>head(closure.getDeclaredFormalParameters());
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(param);
Assert.assertNotNull(resolvedTypes.getActualType(param));
}
Aggregations