Search in sources :

Example 21 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class JavaConverterTest method testStaticAccessCase.

@Test
public void testStaticAccessCase() throws Exception {
    this.j2x.useRobustSyntax();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class Test2 {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("URI getURI(){");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("int i = URI.FRAGMENT_FIRST_SEPARATOR;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("if(URI.FRAGMENT_FIRST_SEPARATOR==0) return null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return URI.createURI(\"myURI\")");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static class URI {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("static int FRAGMENT_FIRST_SEPARATOR=0;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("static URI createURI(String str) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return (URI)null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    XtendClass xtendClazz = this.toValidXtendClass(_builder);
    XtendFunction xtendMember = this.method(xtendClazz, 0);
    Assert.assertEquals("getURI", xtendMember.getName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 22 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class JavaConverterTest method testOverride.

@Test
public void testOverride() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.util.Iterator;");
    _builder.newLine();
    _builder.append("public class JavaToConvert implements Statement {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Iterable statements() { return null;} ");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public String toString() { return null;} ");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void accept(JavaToConvert v){}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public <DH> Iterator<DH> doAnonymousClass() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return new Iterator<DH>() {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("public int hashCode() {return super.hashCode();}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("public boolean hasNext() { return true;}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("public DH next() { return null;}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("public void remove() {}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("};");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("interface Node {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("Iterable statements();");
    _builder.newLine();
    _builder.append("} ");
    _builder.newLine();
    _builder.append("interface Statement extends Node {");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("void accept(JavaToConvert v);");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    XtendClass xtendClazz = this.toValidXtendClass(_builder);
    EList<XtendMember> members = xtendClazz.getMembers();
    Assert.assertEquals("Simple methods count", 4, members.size());
    Assert.assertTrue(this.method(xtendClazz, 0).isOverride());
    Assert.assertTrue(this.method(xtendClazz, 1).isOverride());
    Assert.assertTrue(this.method(xtendClazz, 2).isOverride());
    Assert.assertFalse(this.method(xtendClazz, 3).isOverride());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 23 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass 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 24 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class JavaConverterTest method testNonFinalMethodParameterCase_01.

@Test
public void testNonFinalMethodParameterCase_01() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class JavaToConvert {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public boolean visit(Object node, Object node2, int[] array, int[] array2, String... varArgs) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("node = null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("node2 = null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("array[0] = null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("array2 = null");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("varArgs = null");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return true;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    XtendClass xtendClazz = this.toValidXtendClass(_builder);
    XtendFunction xtendMember = this.method(xtendClazz, 0);
    Assert.assertEquals(JvmVisibility.PUBLIC, xtendMember.getVisibility());
    Assert.assertEquals("node_finalParam_", xtendMember.getParameters().get(0).getName());
    Assert.assertEquals("node2_finalParam_", xtendMember.getParameters().get(1).getName());
    Assert.assertEquals("array", xtendMember.getParameters().get(2).getName());
    Assert.assertEquals("array2_finalParam_", xtendMember.getParameters().get(3).getName());
    Assert.assertEquals("varArgs_finalParam_", xtendMember.getParameters().get(4).getName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 25 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class JavaConverterTest method testLambdaCase2.

@Test
public void testLambdaCase2() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("import java.util.ArrayList;");
    _builder.newLine();
    _builder.append("import com.google.common.base.Function;");
    _builder.newLine();
    _builder.append("import com.google.common.collect.Iterables;");
    _builder.newLine();
    _builder.append("class Clazz {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("final int callCount[] = new int[]{0};");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("Object fun = Iterables.transform(new ArrayList<String>(), new Function<String, String>(){");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("public String apply(String param) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("callCount[0]++;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return null;");
    _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);
    XtendField xtendMember = this.field(clazz, 1);
    Assert.assertEquals("fun", xtendMember.getName());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Aggregations

XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1017 Test (org.junit.Test)988 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)249 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)229 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)169 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)129 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)104 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)101 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)74 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)73 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)63 XExpression (org.eclipse.xtext.xbase.XExpression)62 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)62 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)56 XtendField (org.eclipse.xtend.core.xtend.XtendField)37 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)36 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)35 XAssignment (org.eclipse.xtext.xbase.XAssignment)19 EObject (org.eclipse.emf.ecore.EObject)18 RichString (org.eclipse.xtend.core.xtend.RichString)17