Search in sources :

Example 26 with XtendClass

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

Example 27 with XtendClass

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);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) RichString(org.eclipse.xtend.core.xtend.RichString) Test(org.junit.Test)

Example 28 with XtendClass

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));
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) RichString(org.eclipse.xtend.core.xtend.RichString) Test(org.junit.Test)

Example 29 with XtendClass

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);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) RichString(org.eclipse.xtend.core.xtend.RichString) Test(org.junit.Test)

Example 30 with XtendClass

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);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) 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