Search in sources :

Example 66 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class XtendBatchCompiler method compile.

public boolean compile() {
    try {
        if (!checkConfiguration()) {
            return false;
        }
        ResourceSet resourceSet = resourceSetProvider.get();
        if (!configureWorkspace(resourceSet)) {
            return false;
        }
        generatorConfigProvider.install(resourceSet, generatorConfig);
        File classDirectory = createTempDir("classes");
        try {
            compilerPhases.setIndexing(resourceSet, true);
            // install a type provider without index lookup for the first phase
            installJvmTypeProvider(resourceSet, classDirectory, true);
            loadXtendFiles(resourceSet);
            File sourceDirectory = createStubs(resourceSet);
            if (!preCompileStubs(sourceDirectory, classDirectory)) {
                log.warn("Compilation of stubs had errors.");
            }
            if (!preCompileJava(sourceDirectory, classDirectory)) {
                log.debug("Compilation of Java code against stubs had errors. This is expected and usually is not a probblem.");
            }
        } finally {
            compilerPhases.setIndexing(resourceSet, false);
        }
        // install a fresh type provider for the second phase, so we clear all previously cached classes and misses.
        installJvmTypeProvider(resourceSet, classDirectory, false);
        List<Resource> toBeResolved = new ArrayList<>(resourceSet.getResources().size());
        for (Resource resource : resourceSet.getResources()) {
            if (isSourceFile(resource)) {
                toBeResolved.add(resource);
            }
        }
        for (Resource resource : toBeResolved) {
            EcoreUtil.resolveAll(resource);
        }
        List<Issue> issues = validate(resourceSet);
        Iterable<Issue> errors = Iterables.filter(issues, SeverityFilter.ERROR);
        Iterable<Issue> warnings = Iterables.filter(issues, SeverityFilter.WARNING);
        reportIssues(Iterables.concat(errors, warnings));
        if (!Iterables.isEmpty(errors)) {
            return false;
        }
        generateJavaFiles(resourceSet);
    } finally {
        destroyClassLoader(jvmTypesClassLoader);
        destroyClassLoader(annotationProcessingClassLoader);
        if (isDeleteTempDirectory()) {
            deleteTmpFolders();
        }
    }
    return true;
}
Also used : Issue(org.eclipse.xtext.validation.Issue) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) XtextResource(org.eclipse.xtext.resource.XtextResource) BatchLinkableResource(org.eclipse.xtext.xbase.resource.BatchLinkableResource) ArrayList(java.util.ArrayList) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtendFile(org.eclipse.xtend.core.xtend.XtendFile) File(java.io.File)

Example 67 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class XtendRenameContextFactory method createLocalRenameElementContext.

@Override
public IRenameElementContext createLocalRenameElementContext(EObject targetElement, XtextEditor editor, ITextSelection selection, XtextResource resource) {
    EObject declarationTarget = getDeclarationTarget(targetElement);
    if (declarationTarget instanceof XtendFunction && ((XtendFunction) declarationTarget).isDispatch()) {
        IProject project = projectUtil.getProject(declarationTarget.eResource().getURI());
        ResourceSet resourceSet = resourceSetProvider.get(project);
        XtendFunction relaodedDispatchFunction = (XtendFunction) resourceSet.getEObject(EcoreUtil2.getPlatformResourceOrNormalizedURI(declarationTarget), true);
        Iterable<JvmOperation> allDispatchOperations = dispatchRenameSupport.getAllDispatchOperations(relaodedDispatchFunction);
        Map<URI, IJavaElement> jvm2javaElement = newLinkedHashMap();
        for (JvmOperation jvmOperation : allDispatchOperations) {
            IJavaElement javaElement = getJavaElementFinder().findExactElementFor(jvmOperation);
            if (javaElement != null) {
                URI jvmOperationURI = EcoreUtil.getURI(jvmOperation);
                jvm2javaElement.put(jvmOperationURI, javaElement);
            }
        }
        if (!jvm2javaElement.isEmpty()) {
            return new DispatchMethodRenameContext(relaodedDispatchFunction, jvm2javaElement, editor, selection, resource);
        }
    }
    return super.createLocalRenameElementContext(targetElement, editor, selection, resource);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IJavaElement(org.eclipse.jdt.core.IJavaElement) EObject(org.eclipse.emf.ecore.EObject) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject)

Example 68 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class JdtBasedProcessorProvider method getClassLoader.

