Search in sources :

Example 46 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class LinkingTest method testTypeParameterReference_9.

@Test
public void testTypeParameterReference_9() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Y> { def foo(Iterable<Y> iter) { for(y: iter) { return y } }}").getXtendTypes().get(0)).getMembers().get(0);
    JvmOperation operation = associator.getDirectlyInferredOperation(func);
    JvmTypeReference returnType = operation.getReturnType();
    assertEquals("Y", returnType.getIdentifier());
    JvmTypeReference paramType = operation.getParameters().get(0).getParameterType();
    assertEquals("java.lang.Iterable<Y>", paramType.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Example 47 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class ParserTest method testBug427257.

@Test
public void testBug427257() throws Exception {
    XtendClass clazz = clazz("class C { def Iterable<=>String> m() { emptyList } }");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
    JvmParameterizedTypeReference returnType = (JvmParameterizedTypeReference) m.getReturnType();
    JvmTypeReference typeArgument = returnType.getArguments().get(0);
    assertTrue(typeArgument instanceof XFunctionTypeRef);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XFunctionTypeRef(org.eclipse.xtext.xtype.XFunctionTypeRef) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 48 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class LinkingErrorTest method testNoException_01.

@Test
public void testNoException_01() throws Exception {
    XtendFunction function = function("def noException() {\n" + // exception case is Integeri
    "	    val closure = [Integeri| return i]\n" + "	    for (x : 1..100) closure.apply(x)\n" + "	}");
    JvmTypeReference type = associations.getDirectlyInferredOperation(function).getReturnType();
    assertTrue(type.getType() instanceof JvmVoid);
    assertFalse(type.getType().eIsProxy());
    assertNoExceptions(function);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmVoid(org.eclipse.xtext.common.types.JvmVoid) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Example 49 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class LinkingTest method testTypeParameterReference_18.

@Test
public void testTypeParameterReference_18() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Z> { def foo() { new X }}").getXtendTypes().get(0)).getMembers().get(0);
    JvmOperation operation = associator.getDirectlyInferredOperation(func);
    JvmTypeReference returnType = operation.getReturnType();
    assertEquals("X<java.lang.Object>", returnType.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Example 50 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class LinkingTest method testTypeReference_withImport.

@Test
public void testTypeReference_withImport() throws Exception {
    XtendFunction func = (XtendFunction) clazz("import java.lang.* class X { def (String)=>Boolean foo() {[|true]} }").getMembers().get(0);
    XFunctionTypeRef type = (XFunctionTypeRef) func.getReturnType();
    JvmTypeReference returnType = type.getReturnType();
    assertEquals("java.lang.Boolean", returnType.getIdentifier());
    JvmTypeReference paramType = type.getParamTypes().get(0);
    assertEquals("java.lang.String", paramType.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XFunctionTypeRef(org.eclipse.xtext.xtype.XFunctionTypeRef) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)130 Test (org.junit.Test)58 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)38 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmType (org.eclipse.xtext.common.types.JvmType)28 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)23 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 XExpression (org.eclipse.xtext.xbase.XExpression)18 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 EObject (org.eclipse.emf.ecore.EObject)15 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)12 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)12 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)8