Search in sources :

Example 51 with JvmTypeParameter

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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Test(org.junit.Test)

Example 52 with JvmTypeParameter

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);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Test(org.junit.Test)

Example 53 with JvmTypeParameter

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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Test(org.junit.Test)

Example 54 with JvmTypeParameter

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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Test(org.junit.Test)

Example 55 with JvmTypeParameter

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());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Aggregations

JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)57 Test (org.junit.Test)20 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)16 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)14 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)13 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)12 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)10 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)7 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)7 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)6 List (java.util.List)5 EList (org.eclipse.emf.common.util.EList)5 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)5 EObject (org.eclipse.emf.ecore.EObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 ArrayList (java.util.ArrayList)3 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)3 AbstractMethodBuilder (org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)3