Search in sources :

Example 11 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 12 with JvmTypeReference

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

the class LinkingTest method testTypeReference_0.

@Test
public void testTypeReference_0() throws Exception {
    XtendFunction func = function("def =>java.lang.Boolean foo() {[|true]}");
    XFunctionTypeRef type = (XFunctionTypeRef) func.getReturnType();
    JvmTypeReference returnType = type.getReturnType();
    assertEquals("java.lang.Boolean", returnType.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)

Example 13 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)

Example 14 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 15 with JvmTypeReference

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

the class ValidationBug433213Test method test_01.

@Test
public void test_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("def <T> T m2() {}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head_1 = IterableExtensions.<XExpression>head(body.getExpressions());
        final AnonymousClass anon = ((AnonymousClass) _head_1);
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(anon.getMembers());
        final XtendFunction m2 = ((XtendFunction) _head_2);
        final JvmTypeReference returnType = m2.getReturnType();
        final JvmType t = returnType.getType();
        Assert.assertNotNull("notNull", t);
        Assert.assertFalse("t.eIsProxy", t.eIsProxy());
        this.helper.assertNoErrors(file);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)194 Test (org.junit.Test)98 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)68 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)47 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmType (org.eclipse.xtext.common.types.JvmType)43 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)41 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)27 XExpression (org.eclipse.xtext.xbase.XExpression)22 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)18 EObject (org.eclipse.emf.ecore.EObject)17 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)16 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)14 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmField (org.eclipse.xtext.common.types.JvmField)12 JvmWildcardTypeReference (org.eclipse.xtext.common.types.JvmWildcardTypeReference)12