use of org.eclipse.xtext.common.types.JvmOperation 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());
}
use of org.eclipse.xtext.common.types.JvmOperation 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());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_18.
@Test
public void testTypeParameterReference_18() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Z> { def foo() { new X }}").getXtendTypes().get(0)).getMembers().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(func);
JvmTypeReference returnType = operation.getReturnType();
assertEquals("X<java.lang.Object>", returnType.getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testImplicitFirstArgument_03.
@Test
public void testImplicitFirstArgument_03() throws Exception {
XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + " def testExtensionMethods(CharSequence it) {\n" + " toLowerCase\n" + " }\n" + " extension String" + "}");
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XFeatureCall third = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
JvmOperation thirdFeature = (JvmOperation) third.getFeature();
assertEquals("java.lang.String.toLowerCase()", thirdFeature.getIdentifier());
assertNull(third.getImplicitFirstArgument());
XMemberFeatureCall thirdReceiver = (XMemberFeatureCall) third.getImplicitReceiver();
assertTrue(thirdReceiver.getFeature() instanceof JvmField);
assertNull(third.getInvalidFeatureIssueCode(), third.getInvalidFeatureIssueCode());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_11.
@Test
public void testTypeParameterReference_11() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Z> implements Iterable<Z> { def Iterable<Z> foo() { val result = new X result }}").getXtendTypes().get(0)).getMembers().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(func);
JvmTypeReference returnType = operation.getReturnType();
assertEquals("java.lang.Iterable<Z>", returnType.getIdentifier());
LightweightTypeReference bodyType = getType(func.getExpression());
assertEquals("X<Z>", bodyType.getIdentifier());
LightweightTypeReference bodyReturnType = getReturnType(func.getExpression());
assertEquals("X<Z>", bodyReturnType.getIdentifier());
}
Aggregations