use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_13.
@Test
public void testTypeParameterReference_13() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Z> implements Iterable<Z> { def <Y> Iterable<Y> foo() { val r = new X return r }}").getXtendTypes().get(0)).getMembers().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(func);
JvmTypeReference returnType = operation.getReturnType();
assertEquals("java.lang.Iterable<Y>", returnType.getIdentifier());
LightweightTypeReference bodyType = getType(func.getExpression());
assertEquals("void", bodyType.getIdentifier());
LightweightTypeReference bodyReturnType = getReturnType(func.getExpression());
assertEquals("X<Y>", bodyReturnType.getIdentifier());
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference 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.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class Bug409780Test method testConstraintsInfluenceType.
@Test
public void testConstraintsInfluenceType() throws Exception {
XtendFile file = file("class C {\n" + " def private 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<java.lang.Appendable>", type.getIdentifier());
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class Bug409780Test method testConstraintsInfluenceFeatureScope.
@Test
public void testConstraintsInfluenceFeatureScope() throws Exception {
XtendFile file = file("class C {\n" + " def private a(Iterable<CharSequence> it) {\n" + " map[ b ].map[ 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();
XMemberFeatureCall featureCall = (XMemberFeatureCall) 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.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class TypeProviderTest method testBug380063NoException.
@Test
public void testBug380063NoException() throws Exception {
XtendClass clazz = clazz("class Foo<T> { " + "def foo(java.util.List<? extends T> l) { " + " l.add(null)" + "}}");
XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
XtendParameter xtendParameter = function.getParameters().get(0);
XBlockExpression expr = (XBlockExpression) function.getExpression();
XMemberFeatureCall call = (XMemberFeatureCall) expr.getExpressions().get(0);
LightweightTypeReference type = getType(call.getMemberCallTarget());
assertEquals("List<? extends T>", type.getSimpleName());
assertEquals("List<? extends T>", xtendParameter.getParameterType().getSimpleName());
}
Aggregations