Search in sources :

Example 31 with XtendClass

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

the class JavaConverterTest method testSuperCalls.

@Test
public void testSuperCalls() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.awt.TextField;");
    _builder.newLine();
    _builder.append("public class Clazz extends TextField {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Clazz() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("super();");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Clazz(String txt) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("super(txt);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public String toString() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("Object o = super.textListener;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return super.toString();");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    XtendClass clazz = this.toValidXtendClass(_builder);
    XtendMember _get = clazz.getMembers().get(0);
    Assert.assertEquals(JvmVisibility.PUBLIC, ((XtendConstructor) _get).getVisibility());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 32 with XtendClass

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

the class JavaConverterTest method testLambdaCase.

@Test
public void testLambdaCase() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.awt.event.ActionEvent;");
    _builder.newLine();
    _builder.append("import java.awt.event.ActionListener;");
    _builder.newLine();
    _builder.append("class Clazz {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("ActionListener listener = new ActionListener() {");
    _builder.newLine();
    _builder.append("\t \t");
    _builder.append("public void actionPerformed(ActionEvent arg0) {");
    _builder.newLine();
    _builder.append("\t \t\t");
    _builder.append("arg0.getID();");
    _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);
    XtendMember _get = clazz.getMembers().get(0);
    XtendField xtendMember = ((XtendField) _get);
    Assert.assertEquals("listener", xtendMember.getName());
    XExpression _initialValue = xtendMember.getInitialValue();
    Assert.assertTrue((_initialValue instanceof XClosure));
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XClosure(org.eclipse.xtext.xbase.XClosure) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 33 with XtendClass

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

the class JavaConverterTest method testArrayDimensionOnFragmentAsParameter.

@Test
public void testArrayDimensionOnFragmentAsParameter() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class Clazz {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("String sa[];");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static main(String args[]) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("int i[] = null;");
    _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 34 with XtendClass

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

the class JavaConverterTest method testRichStringSpecialCase.

@Test
public void testRichStringSpecialCase() throws Exception {
    XtendClass clazz = this.toValidXtendClass("class Z { String richTxt = \"a\" +\"\" +\"\'\" +\"s \" + \"\'\'\' no �\'foo\'.length� side-effect \'\'\'\";}");
    Assert.assertNotNull(clazz);
    XtendMember _get = clazz.getMembers().get(0);
    XtendField xtendMember = ((XtendField) _get);
    Assert.assertEquals("richTxt", xtendMember.getName());
    XExpression _initialValue = xtendMember.getInitialValue();
    Assert.assertFalse((_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 35 with XtendClass

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

the class JavaConverterTest method testArrayAccessCase.

@Test
public void testArrayAccessCase() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class Clazz {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("String foo(String... strAr) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("int i = 0;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("System.out.println(strAr[0] + \"\"); ");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("String a = (strAr[0] =\"2\");");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("strAr[1]=a;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("a=strAr[0]+strAr[1];");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return strAr[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)

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