use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class JavaConverterTest method testRichStringCase.
@Test
public void testRichStringCase() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public class Clazz {");
_builder.newLine();
_builder.append("\t");
_builder.append("static int i = 2;");
_builder.newLine();
_builder.append("\t");
_builder.append("static String a = (i-i)+i+\"4=\"+(--i)+\"1=\"+(i++)+i;");
_builder.newLine();
_builder.append("\t");
_builder.append("static String b =\"4=\"+\"1=\";");
_builder.newLine();
_builder.append("}");
XtendClass clazz = this.toValidXtendClass(_builder);
Assert.assertNotNull(clazz);
XtendMember _get = clazz.getMembers().get(1);
XtendField xtendMember = ((XtendField) _get);
Assert.assertEquals("a", xtendMember.getName());
XExpression _initialValue = xtendMember.getInitialValue();
Assert.assertTrue((_initialValue instanceof RichString));
XtendMember _get_1 = clazz.getMembers().get(2);
XExpression _initialValue_1 = ((XtendField) _get_1).getInitialValue();
Assert.assertTrue((_initialValue_1 instanceof RichString));
Assert.assertEquals("static package String a=\'\'\'�(i - i)��i�4=�({i=i - 1})�1=�(i++)��i�\'\'\'", this.toXtendClassBodyDeclr("static String a = (i-i)+i+\"4=\"+(--i)+\"1=\"+(i++)+i;"));
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class JavaConverterTest method testTryCatchCase.
@Test
public void testTryCatchCase() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public void checkTryCatch() {");
_builder.newLine();
_builder.append("\t");
_builder.append("try {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("} catch (final Exception e) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw e;");
_builder.newLine();
_builder.append("\t");
_builder.append("} finally {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("System.out.println();");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
final String javaBody = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("class Test {");
_builder_1.append(javaBody);
_builder_1.append("}");
final XtendClass clazz = this.toValidXtendClass(_builder_1);
Assert.assertNotNull(clazz);
String body = this.toXtendClassBodyDeclr(javaBody);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("def void checkTryCatch() {");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("try {");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("} catch (Exception e) {");
_builder_2.newLine();
_builder_2.append("\t\t");
_builder_2.append("throw e");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("} finally {");
_builder_2.newLine();
_builder_2.append("\t\t");
_builder_2.append("System.out.println() ");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("}");
_builder_2.newLine();
_builder_2.append("}");
Assert.assertEquals(_builder_2.toString(), body);
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class JavaConverterTest method testThrowExpressionCase.
@Test
public void testThrowExpressionCase() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("void foo(byte[] bytes) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (true) throw new RuntimeException();");
_builder.newLine();
_builder.append("\t\t");
_builder.append("bytes[1] = (byte) 2;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
final String java = _builder.toString();
XtendClass clazz = this.toValidXtendClass(java);
Assert.assertNotNull(clazz);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def package void foo(byte[] bytes) {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("if (true) throw new RuntimeException();");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("{ val _wrVal_bytes=bytes _wrVal_bytes.set(1,2 as byte)} ");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
this.assertGeneratedXtend(_builder_1, this.toXtendCode(java));
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class JavaConverterTest method testBitwiseComplementCase.
@Test
public void testBitwiseComplementCase() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public void doBitwiseOperation() {");
_builder.newLine();
_builder.append("\t");
_builder.append("int i = 1;");
_builder.newLine();
_builder.append("\t");
_builder.append("i = ~i;");
_builder.newLine();
_builder.append("}");
final String javaBody = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("class Test {");
_builder_1.append(javaBody);
_builder_1.append("}");
final XtendClass clazz = this.toValidXtendClass(_builder_1);
Assert.assertNotNull(clazz);
String body = this.toXtendClassBodyDeclr(javaBody);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("def void doBitwiseOperation() {");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("var int i=1 ");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("i=i.bitwiseNot ");
_builder_2.newLine();
_builder_2.append("}");
Assert.assertEquals(_builder_2.toString(), body);
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class JavaConverterTest method testSwitchCase2.
@Test
public void testSwitchCase2() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public class FooSwitch {");
_builder.newLine();
_builder.append("\t");
_builder.append("private void doSwitch2() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("int i = 0;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("switch (i) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("case 1:");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("i++;");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("return;");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("case 2: {");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("return;");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("default:");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("return;");
_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);
}
Aggregations