use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class ParserTest method testTypeParams_1.
@Test
public void testTypeParams_1() throws Exception {
XtendFunction func = function("def <T> foo(T t) {t}");
assertEquals(1, func.getTypeParameters().size());
JvmTypeParameter tp = func.getTypeParameters().get(0);
assertEquals("T", tp.getName());
assertEquals(0, tp.getConstraints().size());
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class ParserTest method testTypeParams_2.
@Test
public void testTypeParams_2() throws Exception {
XtendFunction func = function("def <T extends CharSequence> foo(T t) { t}");
assertEquals(1, func.getTypeParameters().size());
JvmTypeParameter tp = func.getTypeParameters().get(0);
assertEquals("T", tp.getName());
assertEquals(1, tp.getConstraints().size());
assertTrue(tp.getConstraints().get(0) instanceof JvmUpperBound);
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_1.
@Test
public void testTypeParameterReference_1() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("import java.lang.* class X { def <String> String foo(java.lang.String x) {x}}").getXtendTypes().get(0)).getMembers().get(0);
JvmTypeReference returnType = func.getReturnType();
JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType();
assertEquals("String", typeParamDecl.getIdentifier());
assertEquals("String", typeParamDecl.getName());
JvmTypeReference paramType = func.getParameters().get(0).getParameterType();
assertNotSame(typeParamDecl, paramType.getType());
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_0.
@Test
public void testTypeParameterReference_0() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("import java.lang.* class X { def <String> String foo(String x) {x}}").getXtendTypes().get(0)).getMembers().get(0);
JvmTypeReference returnType = func.getReturnType();
JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType();
assertEquals("String", typeParamDecl.getIdentifier());
assertEquals("String", typeParamDecl.getName());
JvmTypeReference paramType = func.getParameters().get(0).getParameterType();
assertEquals(typeParamDecl, paramType.getType());
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterShadowsType_4.
@Test
public void testTypeParameterShadowsType_4() throws Exception {
final XtendFile file = file("class B<A> { def A foo(A x) {x} def <A> A foo(A x) {x}}");
final XtendClass xtendClass = ((XtendClass) file.getXtendTypes().get(0));
XtendFunction func1 = (XtendFunction) xtendClass.getMembers().get(0);
XtendFunction func2 = (XtendFunction) xtendClass.getMembers().get(1);
JvmTypeParameter classTypeParam = (JvmTypeParameter) func1.getReturnType().getType();
assertTrue(classTypeParam.getDeclarator() instanceof JvmGenericType);
assertSame(classTypeParam, func1.getParameters().get(0).getParameterType().getType());
JvmTypeParameter funcTypeParam = (JvmTypeParameter) func2.getReturnType().getType();
assertTrue(funcTypeParam.getDeclarator() instanceof JvmOperation);
assertSame(funcTypeParam, func2.getParameters().get(0).getParameterType().getType());
}
Aggregations