Search in sources :

Example 91 with XtendClass

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

the class ParserTest method testCreateExtension_00.

@Test
public void testCreateExtension_00() throws Exception {
    XtendClass clazz = clazz("class Foo { " + "  def create list: newArrayList('foo') getListWithFooAnd(String s) {" + "    list.add(s)" + "  }" + "}");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    assertNotNull(func.getCreateExtensionInfo().getCreateExpression());
    assertEquals("list", func.getCreateExtensionInfo().getName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Example 92 with XtendClass

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

the class ParserTest method testExtensionOnForLoopParam_01.

@Test
public void testExtensionOnForLoopParam_01() throws Exception {
    XtendClass clazz = clazz("class Foo { def void m() { for(extension i: 1..2) {} } }");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    assertEquals(1, body.getExpressions().size());
    XForLoopExpression forLoop = (XForLoopExpression) body.getExpressions().get(0);
    XtendFormalParameter parameter = (XtendFormalParameter) forLoop.getDeclaredParam();
    assertTrue(parameter.isExtension());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XForLoopExpression(org.eclipse.xtext.xbase.XForLoopExpression) XtendFormalParameter(org.eclipse.xtend.core.xtend.XtendFormalParameter) Test(org.junit.Test)

Example 93 with XtendClass

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

the class ParserTest method testCreateExtension_01.

@Test
public void testCreateExtension_01() throws Exception {
    XtendClass clazz = clazz("class Foo { " + "  def create foo : newArrayList('foo') getListWithFooAnd(String s) {" + "    foo.add(s)" + "  }" + "}");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    assertNotNull(func.getCreateExtensionInfo().getCreateExpression());
    assertEquals("foo", func.getCreateExtensionInfo().getName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Example 94 with XtendClass

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

the class ParserTest method testAllGrammarElementsUniqueAfterReparse.

@Test
public void testAllGrammarElementsUniqueAfterReparse() throws Exception {
    String text = "class Foo { def m() { newArrayList() } }";
    XtendClass clazz = clazz(text);
    XtextResource resource = (XtextResource) clazz.eResource();
    resource.update(text.indexOf('m'), 0, "m");
    ICompositeNode root = resource.getParseResult().getRootNode();
    assertSame(root, root.getRootNode());
    Set<EObject> grammarElements = Sets.newHashSet();
    for (INode node : root.getAsTreeIterable()) {
        if (node instanceof ICompositeNode) {
            if (node.getGrammarElement() == null) {
                fail("node without grammar element");
            }
            if (!grammarElements.add(node.getGrammarElement())) {
                fail(node.getGrammarElement().toString());
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) RichString(org.eclipse.xtend.core.xtend.RichString) Test(org.junit.Test)

Example 95 with XtendClass

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

the class ParserTest method testAllGrammarElementsUnique.

@Test
public void testAllGrammarElementsUnique() throws Exception {
    XtendClass clazz = clazz("class Foo { def m() { newArrayList() } }");
    XtextResource resource = (XtextResource) clazz.eResource();
    ICompositeNode root = resource.getParseResult().getRootNode();
    new InvariantChecker().checkInvariant(root);
    assertSame(root, root.getRootNode());
    Set<EObject> grammarElements = Sets.newHashSet();
    for (INode node : root.getAsTreeIterable()) {
        if (node instanceof ICompositeNode) {
            if (node.getGrammarElement() == null) {
                fail("node without grammar element");
            }
            if (!grammarElements.add(node.getGrammarElement())) {
                fail(node.getGrammarElement().toString());
            }
        }
    }
}
Also used : InvariantChecker(org.eclipse.xtext.nodemodel.impl.InvariantChecker) INode(org.eclipse.xtext.nodemodel.INode) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) 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