Search in sources :

Example 31 with JvmDeclaredType

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

the class XtendCompilerErrorHandlingTest method assertCompilesTo.

public void assertCompilesTo(final CharSequence input, final CharSequence expected, final boolean shouldBeSyntacticallyValid) {
    try {
        final XtendFile file = this.file(input.toString(), false, shouldBeSyntacticallyValid);
        final Resource resource = file.eResource();
        try {
            this.issueProviderFactory.attachData(resource);
            final JvmDeclaredType inferredType = IterableExtensions.<JvmDeclaredType>head(Iterables.<JvmDeclaredType>filter(resource.getContents(), JvmDeclaredType.class));
            CharSequence javaCode = this.generator.generateType(inferredType, this.generatorConfigProvider.get(inferredType));
            javaCode = this.postProcessor.postProcess(null, javaCode);
            Assert.assertEquals(expected.toString(), javaCode.toString());
        } finally {
            this.issueProviderFactory.detachData(resource);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) Resource(org.eclipse.emf.ecore.resource.Resource) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 32 with JvmDeclaredType

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

the class XtendValidationTest method testSyntheticallyUsedField.

@Test
public void testSyntheticallyUsedField() throws Exception {
    XtendClass clazz = clazz("class X { String foo }");
    JvmDeclaredType jvmType = (JvmDeclaredType) clazz.eResource().getContents().get(1);
    EObject eObject = jvmType.getMembers().get(1);
    readAndWriteTracking.markReadAccess(eObject);
    helper.assertNoIssues(clazz.eContainer());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) Test(org.junit.Test)

Example 33 with JvmDeclaredType

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

the class XtendValidationTest method testSyntheticallyUsedFunction.

@Test
public void testSyntheticallyUsedFunction() throws Exception {
    XtendClass clazz = clazz("class X { def private String foo() {} def bar(){}}");
    JvmDeclaredType jvmType = (JvmDeclaredType) clazz.eResource().getContents().get(1);
    EObject eObject = jvmType.getMembers().get(1);
    readAndWriteTracking.markReadAccess(eObject);
    helper.assertNoIssues(clazz.eContainer());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) Test(org.junit.Test)

Example 34 with JvmDeclaredType

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

the class AbstractXtendCompilerTest method doAssertCompilesTo.

protected XtendFile doAssertCompilesTo(final CharSequence input, final CharSequence expected, final GeneratorConfig config, final boolean serializeAllTypes) {
    try {
        final XtendFile file = this.file(input.toString(), true);
        final ArrayList<CharSequence> results = CollectionLiterals.<CharSequence>newArrayList();
        Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(file.eResource().getContents(), JvmDeclaredType.class);
        for (final JvmDeclaredType inferredType : _filter) {
            {
                Assert.assertFalse(DisableCodeGenerationAdapter.isDisabled(inferredType));
                CharSequence javaCode = this.generator.generateType(inferredType, config);
                javaCode = this.postProcessor.postProcess(null, javaCode);
                results.add(javaCode);
                if (this.useJavaCompiler) {
                    final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
                        it.getCompiledClass();
                    };
                    this.compilationTestHelper.compile(input, _function);
                }
            }
        }
        if (serializeAllTypes) {
            Assert.assertEquals(expected.toString(), IterableExtensions.join(results, "\n"));
        } else {
            Assert.assertEquals(expected.toString(), IterableExtensions.<CharSequence>head(results).toString());
        }
        return file;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) CompilationTestHelper(org.eclipse.xtext.xbase.testing.CompilationTestHelper) IAcceptor(org.eclipse.xtext.util.IAcceptor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 35 with JvmDeclaredType

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

the class AbstractMultiModeOutlineTreeProvider method createQualifier.

private String createQualifier(JvmMember jvmMember) {
    String qualifier = null;
    if (jvmMember instanceof JvmFeature) {
        JvmDeclaredType declaringType = jvmMember.getDeclaringType();
        qualifier = getPackageFreeNameForType(declaringType);
    } else if (jvmMember instanceof JvmDeclaredType) {
        if (jvmMember.eContainer() instanceof JvmDeclaredType) {
            qualifier = getPackageFreeNameForType((JvmDeclaredType) jvmMember.eContainer());
        } else {
            JvmDeclaredType jvmDeclaredType = (JvmDeclaredType) jvmMember;
            if (StringUtils.isEmpty(jvmDeclaredType.getPackageName())) {
                qualifier = "(default package)";
            } else {
                qualifier = jvmDeclaredType.getPackageName();
            }
        }
    }
    return qualifier;
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) StyledString(org.eclipse.jface.viewers.StyledString)

Aggregations

JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)74 EObject (org.eclipse.emf.ecore.EObject)21 JvmType (org.eclipse.xtext.common.types.JvmType)18 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)12 JvmMember (org.eclipse.xtext.common.types.JvmMember)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 Test (org.junit.Test)8 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)7 Resource (org.eclipse.emf.ecore.resource.Resource)5 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)5 XExpression (org.eclipse.xtext.xbase.XExpression)5 List (java.util.List)4 EList (org.eclipse.emf.common.util.EList)4 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)4