Search in sources :

Example 1 with IFileSystemAccess2

use of org.eclipse.xtext.generator.IFileSystemAccess2 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)

Example 2 with IFileSystemAccess2

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

the class MyGenerator method doGenerate.

@Override
public void doGenerate(Resource input, IFileSystemAccess fsa) {
    TreeIterator<EObject> allContents = input.getAllContents();
    while (allContents.hasNext()) {
        EObject next = allContents.next();
        if (next instanceof Element) {
            Element ele = (Element) next;
            String fileName = ele.getName() + ".txt";
            if (fsa instanceof IFileSystemAccess2) {
                IFileSystemAccess2 fileSystemAccess2 = (IFileSystemAccess2) fsa;
                if (fileSystemAccess2.isFile(fileName)) {
                    fileSystemAccess2.readTextFile(fileName);
                }
            }
            fsa.generateFile(fileName, "object " + ele.getName());
        }
    }
}
Also used : IFileSystemAccess2(org.eclipse.xtext.generator.IFileSystemAccess2) EObject(org.eclipse.emf.ecore.EObject) Element(org.eclipse.xtext.builder.tests.builderTestLanguage.Element)

Aggregations

IFileSystemAccess2 (org.eclipse.xtext.generator.IFileSystemAccess2)2 IFile (org.eclipse.core.resources.IFile)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Element (org.eclipse.xtext.builder.tests.builderTestLanguage.Element)1 FileSystemAccessQueue (org.eclipse.xtext.generator.FileSystemAccessQueue)1 IGenerator2 (org.eclipse.xtext.generator.IGenerator2)1 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)1