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