use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testExtensionMethodCall_04.
@Test
public void testExtensionMethodCall_04() throws Exception {
XtendClass clazz = clazz("" + "abstract class MyIterable implements Iterable<String> {" + " def doSomething() {\n" + " this.filter [ s.toUpperCase != null ]\n" + " }\n" + "}");
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
final XAbstractFeatureCall call = (XAbstractFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.filter(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", call.getFeature().getIdentifier());
JvmOperation operation = associator.getDirectlyInferredOperation(func);
assertEquals("Iterable<String>", operation.getReturnType().getSimpleName());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testExtensionMethodCall_03.
@Test
public void testExtensionMethodCall_03() throws Exception {
XtendClass clazz = clazz("" + "abstract class MyIterable implements Iterable<String> {" + " def doSomething() {\n" + " filter [ s.toUpperCase != null ]\n" + " }\n" + "}");
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
final XFeatureCall call = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.filter(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", call.getFeature().getIdentifier());
assertNull(call.getInvalidFeatureIssueCode(), call.getInvalidFeatureIssueCode());
JvmOperation operation = associator.getDirectlyInferredOperation(func);
assertEquals("Iterable<String>", operation.getReturnType().getSimpleName());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_4.
@Test
public void testTypeParameterReference_4() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class X { def <Y> foo(Y y) { return y }}").getXtendTypes().get(0)).getMembers().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(func);
JvmTypeReference returnType = operation.getReturnType();
assertEquals("Y", returnType.getIdentifier());
JvmTypeReference paramType = operation.getParameters().get(0).getParameterType();
assertEquals("Y", paramType.getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_9.
@Test
public void testTypeParameterReference_9() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Y> { def foo(Iterable<Y> iter) { for(y: iter) { return y } }}").getXtendTypes().get(0)).getMembers().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(func);
JvmTypeReference returnType = operation.getReturnType();
assertEquals("Y", returnType.getIdentifier());
JvmTypeReference paramType = operation.getParameters().get(0).getParameterType();
assertEquals("java.lang.Iterable<Y>", paramType.getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class LinkingTest method testImplicitFirstArgument_05.
@Test
public void testImplicitFirstArgument_05() throws Exception {
XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + " def testExtensionMethods(CharSequence it) {\n" + " withObject\n" + " }\n" + " extension String" + " def withObject(Object obj) { null }" + "}");
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XFeatureCall fifth = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
JvmOperation fifthFeature = (JvmOperation) fifth.getFeature();
assertEquals("MyXtendClass.withObject(java.lang.Object)", fifthFeature.getIdentifier());
assertEquals(1, fifthFeature.getParameters().size());
assertNotNull(fifth.getImplicitFirstArgument());
assertEquals("it", ((XAbstractFeatureCall) fifth.getImplicitFirstArgument()).getFeature().getSimpleName());
XFeatureCall fifthReceiver = (XFeatureCall) fifth.getImplicitReceiver();
assertTrue(fifthReceiver.getFeature() instanceof JvmGenericType);
assertNull(fifth.getInvalidFeatureIssueCode(), fifth.getInvalidFeatureIssueCode());
}
Aggregations