Search in sources :

Example 6 with JvmEnumerationType

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

the class JvmModelTests method testEnumIsFinal.

@Test
public void testEnumIsFinal() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("enum Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("BAR");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmEnumerationType inferred = this._iXtendJvmAssociations.getInferredEnumerationType(this.enumeration(_builder.toString()));
        Assert.assertTrue(inferred.isFinal());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) Test(org.junit.Test)

Example 7 with JvmEnumerationType

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

the class JvmModelTests method testNestedClass_01.

@Test
public void testNestedClass_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo { ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("static class Nested0 {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("interface Nested1 {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("annotation Nested2 {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("enum Nested3 {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("X");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(this.clazz(_builder.toString()));
        Assert.assertEquals(2, clazz.getMembers().size());
        JvmMember _head = IterableExtensions.<JvmMember>head(clazz.getMembers());
        Assert.assertTrue((_head instanceof JvmGenericType));
        JvmMember _head_1 = IterableExtensions.<JvmMember>head(clazz.getMembers());
        final JvmGenericType nested0 = ((JvmGenericType) _head_1);
        Assert.assertEquals("Nested0", nested0.getSimpleName());
        Assert.assertTrue(nested0.isStatic());
        Assert.assertEquals(2, nested0.getMembers().size());
        JvmMember _head_2 = IterableExtensions.<JvmMember>head(nested0.getMembers());
        Assert.assertTrue((_head_2 instanceof JvmGenericType));
        JvmMember _head_3 = IterableExtensions.<JvmMember>head(nested0.getMembers());
        final JvmGenericType nested1 = ((JvmGenericType) _head_3);
        Assert.assertEquals("Nested1", nested1.getSimpleName());
        Assert.assertTrue(nested1.isStatic());
        Assert.assertEquals(2, nested1.getMembers().size());
        JvmMember _head_4 = IterableExtensions.<JvmMember>head(nested1.getMembers());
        Assert.assertTrue((_head_4 instanceof JvmAnnotationType));
        JvmMember _head_5 = IterableExtensions.<JvmMember>head(nested1.getMembers());
        final JvmAnnotationType nested2 = ((JvmAnnotationType) _head_5);
        Assert.assertEquals("Nested2", nested2.getSimpleName());
        Assert.assertTrue(nested2.isStatic());
        Assert.assertEquals(2, nested1.getMembers().size());
        JvmMember _last = IterableExtensions.<JvmMember>last(nested1.getMembers());
        Assert.assertTrue((_last instanceof JvmEnumerationType));
        JvmMember _last_1 = IterableExtensions.<JvmMember>last(nested1.getMembers());
        final JvmEnumerationType nested3 = ((JvmEnumerationType) _last_1);
        Assert.assertEquals("Nested3", nested3.getSimpleName());
        Assert.assertTrue(nested3.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) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) Test(org.junit.Test)

Example 8 with JvmEnumerationType

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

the class XtendJvmModelInferrer method doInferTypeSceleton.

protected JvmDeclaredType doInferTypeSceleton(final XtendTypeDeclaration declaration, final IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase, XtendFile xtendFile, List<Runnable> doLater) {
    if (Strings.isEmpty(declaration.getName()))
        return null;
    if (declaration instanceof XtendAnnotationType) {
        final JvmAnnotationType annotation = typesFactory.createJvmAnnotationType();
        if (!preIndexingPhase) {
            doLater.add(new Runnable() {

                @Override
                public void run() {
                    initialize((XtendAnnotationType) declaration, annotation);
                }
            });
        }
        return annotation;
    } else if (declaration instanceof XtendClass) {
        XtendClass xtendClass = (XtendClass) declaration;
        final JvmGenericType javaType = typesFactory.createJvmGenericType();
        copyTypeParameters(xtendClass.getTypeParameters(), javaType);
        if (!preIndexingPhase) {
            doLater.add(new Runnable() {

                @Override
                public void run() {
                    initialize((XtendClass) declaration, javaType);
                }
            });
        }
        return javaType;
    } else if (declaration instanceof XtendInterface) {
        XtendInterface xtendInterface = (XtendInterface) declaration;
        final JvmGenericType javaType = typesFactory.createJvmGenericType();
        javaType.setInterface(true);
        copyTypeParameters(xtendInterface.getTypeParameters(), javaType);
        if (!preIndexingPhase) {
            doLater.add(new Runnable() {

                @Override
                public void run() {
                    initialize((XtendInterface) declaration, javaType);
                }
            });
        }
        return javaType;
    } else if (declaration instanceof XtendEnum) {
        final JvmEnumerationType javaType = typesFactory.createJvmEnumerationType();
        if (!preIndexingPhase) {
            doLater.add(new Runnable() {

                @Override
                public void run() {
                    initialize((XtendEnum) declaration, javaType);
                }
            });
        }
        return javaType;
    } else {
        return null;
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) XtendAnnotationType(org.eclipse.xtend.core.xtend.XtendAnnotationType) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendInterface(org.eclipse.xtend.core.xtend.XtendInterface) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XtendEnum(org.eclipse.xtend.core.xtend.XtendEnum) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType)

Example 9 with JvmEnumerationType

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

the class JvmModelTests method testEnumInAnnotationIsStatic.

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

Example 10 with JvmEnumerationType

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

the class JvmModelTests method testTopLevelEnumIsNotStatic.

@Test
public void testTopLevelEnumIsNotStatic() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("enum Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("BAR");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmEnumerationType inferred = this._iXtendJvmAssociations.getInferredEnumerationType(this.enumeration(_builder.toString()));
        Assert.assertFalse(inferred.isStatic());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) Test(org.junit.Test)

Aggregations

JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)14 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)6 Test (org.junit.Test)6 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 JvmType (org.eclipse.xtext.common.types.JvmType)5 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)4 JvmMember (org.eclipse.xtext.common.types.JvmMember)3 HashMap (java.util.HashMap)2 EObject (org.eclipse.emf.ecore.EObject)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 XtendEnum (org.eclipse.xtend.core.xtend.XtendEnum)2 JvmArrayType (org.eclipse.xtext.common.types.JvmArrayType)2 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)2 JvmField (org.eclipse.xtext.common.types.JvmField)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 UnresolvableFeatureException (org.eclipse.xtext.xbase.interpreter.UnresolvableFeatureException)2 Provider (com.google.inject.Provider)1