Search in sources :

Example 76 with XtendFunction

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

the class ParserTest method testRichStringWithComment_00.

@Test
public void testRichStringWithComment_00() throws Exception {
    XtendFunction function = function("def foo() '''first��� 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 77 with XtendFunction

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

the class ParserTest method testTypeParams_3.

@Test
public void testTypeParams_3() throws Exception {
    XtendFunction func = function("def <T extends CharSequence & java.io.Serializable> foo(T t) { t}");
    assertEquals(1, func.getTypeParameters().size());
    JvmTypeParameter tp = func.getTypeParameters().get(0);
    assertEquals("T", tp.getName());
    assertEquals(2, tp.getConstraints().size());
    for (JvmTypeConstraint constraint : tp.getConstraints()) {
        assertTrue(constraint instanceof JvmUpperBound);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) Test(org.junit.Test)

Example 78 with XtendFunction

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

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

the class ParserTest method testFunction_1.

@Test
public void testFunction_1() throws Exception {
    XtendFunction func = function("def String foo() {foo}");
    assertEquals("foo", func.getName());
    assertTrue(((XBlockExpression) func.getExpression()).getExpressions().get(0) instanceof XFeatureCall);
    assertEquals(0, func.getParameters().size());
    assertNotNull(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 80 with XtendFunction

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

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