@Override
public ClassLoader getClassLoader(final EObject ctx) {
    ResourceSet _resourceSet = ctx.eResource().getResourceSet();
    final XtextResourceSet rs = ((XtextResourceSet) _resourceSet);
    final boolean isBuilder = ResourceSetContext.get(rs).isBuilder();
    final boolean isEditor = ResourceSetContext.get(rs).isEditor();
    if (isBuilder) {
        final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(rs.eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
        if ((adapter != null)) {
            return adapter.getClassLoader();
        }
    }
    if (isEditor) {
        final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter_1 = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(this.getEditorResource(ctx).eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
        if ((adapter_1 != null)) {
            ClassLoader _classLoader = adapter_1.getClassLoader();
            boolean _tripleEquals = (_classLoader == null);
            if (_tripleEquals) {
                this.getEditorResource(ctx).eAdapters().remove(adapter_1);
            } else {
                return adapter_1.getClassLoader();
            }
        }
    }
    Object _classpathURIContext = rs.getClasspathURIContext();
    final IJavaProject project = ((IJavaProject) _classpathURIContext);
    final URLClassLoader classloader = this.createClassLoaderForJavaProject(project);
    if (isBuilder) {
        EList<Adapter> _eAdapters = rs.eAdapters();
        ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
        _eAdapters.add(_processorClassloaderAdapter);
    }
    if (isEditor) {
        EList<Adapter> _eAdapters_1 = this.getEditorResource(ctx).eAdapters();
        ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter_1 = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
        _eAdapters_1.add(_processorClassloaderAdapter_1);
    }
    return classloader;
}
Also used : ProcessorInstanceForJvmTypeProvider(org.eclipse.xtend.core.macro.ProcessorInstanceForJvmTypeProvider) IJavaProject(org.eclipse.jdt.core.IJavaProject) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) EObject(org.eclipse.emf.ecore.EObject) Adapter(org.eclipse.emf.common.notify.Adapter) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 69 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class FormatterResourceProvider method createResource.

@Override
public XtextResource createResource() {
    ResourceSet resourceSet = resourceSetProvider.get(null);
    @SuppressWarnings("restriction") XtextResource result = (XtextResource) resourceSet.createResource(URI.createURI(org.eclipse.xtext.ui.codetemplates.ui.preferences.TemplateResourceProvider.SYNTHETIC_SCHEME + ":/" + "FormatterPreview.xtend"));
    result.setValidationDisabled(true);
    return result;
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 70 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class DispatchRenameSupport method getAllDispatchOperations.

/**
 * Returns all operations of the declaring type that have to be renamed with the given Xtend function. I.e. all
 * dispatch functions with the same name of all sub- and super types as well as the artificial dispatchers.
 *
 * The method will likely load all subtypes into the resource set of the dispatch function, so you might want to
 * hand in a reloaded instance instead.
 */
public Iterable<JvmOperation> getAllDispatchOperations(XtendFunction dispatchFunction) {
    Assert.isLegal(dispatchFunction.isDispatch());
    IProject project = projectUtil.getProject(dispatchFunction.eResource().getURI());
    final ResourceSet tempResourceSet = resourceSetProvider.get(project);
    JvmOperation localDispatcher = associations.getDispatchOperation(dispatchFunction);
    XtendClass xtendClass = (XtendClass) dispatchFunction.eContainer();
    final Set<JvmOperation> dispatchCases = newLinkedHashSet();
    IAcceptor<JvmOperation> operationAcceptor = new IAcceptor<JvmOperation>() {

        @Override
        public void accept(JvmOperation operation) {
            dispatchCases.add(operation);
        }
    };
    final Set<JvmGenericType> processedTypes = newHashSet();
    addDispatcher(associations.getInferredType(xtendClass), new DispatchHelper.DispatchSignature(localDispatcher.getSimpleName(), localDispatcher.getParameters().size()), operationAcceptor, processedTypes, tempResourceSet);
    return dispatchCases;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) IAcceptor(org.eclipse.xtext.util.IAcceptor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) IProject(org.eclipse.core.resources.IProject)

Aggregations

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)71 Test (org.junit.Test)51 EObject (org.eclipse.emf.ecore.EObject)34 URI (org.eclipse.emf.common.util.URI)32 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)32 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)21 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)21 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)17 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)17 XtextResource (org.eclipse.xtext.resource.XtextResource)16 EPackage (org.eclipse.emf.ecore.EPackage)12 IFile (org.eclipse.core.resources.IFile)10 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)10 ArrayList (java.util.ArrayList)9 EClass (org.eclipse.emf.ecore.EClass)9 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)9 IOException (java.io.IOException)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8