Search in sources :

Example 71 with XtendFunction

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

the class LinkingTest method testBug345433_01.

@Test
public void testBug345433_01() throws Exception {
    String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + "	org.eclipse.xtext.Grammar grammar\n" + "	def function1() {\n" + "		grammar.containedRuleCalls.filter(e | " + "			!e.isAssigned() && !e.isEObjectRuleCall()" + "		).map(e | e.rule)\n" + "	}\n" + "	def function2() {\n" + "		newArrayList(function1().head())\n" + "	}\n" + "}";
    XtendClass clazz = clazz(classAsString);
    IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
    List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
    assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
    XtendFunction function1 = (XtendFunction) clazz.getMembers().get(1);
    JvmOperation operation1 = associator.getDirectlyInferredOperation(function1);
    assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", operation1.getReturnType().getIdentifier());
    XtendFunction function2 = (XtendFunction) clazz.getMembers().get(2);
    JvmOperation operation2 = associator.getDirectlyInferredOperation(function2);
    assertEquals("java.util.ArrayList<org.eclipse.xtext.AbstractRule>", operation2.getReturnType().getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) Issue(org.eclipse.xtext.validation.Issue) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) Test(org.junit.Test)

Example 72 with XtendFunction

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

the class ParserTest method testRichStringIF_00.

@Test
public void testRichStringIF_00() throws Exception {
    XtendFunction function = function("def foo() ''' foo �IF true� wurst �ELSEIF null==3� brot �ELSE� machine �ENDIF� bar '''");
    final RichString richString = (RichString) function.getExpression();
    assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral);
    final RichStringIf rsIf = (RichStringIf) richString.getExpressions().get(1);
    assertTrue(rsIf.getIf() instanceof XBooleanLiteral);
    assertTrue(rsIf.getThen() instanceof RichString);
    assertEquals(1, rsIf.getElseIfs().size());
    RichStringElseIf elseIf = rsIf.getElseIfs().get(0);
    assertTrue(elseIf.getIf() instanceof XBinaryOperation);
    assertTrue(elseIf.getThen() instanceof RichString);
    assertTrue(rsIf.getElse() instanceof RichString);
    assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBooleanLiteral(org.eclipse.xtext.xbase.XBooleanLiteral) RichString(org.eclipse.xtend.core.xtend.RichString) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) RichStringIf(org.eclipse.xtend.core.xtend.RichStringIf) XBinaryOperation(org.eclipse.xtext.xbase.XBinaryOperation) RichStringElseIf(org.eclipse.xtend.core.xtend.RichStringElseIf) Test(org.junit.Test)

Example 73 with XtendFunction

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

the class ParserTest method testFunction_0.

@Test
public void testFunction_0() throws Exception {
    XtendFunction func = function("def foo() {foo}");
    assertEquals("foo", func.getName());
    assertTrue(((XBlockExpression) func.getExpression()).getExpressions().get(0) instanceof XFeatureCall);
    assertEquals(0, func.getParameters().size());
    assertNull(func.getReturnType());
    assertEquals(0, func.getTypeParameters().size());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 74 with XtendFunction

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

the class ParserTest method testRichStringWithComment_01.

@Test
public void testRichStringWithComment_01() throws Exception {
    XtendFunction function = function("def foo() '''first� /* ml comment\n */ �� sl_comment \nsecond'''");
    assertTrue(function.getExpression() instanceof RichString);
    RichString richString = (RichString) function.getExpression();
    assertEquals(2, richString.getExpressions().size());
    RichStringLiteral first = (RichStringLiteral) richString.getExpressions().get(0);
    assertEquals("first", first.getValue());
    RichStringLiteral second = (RichStringLiteral) richString.getExpressions().get(1);
    assertEquals("second", second.getValue());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) RichString(org.eclipse.xtend.core.xtend.RichString) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) Test(org.junit.Test)

Example 75 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction 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)

Aggregations

XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)441 Test (org.junit.Test)374 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)248 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)198 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)182 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)116 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)101 XExpression (org.eclipse.xtext.xbase.XExpression)95 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)91 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)78 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)72 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)60 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)46 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)39 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)30 EObject (org.eclipse.emf.ecore.EObject)28 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)23 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)23 RichString (org.eclipse.xtend.core.xtend.RichString)17 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)16