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());
}
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());
}
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));
}
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());
}
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());
}
Aggregations