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);
}
}
};
}
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());
}
}
}
Aggregations