Search in sources :

Example 1 with IGenerator2

use of org.eclipse.xtext.generator.IGenerator2 in project xtext-eclipse by eclipse.

the class ParallelBuilderParticipant method createRunnable.

/**
 * @since 2.9
 */
protected Runnable createRunnable(final ParallelBuildContext buildContext) {
    final IGenerator2 generator = getGenerator2();
    final Resource resource = buildContext.resource;
    if (resource != null) {
        generator.beforeGenerate(resource, buildContext.synchronousFileSystemAccess, buildContext.getGeneratorContext());
        buildContext.afterGenerateQueue.add(buildContext);
    }
    return new Runnable() {

        @Override
        public void run() {
            Delta delta = buildContext.delta;
            try {
                Set<IFile> derivedResources = getDerivedResources(delta, buildContext.outputConfigurations, buildContext.generatorMarkers);
                FileSystemAccessQueue fileSystemAccessQueue = buildContext.fileSystemAccessQueue;
                IFileSystemAccess2 fsa = getParallelFileSystemAccess(delta, buildContext, derivedResources, fileSystemAccessQueue, buildContext.synchronousFileSystemAccess);
                boolean generated = doGenerate(delta, buildContext, fsa);
                final Runnable derivedResourceCallback = getFlushAndCleanDerivedResourcesCallback(buildContext, derivedResources, generated);
                fileSystemAccessQueue.sendAsync(delta.getUri(), new Runnable() {

                    @Override
                    public void run() {
                        try {
                            derivedResourceCallback.run();
                        } finally {
                            if (resource != null) {
                                generator.afterGenerate(resource, buildContext.synchronousFileSystemAccess, buildContext.getGeneratorContext());
                                buildContext.afterGenerateQueue.remove(buildContext);
                            }
                        }
                    }
                });
            } catch (OperationCanceledException e) {
            // do nothing
            } catch (Throwable e) {
                addMarkerAndLogError(delta.getUri(), e);
            }
        }
    };
}
Also used : IFile(org.eclipse.core.resources.IFile) IFileSystemAccess2(org.eclipse.xtext.generator.IFileSystemAccess2) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Resource(org.eclipse.emf.ecore.resource.Resource) IGenerator2(org.eclipse.xtext.generator.IGenerator2) FileSystemAccessQueue(org.eclipse.xtext.generator.FileSystemAccessQueue)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 FileSystemAccessQueue (org.eclipse.xtext.generator.FileSystemAccessQueue)1 IFileSystemAccess2 (org.eclipse.xtext.generator.IFileSystemAccess2)1 IGenerator2 (org.eclipse.xtext.generator.IGenerator2)1 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)1