Search in sources :

Example 86 with XtendFunction

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

the class ParserTest method testMultiCatch_02.

@Test
public void testMultiCatch_02() throws Exception {
    XtendClass clazz = clazz("class Foo { def void m() { try {} catch(extension NullPointerException | IllegalArgumentException | IllegalStateException e) {} } }");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    assertEquals(1, body.getExpressions().size());
    XTryCatchFinallyExpression tryCatch = (XTryCatchFinallyExpression) body.getExpressions().get(0);
    XCatchClause singleCatchClause = tryCatch.getCatchClauses().get(0);
    XtendFormalParameter parameter = (XtendFormalParameter) singleCatchClause.getDeclaredParam();
    assertTrue(parameter.isExtension());
    JvmSynonymTypeReference parameterType = (JvmSynonymTypeReference) parameter.getParameterType();
    assertEquals(3, parameterType.getReferences().size());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XCatchClause(org.eclipse.xtext.xbase.XCatchClause) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmSynonymTypeReference(org.eclipse.xtext.common.types.JvmSynonymTypeReference) XTryCatchFinallyExpression(org.eclipse.xtext.xbase.XTryCatchFinallyExpression) XtendFormalParameter(org.eclipse.xtend.core.xtend.XtendFormalParameter) Test(org.junit.Test)

Example 87 with XtendFunction

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

the class ParserTest method testRichString_02.

@Test
public void testRichString_02() throws Exception {
    XtendFunction function = function("def foo() ''''''");
    assertTrue(function.getExpression() instanceof RichString);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) RichString(org.eclipse.xtend.core.xtend.RichString) Test(org.junit.Test)

Example 88 with XtendFunction

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

the class ParserTest method testFunctionTypeRef_0.

@Test
public void testFunctionTypeRef_0() throws Exception {
    XtendFunction func = function("def =>Boolean foo() { [|true]}");
    XFunctionTypeRef type = (XFunctionTypeRef) func.getReturnType();
    assertNotNull(type.getReturnType());
    assertEquals(0, type.getParamTypes().size());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XFunctionTypeRef(org.eclipse.xtext.xtype.XFunctionTypeRef) Test(org.junit.Test)

Example 89 with XtendFunction

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

the class ParserTest method testRichString_01.

@Test
public void testRichString_01() throws Exception {
    XtendFunction function = function("def foo() ''' foo �'holla'� bar '''");
    final RichString richString = (RichString) function.getExpression();
    assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(1) instanceof XStringLiteral);
    assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XStringLiteral(org.eclipse.xtext.xbase.XStringLiteral) RichString(org.eclipse.xtend.core.xtend.RichString) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) Test(org.junit.Test)

Example 90 with XtendFunction

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

the class ParserTest method testFunction_3.

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

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