use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testBug426788.
@Test
public void testBug426788() throws Exception {
XtendFile file = file("class Bug {\n" + " def <T extends Object> void m(T t) {}\n" + " def void m(CharSequence t) {}\n" + " def void n(Iterable<String> it) {\n" + " m(it.head) \n" + " m(it.iterator.next) \n" + " m(\"\") \n" + " }\n" + "}");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction n = (XtendFunction) c.getMembers().get(2);
XBlockExpression body = (XBlockExpression) n.getExpression();
for (XExpression featureCall : body.getExpressions()) {
XFeatureCall casted = (XFeatureCall) featureCall;
JvmIdentifiableElement method = casted.getFeature();
assertEquals("Bug.m(java.lang.CharSequence)", method.getIdentifier());
}
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class Bug409780Test method testConstraintsInfluenceFeatureScope_02.
@Test
public void testConstraintsInfluenceFeatureScope_02() throws Exception {
XtendFile file = file("class C {\n" + " def private a(Iterable<CharSequence> it) {\n" + " map[ b.append('') ]\n" + " }\n" + " def private <T extends Appendable> T b(CharSequence c) {}\n" + "}");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction m = (XtendFunction) c.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
JvmIdentifiableElement method = featureCall.getFeature();
assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
assertTrue(featureCall.isStatic());
assertTrue(featureCall.isExtension());
assertFalse(featureCall.isTypeLiteral());
LightweightTypeReference type = getType(featureCall);
assertEquals("java.lang.Iterable<java.lang.Appendable>", type.getIdentifier());
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class Bug409780Test method testMissingTypeArgumentInference.
@Test
public void testMissingTypeArgumentInference() throws Exception {
XtendFile file = file("class C {\n" + " def private <T extends Appendable> Iterable<T> a(Iterable<CharSequence> it) {\n" + " map[ b ]\n" + " }\n" + " def private <T extends Appendable> T b(CharSequence c) {}\n" + "}");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction m = (XtendFunction) c.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
JvmIdentifiableElement method = featureCall.getFeature();
assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
assertTrue(featureCall.isStatic());
assertTrue(featureCall.isExtension());
assertFalse(featureCall.isTypeLiteral());
LightweightTypeReference type = getType(featureCall);
assertEquals("java.lang.Iterable<T>", type.getIdentifier());
LightweightTypeReference expectedType = getExpectedType(featureCall);
assertEquals("java.lang.Iterable<T>", expectedType.getIdentifier());
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class TypeProviderTest method doTestBug403357.
protected void doTestBug403357(String expression, String expectation) throws Exception {
XtendFile file = file("import java.util.List\n" + "class C {\n" + " def static m() {\n" + " printMe(" + expression + ")\n" + " " + expression + ".printMe\n" + " val list = " + expression + "\n" + " printMe(list)\n" + " list.printMe\n" + " }\n" + " static def void printMe(List<String> listOfStrings) {}" + "}\n");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction function = (XtendFunction) c.getMembers().get(0);
XBlockExpression body = (XBlockExpression) function.getExpression();
XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
XExpression firstArgument = featureCall.getFeatureCallArguments().get(0);
assertEquals(expectation, getType(firstArgument).getSimpleName());
XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) body.getExpressions().get(1);
XExpression target = memberFeatureCall.getMemberCallTarget();
assertEquals(expectation, getType(target).getSimpleName());
XFeatureCall deferredFeatureCall = (XFeatureCall) body.getExpressions().get(3);
XExpression deferredFirstArgument = deferredFeatureCall.getFeatureCallArguments().get(0);
assertEquals(expectation, getType(deferredFirstArgument).getSimpleName());
XMemberFeatureCall deferredMemberFeatureCall = (XMemberFeatureCall) body.getExpressions().get(4);
XExpression deferredTarget = deferredMemberFeatureCall.getMemberCallTarget();
assertEquals(expectation, getType(deferredTarget).getSimpleName());
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class TypeProviderTest method testExpectationRelevantExpressionType_01.
@Test
public void testExpectationRelevantExpressionType_01() throws Exception {
String clazzString = "import java.util.Set\n" + "import org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor\n" + "import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference\n" + "class C extends TypeParameterSubstitutor<Set<String>> {\n" + " override substitute(LightweightTypeReference original) {\n" + " original.accept(this, newHashSet)\n" + " }" + "}";
XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
XBlockExpression body = (XBlockExpression) function.getExpression();
XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
XFeatureCall newHashSet = (XFeatureCall) invocation.getActualArguments().get(1);
assertEquals("newHashSet", newHashSet.getFeature().getSimpleName());
assertEquals("Set<String>", getExpectedType(newHashSet).getSimpleName());
assertEquals("HashSet<String>", getType(newHashSet).getSimpleName());
}
Aggregations