Search in sources :

Example 51 with JvmTypeReference

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

the class LinkingTest method testImplicitPackageImport.

@Test
public void testImplicitPackageImport() throws Exception {
    XtendFile file = file("package java.io class Foo implements Serializable {}");
    List<JvmTypeReference> implementedInterfaces = ((XtendClass) file.getXtendTypes().get(0)).getImplements();
    assertFalse(implementedInterfaces.isEmpty());
    JvmType implementedInterface = implementedInterfaces.get(0).getType();
    assertNotNull(implementedInterface);
    assertEquals("java.io.Serializable", implementedInterface.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 52 with JvmTypeReference

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

the class LinkingTest method testTypeParameterReference_11.

@Test
public void testTypeParameterReference_11() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Z> implements Iterable<Z> { def Iterable<Z> foo() { val result = new X result }}").getXtendTypes().get(0)).getMembers().get(0);
    JvmOperation operation = associator.getDirectlyInferredOperation(func);
    JvmTypeReference returnType = operation.getReturnType();
    assertEquals("java.lang.Iterable<Z>", returnType.getIdentifier());
    LightweightTypeReference bodyType = getType(func.getExpression());
    assertEquals("X<Z>", bodyType.getIdentifier());
    LightweightTypeReference bodyReturnType = getReturnType(func.getExpression());
    assertEquals("X<Z>", bodyReturnType.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Example 53 with JvmTypeReference

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

the class LinkingTest method testTypeParameterReference_2.

@Test
public void testTypeParameterReference_2() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Y> { def foo(Y y) { 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("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 54 with JvmTypeReference

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

the class LinkingTest method testTypeParameterReference_10.

@Test
public void testTypeParameterReference_10() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Y> { def foo(Iterable<Y> iter) { for(y: iter) { return y } null }}").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 55 with JvmTypeReference

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

the class LinkingTest method testTypeParameterReference.

@Test
public void testTypeParameterReference() throws Exception {
    XtendFunction func = function("def <X> X foo(X x) {x}");
    JvmTypeReference returnType = func.getReturnType();
    JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType();
    assertEquals("X", typeParamDecl.getIdentifier());
    assertEquals("X", typeParamDecl.getName());
    JvmTypeReference paramType = func.getParameters().get(0).getParameterType();
    assertEquals(typeParamDecl, paramType.getType());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) 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