Search in sources :

Example 21 with JvmGenericType

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

the class NonOverridableTypesProviderTest method testInheritMiddle_01.

@Test
public void testInheritMiddle_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import types.OuterClass");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo extends OuterClass$MiddleClass {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo() ");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendClass xtendClass = this.clazz(_builder.toString());
        final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
        this.assertTypeInScope("Foo", inferredType);
        this.assertTypeInScope("InnerMostClass", inferredType);
        this.assertNotInScope("OuterClass.MiddleClass", inferredType);
        this.assertNotInScope("MiddleClass", inferredType);
        this.assertNotInScope("OuterClass", inferredType);
        this.assertNotInScope("PrivateMiddleClass", inferredType);
        final XtendMember method = xtendClass.getMembers().get(0);
        final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
        this.assertTypeInScope("Foo", operation);
        this.assertTypeInScope("InnerMostClass", operation);
        this.assertNotInScope("OuterClass.MiddleClass", operation);
        this.assertNotInScope("MiddleClass", operation);
        this.assertNotInScope("OuterClass", operation);
        this.assertNotInScope("PrivateMiddleClass", inferredType);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 22 with JvmGenericType

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

the class NonOverridableTypesProviderTest method testInheritMiddleParam_01.

@Test
public void testInheritMiddleParam_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import types.OuterClass");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo<InnerMostClass, T> extends OuterClass$MiddleClass<String> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <InnerMostClass> foo() ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar() ");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendClass xtendClass = this.clazz(_builder.toString());
        final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
        this.assertTypeInScope("Foo", inferredType);
        this.assertTypeInScope("InnerMostClass", inferredType);
        this.assertTypeParameterInScope("T", inferredType);
        this.assertNotInScope("OuterClass.MiddleClass", inferredType);
        this.assertNotInScope("MiddleClass", inferredType);
        this.assertNotInScope("OuterClass", inferredType);
        final XtendMember method = xtendClass.getMembers().get(0);
        final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
        this.assertTypeInScope("Foo", operation);
        this.assertTypeParameterInScope("InnerMostClass", operation);
        this.assertTypeParameterInScope("T", operation);
        this.assertNotInScope("OuterClass.MiddleClass", operation);
        this.assertNotInScope("MiddleClass", operation);
        this.assertNotInScope("OuterClass", operation);
        final XtendMember method2 = xtendClass.getMembers().get(0);
        final JvmOperation operation2 = this.associations.getDirectlyInferredOperation(((XtendFunction) method2));
        this.assertTypeInScope("Foo", operation2);
        this.assertTypeInScope("InnerMostClass", operation2);
        this.assertTypeParameterInScope("T", operation2);
        this.assertNotInScope("OuterClass.MiddleClass", operation2);
        this.assertNotInScope("MiddleClass", operation2);
        this.assertNotInScope("OuterClass", operation2);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 23 with JvmGenericType

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

the class NonOverridableTypesProviderTest method testInheritOuterTypeParam.

@Test
public void testInheritOuterTypeParam() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import types.OuterClass");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo<MiddleClass, T> extends OuterClass<String> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <MiddleClass> foo() ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar()");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendClass xtendClass = this.clazz(_builder.toString());
        final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
        this.assertTypeInScope("Foo", inferredType);
        this.assertTypeInScope("MiddleClass", inferredType);
        this.assertNotInScope("MiddleClass.InnerMostClass", inferredType);
        this.assertTypeParameterInScope("T", inferredType);
        this.assertNotInScope("OuterClass", inferredType);
        final XtendMember method = xtendClass.getMembers().get(0);
        final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
        this.assertTypeInScope("Foo", operation);
        this.assertTypeParameterInScope("MiddleClass", operation);
        this.assertTypeParameterInScope("T", operation);
        this.assertNotInScope("MiddleClass.InnerMostClass", operation);
        this.assertNotInScope("OuterClass", operation);
        final XtendMember method2 = xtendClass.getMembers().get(0);
        final JvmOperation operation2 = this.associations.getDirectlyInferredOperation(((XtendFunction) method2));
        this.assertTypeInScope("Foo", operation2);
        this.assertTypeParameterInScope("MiddleClass", operation2);
        this.assertTypeParameterInScope("T", operation2);
        this.assertNotInScope("MiddleClass.InnerMostClass", operation2);
        this.assertNotInScope("OuterClass", operation2);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 24 with JvmGenericType

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

the class JvmModelTests method testInterfaceImplicitSuperType.

@Test
public void testInterfaceImplicitSuperType() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("interface Foo {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmGenericType inferred = this._iXtendJvmAssociations.getInferredType(this.interfaze(_builder.toString()));
        Assert.assertEquals(1, inferred.getSuperTypes().size());
        Assert.assertEquals("java.lang.Object", IterableExtensions.<JvmTypeReference>head(inferred.getSuperTypes()).getIdentifier());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 25 with JvmGenericType

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

the class JvmModelTests method testClassInAnnotationIsStatic.

@Test
public void testClassInAnnotationIsStatic() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotation Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("class C {}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmAnnotationType inferred = this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString()));
        JvmMember _head = IterableExtensions.<JvmMember>head(inferred.getMembers());
        final JvmGenericType c = ((JvmGenericType) _head);
        Assert.assertTrue(c.isStatic());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)155 Test (org.junit.Test)106 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)23 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)23 JvmMember (org.eclipse.xtext.common.types.JvmMember)21 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)19 JvmField (org.eclipse.xtext.common.types.JvmField)19 JvmType (org.eclipse.xtext.common.types.JvmType)13 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)11 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)11 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 Check (org.eclipse.xtext.validation.Check)9 DispatchSignature (org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature)8