use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class LinkingTest method testOverloadedMethods_18.
@Test
public void testOverloadedMethods_18() throws Exception {
XtendFile file = file("import java.util.Collection\n" + "class X {\n" + " def <T> foo(Collection<T> collection, Iterable<? extends T> elements) {\n" + " collection.addAll(elements.head)\n" + " }\n" + "}");
XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
JvmIdentifiableElement addAll = featureCall.getFeature();
assertNotNull(addAll);
assertFalse(addAll.eIsProxy());
assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,T[])", addAll.getIdentifier());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class LinkingTest method testStaticImports_09.
@Test
public void testStaticImports_09() throws Exception {
String fileAsText = "import static java.util.Collections.* class Clazz { def void method() {singletonList('').findFirst(String e|e!=null)} }";
XtendFile file = file(fileAsText, true);
XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) function.getExpression()).getExpressions().get(0);
String identifier = featureCall.getFeature().getIdentifier();
assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.findFirst(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", identifier);
}
use of org.eclipse.xtend.core.xtend.XtendFunction 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.xtend.core.xtend.XtendFunction 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());
}
use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class LinkingTest method testFeatureScope_3.
@Test
public void testFeatureScope_3() throws Exception {
XtendFile file = file("import java.lang.String class X { def String foo(String foo) {[String foo|foo]}}");
XtendClass xClass = ((XtendClass) file.getXtendTypes().get(0));
XtendFunction func = (XtendFunction) xClass.getMembers().get(0);
XClosure closure = (XClosure) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
XAbstractFeatureCall featureCall1 = (XAbstractFeatureCall) (((XBlockExpression) closure.getExpression()).getExpressions().get(0));
assertEquals(closure.getFormalParameters().get(0), featureCall1.getFeature());
}
Aggregations