Search in sources :

Example 31 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation 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 32 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation 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 33 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation 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 34 with JvmOperation

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

the class JvmModelTests method testEnumArtificialMethods.

@Test
public void testEnumArtificialMethods() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package bar");
        _builder.newLine();
        _builder.newLine();
        _builder.append("enum Foo {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final EList<JvmMember> inferred = this._iXtendJvmAssociations.getInferredEnumerationType(this.enumeration(_builder.toString())).getMembers();
        Assert.assertEquals(2, inferred.size());
        JvmMember _get = inferred.get(0);
        final JvmOperation values = ((JvmOperation) _get);
        Assert.assertEquals("bar.Foo.values()", values.getIdentifier());
        Assert.assertTrue(values.isStatic());
        Assert.assertEquals(JvmVisibility.PUBLIC, values.getVisibility());
        JvmMember _get_1 = inferred.get(1);
        final JvmOperation valueOf = ((JvmOperation) _get_1);
        Assert.assertEquals("bar.Foo.valueOf(java.lang.String)", valueOf.getIdentifier());
        Assert.assertTrue(valueOf.isStatic());
        Assert.assertEquals(JvmVisibility.PUBLIC, valueOf.getVisibility());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Example 35 with JvmOperation

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

the class JvmModelTests method testEmptyListAsAnnotationValueDefault.

@Test
public void testEmptyListAsAnnotationValueDefault() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotation Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("String[] bar = #[]");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString())).getMembers());
        final JvmOperation inferred = ((JvmOperation) _head);
        Assert.assertEquals("java.lang.String[]", inferred.getReturnType().getIdentifier());
        JvmAnnotationValue _defaultValue = inferred.getDefaultValue();
        Assert.assertTrue((_defaultValue instanceof JvmCustomAnnotationValue));
        JvmAnnotationValue _defaultValue_1 = inferred.getDefaultValue();
        EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _defaultValue_1).getValues());
        Assert.assertTrue((_head_1 instanceof XListLiteral));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmCustomAnnotationValue(org.eclipse.xtext.common.types.JvmCustomAnnotationValue) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) XListLiteral(org.eclipse.xtext.xbase.XListLiteral) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue) Test(org.junit.Test)

Aggregations

JvmOperation (org.eclipse.xtext.common.types.JvmOperation)202 Test (org.junit.Test)127 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)101 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)73 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)38 EObject (org.eclipse.emf.ecore.EObject)30 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)26 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)22 XExpression (org.eclipse.xtext.xbase.XExpression)20 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)20 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)20 JvmField (org.eclipse.xtext.common.types.JvmField)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)15 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)15 JvmMember (org.eclipse.xtext.common.types.JvmMember)15 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10