Search in sources :

Example 21 with XClosure

use of org.eclipse.xtext.xbase.XClosure in project xtext-xtend by eclipse.

the class LinkingTest method testBug345433_02.

@Test
public void testBug345433_02() 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(e0 | " + "			!e0.isAssigned() && !e0.isEObjectRuleCall()" + "		).map(e1 | e1.rule)\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 function = (XtendFunction) clazz.getMembers().get(1);
    XExpression body = function.getExpression();
    LightweightTypeReference bodyType = getType(body);
    assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", bodyType.getIdentifier());
    XBlockExpression block = (XBlockExpression) body;
    XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0);
    XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0);
    JvmFormalParameter e1 = closure.getFormalParameters().get(0);
    assertEquals("e1", e1.getSimpleName());
    assertEquals("org.eclipse.xtext.RuleCall", getType(e1).getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) Issue(org.eclipse.xtext.validation.Issue) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XClosure(org.eclipse.xtext.xbase.XClosure) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Aggregations

XClosure (org.eclipse.xtext.xbase.XClosure)21 Test (org.junit.Test)17 XExpression (org.eclipse.xtext.xbase.XExpression)16 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)8 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)8 XtendField (org.eclipse.xtend.core.xtend.XtendField)6 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)6 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)6 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)5 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)4 IFeatureCallArgumentSlot (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot)4 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)4 EObject (org.eclipse.emf.ecore.EObject)3 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)3 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)3 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)3 XtendFormalParameter (org.eclipse.xtend.core.xtend.XtendFormalParameter)2