Search in sources :

Example 91 with XtendFunction

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

the class ParserTest method testBug427257.

@Test
public void testBug427257() throws Exception {
    XtendClass clazz = clazz("class C { def Iterable<=>String> m() { emptyList } }");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
    JvmParameterizedTypeReference returnType = (JvmParameterizedTypeReference) m.getReturnType();
    JvmTypeReference typeArgument = returnType.getArguments().get(0);
    assertTrue(typeArgument instanceof XFunctionTypeRef);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XFunctionTypeRef(org.eclipse.xtext.xtype.XFunctionTypeRef) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 92 with XtendFunction

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

the class ParserTest method testRichStringFOR_03.

@Test
public void testRichStringFOR_03() throws Exception {
    XtendFunction function = function("def withForLoop(String it) '''�it��val it = 1..10��FOR i: it SEPARATOR it��ENDFOR�'''");
    final RichString richString = (RichString) function.getExpression();
    assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(1) instanceof XFeatureCall);
    JvmOperation operation = associations.getDirectlyInferredOperation(function);
    assertSame(operation.getParameters().get(0), ((XAbstractFeatureCall) richString.getExpressions().get(1)).getFeature());
    assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(3) instanceof XVariableDeclaration);
    assertTrue(richString.getExpressions().get(4) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(5) instanceof RichStringForLoop);
    final RichStringForLoop rsFor = (RichStringForLoop) richString.getExpressions().get(5);
    assertTrue(rsFor.getForExpression() instanceof XFeatureCall);
    assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getForExpression()).getFeature());
    assertEquals("i", rsFor.getDeclaredParam().getName());
    assertTrue(rsFor.getSeparator() instanceof XFeatureCall);
    assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getSeparator()).getFeature());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) RichString(org.eclipse.xtend.core.xtend.RichString) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) RichStringForLoop(org.eclipse.xtend.core.xtend.RichStringForLoop) Test(org.junit.Test)

Example 93 with XtendFunction

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

the class UTF8ParserErrorTest method testInvalidIdentifier_01.

@Test
public void testInvalidIdentifier_01() throws Exception {
    XtendFunction func = function("def \\u0020invalidStart() {}");
    assertEquals("invalidStart", func.getName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) Test(org.junit.Test)

Example 94 with XtendFunction

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

the class UTF8ParserErrorTest method testIdentifiers_02.

@Test
public void testIdentifiers_02() throws Exception {
    XtendFunction func = function("def invalid\\u0020Part() {}");
    assertEquals("invalidPart", func.getName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) Test(org.junit.Test)

Example 95 with XtendFunction

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

the class UTF8ParserErrorTest method testInvalidReference_01.

@Test
public void testInvalidReference_01() throws Exception {
    XtendFunction func = function("def m() { \\u0020invalidStart }");
    XBlockExpression block = (XBlockExpression) func.getExpression();
    XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
    String featureName = featureCall.getConcreteSyntaxFeatureName();
    assertEquals("\\u0020invalidStart", featureName);
    assertTrue(featureCall.getFeature().eIsProxy());
    List<Diagnostic> errorList = func.eResource().getErrors();
    assertEquals(2, errorList.size());
    XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errorList.get(1);
    assertTrue(diagnostic.getMessage().contains("invalidStart"));
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) 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