Search in sources :

Example 6 with XClosure

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));
}
Also used : XCastedExpression(org.eclipse.xtext.xbase.XCastedExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XClosure(org.eclipse.xtext.xbase.XClosure) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 7 with 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));
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XClosure(org.eclipse.xtext.xbase.XClosure) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 8 with 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());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XClosure(org.eclipse.xtext.xbase.XClosure) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 9 with XClosure

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());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XClosure(org.eclipse.xtext.xbase.XClosure) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 10 with XClosure

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());
}
Also used : JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XClosure(org.eclipse.xtext.xbase.XClosure) XtendFormalParameter(org.eclipse.xtend.core.xtend.XtendFormalParameter) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Aggregations

XClosure (org.eclipse.xtext.xbase.XClosure)21 Test (org.junit.Test)17 XExpression (org.eclipse.xtext.xbase.XExpression)16 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)8 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)8 XtendField (org.eclipse.xtend.core.xtend.XtendField)6 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)6 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)6 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)5 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)4 IFeatureCallArgumentSlot (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot)4 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)4 EObject (org.eclipse.emf.ecore.EObject)3 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)3 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)3 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)3 XtendFormalParameter (org.eclipse.xtend.core.xtend.XtendFormalParameter)2