use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class JavaConverterTest method testLambdaCase3.
@Test
public void testLambdaCase3() throws Exception {
this.j2x.useRobustSyntax();
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.util.Iterator;");
_builder.newLine();
_builder.append("class Clazz {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Iterable<String> iter = new AbstractIterable<String>() {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("public Iterator<String> internalIterator() {");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("return null;");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("};");
_builder.newLine();
_builder.append("\t\t");
_builder.append("abstract static class AbstractIterable<T> implements Iterable<T> {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("public Iterator<T> iterator() {");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("return internalIterator();");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("public abstract Iterator<T> internalIterator();");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
XtendClass clazz = this.toValidXtendClass(_builder);
Assert.assertNotNull(clazz);
XtendField xtendMember = this.field(clazz, 0);
Assert.assertEquals("iter", xtendMember.getName());
XExpression _initialValue = xtendMember.getInitialValue();
Assert.assertTrue((_initialValue instanceof XCastedExpression));
XExpression _initialValue_1 = xtendMember.getInitialValue();
XExpression _target = ((XCastedExpression) _initialValue_1).getTarget();
Assert.assertTrue((_target instanceof XClosure));
}
use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class JavaConverterTest method testLambdaCase.
@Test
public void testLambdaCase() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.awt.event.ActionEvent;");
_builder.newLine();
_builder.append("import java.awt.event.ActionListener;");
_builder.newLine();
_builder.append("class Clazz {");
_builder.newLine();
_builder.append("\t");
_builder.append("ActionListener listener = new ActionListener() {");
_builder.newLine();
_builder.append("\t \t");
_builder.append("public void actionPerformed(ActionEvent arg0) {");
_builder.newLine();
_builder.append("\t \t\t");
_builder.append("arg0.getID();");
_builder.newLine();
_builder.append("\t \t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("};");
_builder.newLine();
_builder.append("}");
XtendClass clazz = this.toValidXtendClass(_builder);
Assert.assertNotNull(clazz);
XtendMember _get = clazz.getMembers().get(0);
XtendField xtendMember = ((XtendField) _get);
Assert.assertEquals("listener", xtendMember.getName());
XExpression _initialValue = xtendMember.getInitialValue();
Assert.assertTrue((_initialValue instanceof XClosure));
}
use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class LinkingTest method testBug400807.
@Test
public void testBug400807() throws Exception {
XtendFile file = file("package testPackage\n" + "import bug400807.Bug400807\n" + "class C {\n" + " def Bug400807 m() {\n" + " [ string ]\n" + " }\n" + "}\n");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction m = (XtendFunction) c.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
XClosure lambda = (XClosure) body.getExpressions().get(0);
XBlockExpression innerBody = (XBlockExpression) lambda.getExpression();
XAbstractFeatureCall string = (XAbstractFeatureCall) innerBody.getExpressions().get(0);
assertEquals("bug400807.Bug400807Param.getString()", string.getFeature().getIdentifier());
}
use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class LinkingTest method testFeatureScope_3.
@Test
public void testFeatureScope_3() throws Exception {
XtendFile file = file("import java.lang.String class X { def String foo(String foo) {[String foo|foo]}}");
XtendClass xClass = ((XtendClass) file.getXtendTypes().get(0));
XtendFunction func = (XtendFunction) xClass.getMembers().get(0);
XClosure closure = (XClosure) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
XAbstractFeatureCall featureCall1 = (XAbstractFeatureCall) (((XBlockExpression) closure.getExpression()).getExpressions().get(0));
assertEquals(closure.getFormalParameters().get(0), featureCall1.getFeature());
}
use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.
the class ParserTest method testExtensionOnLambdaParameter_01.
@Test
public void testExtensionOnLambdaParameter_01() throws Exception {
XtendClass clazz = clazz("class Foo { val x = [ extension String a, String b | 0 ] }");
assertEquals(1, clazz.getMembers().size());
XtendField f = (XtendField) clazz.getMembers().get(0);
XClosure initializer = (XClosure) f.getInitialValue();
List<JvmFormalParameter> parameters = initializer.getDeclaredFormalParameters();
assertEquals(2, parameters.size());
XtendFormalParameter firstParameter = (XtendFormalParameter) parameters.get(0);
assertTrue(firstParameter.isExtension());
XtendFormalParameter secondParameter = (XtendFormalParameter) parameters.get(1);
assertFalse(secondParameter.isExtension());
}
Aggregations