Search in sources :

Example 61 with XtendField

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

the class JavaConverterTest method testFieldDeclarationCase.

@Test
public void testFieldDeclarationCase() throws Exception {
    XtendClass xtendClazz = this.toValidXtendClass("public class JavaToConvert { private String str = \"myString\";}");
    EList<XtendMember> members = xtendClazz.getMembers();
    Assert.assertEquals("Simple fields count", 1, members.size());
    XtendMember _get = members.get(0);
    XtendField xtendMember = ((XtendField) _get);
    Assert.assertEquals(JvmVisibility.PRIVATE, xtendMember.getVisibility());
    Assert.assertEquals("String", xtendMember.getType().getSimpleName());
    Assert.assertEquals("str", xtendMember.getName());
    XExpression _initialValue = xtendMember.getInitialValue();
    Assert.assertEquals("myString", ((XStringLiteral) _initialValue).getValue());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 62 with XtendField

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

the class JavaConverterTest method checkVisibility.

private void checkVisibility(final XtendClass xtendClazz) {
    Assert.assertEquals("Simple fields count", 4, xtendClazz.getMembers().size());
    XtendField xtendMember = this.field(xtendClazz, 0);
    Assert.assertEquals("priv", xtendMember.getName());
    Assert.assertEquals("field PRIVATE visibility", JvmVisibility.PRIVATE, xtendMember.getVisibility());
    Assert.assertEquals("String", xtendMember.getType().getSimpleName());
    xtendMember = this.field(xtendClazz, 1);
    Assert.assertEquals("pub", xtendMember.getName());
    Assert.assertEquals("field public visibility", JvmVisibility.PUBLIC, xtendMember.getVisibility());
    Assert.assertEquals("String", xtendMember.getType().getSimpleName());
    xtendMember = this.field(xtendClazz, 2);
    Assert.assertEquals("prot", xtendMember.getName());
    Assert.assertEquals("field PROTECTED visibility", JvmVisibility.PROTECTED, xtendMember.getVisibility());
    Assert.assertEquals("String", xtendMember.getType().getSimpleName());
    xtendMember = this.field(xtendClazz, 3);
    Assert.assertEquals("def", xtendMember.getName());
    Assert.assertEquals("field DEFAULT visibility", JvmVisibility.DEFAULT, xtendMember.getVisibility());
    Assert.assertEquals("String", xtendMember.getType().getSimpleName());
}
Also used : XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 63 with XtendField

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

the class JavaConverterTest method testStringLiteralCase.

@Test
public void testStringLiteralCase() throws Exception {
    XtendClass xtendClazz = this.toValidXtendClass("class TestStringLiteral { \n\t\t\t\tString withLineWrap=\"string with wrap\\n\";\n\t\t\t\tString str2 = new String(\"\\1\\2\\3\");\n\t\t\t}");
    XtendField xtendMember = this.field(xtendClazz, 0);
    Assert.assertEquals("withLineWrap", xtendMember.getName());
    XExpression _initialValue = xtendMember.getInitialValue();
    Assert.assertEquals("string with wrap\n", ((XStringLiteral) _initialValue).getValue());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 64 with XtendField

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

the class JavaConverterTest method testRichStringSpecialCase3.

@Test
public void testRichStringSpecialCase3() throws Exception {
    XtendClass clazz = this.toValidXtendClass("class Z {String richTxt = \"x(p1)} def dispatch x(int s) {\'int\'} def dispatch x(boolean s)\"+\" {\'boolean\'} def dispatch x(double s) {\'double\'\";}");
    Assert.assertNotNull(clazz);
    XtendMember _get = clazz.getMembers().get(0);
    XtendField xtendMember = ((XtendField) _get);
    Assert.assertEquals("richTxt", xtendMember.getName());
    XExpression _initialValue = xtendMember.getInitialValue();
    Assert.assertTrue((_initialValue instanceof RichString));
}
Also used : RichString(org.eclipse.xtend.core.xtend.RichString) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 65 with XtendField

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

the class JavaConverterTest method testNumberLiteralCase2.

@Test
public void testNumberLiteralCase2() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class TestStringLiteral {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("long l= 0x598df91c;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("double d = 0x43p-43;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("float f = 0x43p-43f;");
    _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("0x598df91c", ((XNumberLiteral) _initialValue).getValue());
    xtendMember = this.field(xtendClazz, 1);
    Assert.assertEquals("d", xtendMember.getName());
    XExpression _initialValue_1 = xtendMember.getInitialValue();
    Assert.assertEquals("7.617018127348274E-12", ((XNumberLiteral) _initialValue_1).getValue());
    xtendMember = this.field(xtendClazz, 2);
    Assert.assertEquals("f", xtendMember.getName());
    XExpression _initialValue_2 = xtendMember.getInitialValue();
    Assert.assertEquals("7.617018E-12f", ((XNumberLiteral) _initialValue_2).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)

Aggregations

XtendField (org.eclipse.xtend.core.xtend.XtendField)71 Test (org.junit.Test)50 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)38 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)33 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)29 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)23 XExpression (org.eclipse.xtext.xbase.XExpression)23 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)14 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)12 EObject (org.eclipse.emf.ecore.EObject)8 RichString (org.eclipse.xtend.core.xtend.RichString)7 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)6 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)6 XClosure (org.eclipse.xtext.xbase.XClosure)6 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)5 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)5 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)4 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)4 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)4 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3