use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testOverloadedMethods_01.
@Test
public void testOverloadedMethods_01() throws Exception {
XtendFile file = file("import java.util.List\n" + "class X {\n" + " def foo() {\n" + " var List<CharSequence> chars = null\n" + " var List<String> strings = null\n" + " var testdata.OverloadedMethods<Object> receiver = null\n" + " receiver.overloaded(chars, strings)\n" + " }\n" + "}");
XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(3);
JvmIdentifiableElement overloaded = featureCall.getFeature();
assertNotNull(overloaded);
assertFalse(overloaded.eIsProxy());
assertEquals("testdata.OverloadedMethods.overloaded(java.util.Collection,java.lang.Iterable)", overloaded.getIdentifier());
}
use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testTypeOfSuper.
@Test
public void testTypeOfSuper() throws Exception {
String classAsString = "class Foo extends java.util.ArrayList<String> {" + " def m() {\n" + " super.add(null)\n" + " }\n" + "}";
XtendClass clazz = clazz(classAsString);
XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
XExpression body = function.getExpression();
XBlockExpression block = (XBlockExpression) body;
XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0);
XFeatureCall superCall = (XFeatureCall) featureCall.getMemberCallTarget();
LightweightTypeReference type = getType(superCall);
assertEquals("java.util.ArrayList<java.lang.String>", type.getIdentifier());
}
use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testOverloadedMethods_21.
@Test
public void testOverloadedMethods_21() throws Exception {
XtendFile file = file("import java.util.Collection\n" + "class X {\n" + " def <T> foo(Collection<T> collection, Iterable<? extends T> elements) {\n" + " val t = elements.head\n" + " collection.addAll(t)\n" + " }\n" + "}");
XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(1);
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.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testStaticImports_03.
@Test
public void testStaticImports_03() throws Exception {
String fileAsText = "import static extension java.util.Collections.* class Clazz { def void method() {''.singletonList()} }";
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("java.util.Collections.singletonList(T)", identifier);
}
use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testExplicitTypeOverSugar_01.
@Test
public void testExplicitTypeOverSugar_01() throws Exception {
XtendFile file = file("import static extension org.eclipse.emf.ecore.util.EcoreUtil.*\n" + "import org.eclipse.emf.ecore.EObject\n" + "import org.eclipse.emf.common.util.URI\n" + "\n" + "class C {\n" + " def m(EObject it) {\n" + " URI::createURI(\"someString\")\n" + " }\n" + "}");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction m = (XtendFunction) c.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
JvmIdentifiableElement method = featureCall.getFeature();
assertEquals("org.eclipse.emf.common.util.URI.createURI(java.lang.String)", method.getIdentifier());
assertTrue(featureCall.isStaticWithDeclaringType());
XFeatureCall target = (XFeatureCall) featureCall.getMemberCallTarget();
assertTrue(target.isTypeLiteral());
assertEquals("org.eclipse.emf.common.util.URI", target.getFeature().getIdentifier());
}
Aggregations