Search in sources :

Example 16 with XtendClass

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

the class JavaConverterTest method testXORExpressionCase.

@Test
public void testXORExpressionCase() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class XorCase {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void doXorOperation() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("boolean b = true;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(true ^ b) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(b ^ b) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(b ^ false) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("int i = 1;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (((1 ^ 2 ^ 4) + (i ^ 2) - (3 ^ i) ^ 2) > i) {");
    _builder.newLine();
    _builder.append("\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("\t");
    _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("class XorCase {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def void doXorOperation() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("var boolean b=true ");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("if (true.xor(b)) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("return;");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("if (b.xor(b)) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("return;");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("if (b.xor(false)) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("return;");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("var int i=1 ");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("if (((1.bitwiseXor(2).bitwiseXor(4)) + (i.bitwiseXor(2)) - (3.bitwiseXor(i)).bitwiseXor(2)) > i) {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("return;");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    Assert.assertEquals(_builder_1.toString(), 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 17 with XtendClass

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

the class JavaConverterTest method testEnumCase1.

@Test
public void testEnumCase1() throws Exception {
    XtendClass enum_ = this.toValidXtendClass("public class MyClazz{\n\t \t\t\tenum MyEnum { NEW }\n\t\t\t}");
    XtendMember _get = enum_.getMembers().get(0);
    Assert.assertEquals(JvmVisibility.DEFAULT, ((XtendEnum) _get).getVisibility());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Test(org.junit.Test)

Example 18 with XtendClass

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

the class JavaConverterTest method testNumberLiteralCase.

@Test
public void testNumberLiteralCase() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class TestStringLiteral {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("long l= 0x0000000000000000L;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("double d= 2.5d;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("long l2= 0x000000000000A;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("long l3= 0x000000000000B;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("long l4= 0x000000000000c;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("long l5= 0x000000000000d;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("long l6= 0x000000000000e;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("long l7= 0x000000000000f;");
    _builder.newLine();
    _builder.append("}");
    XtendClass xtendClazz = this.toValidXtendClass(_builder);
    XtendField xtendMember = this.field(xtendClazz, 0);
    Assert.assertEquals("l", xtendMember.getName());
    XExpression _initialValue = xtendMember.getInitialValue();
    Assert.assertEquals("0x0000000000000000#L", ((XNumberLiteral) _initialValue).getValue());
    xtendMember = this.field(xtendClazz, 1);
    Assert.assertEquals("d", xtendMember.getName());
    XExpression _initialValue_1 = xtendMember.getInitialValue();
    Assert.assertEquals("2.5d", ((XNumberLiteral) _initialValue_1).getValue());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 19 with XtendClass

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

the class JavaConverterTest method testArrayPrefixMinusCase.

@Test
public void testArrayPrefixMinusCase() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class Clazz {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static main(String[] args) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("int i =3;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("int[] ints = new int[]{1,2,3,4,5};");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("System.out.print(\"2=\"+(--ints[--i]));");
    _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)

Example 20 with XtendClass

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

the class JavaConverterTest method testStaticImportCase.

@Test
public void testStaticImportCase() throws Exception {
    XtendClass xtendClazz = this.toValidXtendClass("import static java.awt.AWTEvent.*; public class Test { long o= ACTION_EVENT_MASK;}");
    XtendMember _get = xtendClazz.getMembers().get(0);
    XtendField xtendMember = ((XtendField) _get);
    Assert.assertEquals("o", xtendMember.getName());
    XExpression _initialValue = xtendMember.getInitialValue();
    XFeatureCall xFeatureCall = ((XFeatureCall) _initialValue);
    Assert.assertEquals("ACTION_EVENT_MASK", xFeatureCall.getFeature().getSimpleName());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) 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