use of org.eclipse.xtext.generator.GeneratorDelegate in project n4js by eclipse.
the class XStatefulIncrementalBuilder method generate.
/**
* Generate code for the given resource
*/
protected void generate(Resource resource, XSource2GeneratedMapping newMappings, IResourceServiceProvider serviceProvider) {
GeneratorDelegate generator = serviceProvider.get(GeneratorDelegate.class);
if (generator == null) {
return;
}
if (isResourceInOutputDirectory(resource, serviceProvider)) {
return;
}
URI source = resource.getURI();
Set<URI> previous = newMappings.deleteSource(source);
URIBasedFileSystemAccess fileSystemAccess = this.createFileSystemAccess(serviceProvider, resource);
fileSystemAccess.setBeforeWrite((uri, outputCfgName, contents) -> {
newMappings.addSource2Generated(source, uri, outputCfgName);
previous.remove(uri);
request.afterGenerate(source, uri);
return contents;
});
fileSystemAccess.setBeforeDelete((uri) -> {
newMappings.deleteGenerated(uri);
request.afterDelete(uri);
return true;
});
fileSystemAccess.setContext(resource);
if (request.isWriteStorageResources() && resource instanceof StorageAwareResource) {
IResourceStorageFacade resourceStorageFacade = ((StorageAwareResource) resource).getResourceStorageFacade();
if (resourceStorageFacade != null) {
resourceStorageFacade.saveResource((StorageAwareResource) resource, fileSystemAccess);
}
}
if (request.canGenerate()) {
GeneratorContext generatorContext = new GeneratorContext();
generatorContext.setCancelIndicator(request.getCancelIndicator());
generator.generate(resource, fileSystemAccess, generatorContext);
XtextResourceSet resourceSet = request.getResourceSet();
for (URI noLongerCreated : previous) {
try {
resourceSet.getURIConverter().delete(noLongerCreated, CollectionLiterals.emptyMap());
request.afterDelete(noLongerCreated);
} catch (IOException e) {
Exceptions.sneakyThrow(e);
}
}
}
}
use of org.eclipse.xtext.generator.GeneratorDelegate in project ArchCNL by Mari-Wie.
the class CNL2OWLGenerator method transformCNLFile.
/**
* Translates the given file from ArchCNL's CNL to OWL. The resulting OWL ontology is written to
* the specified output file.
*
* @param path The path of the file to transform.
* @param outputPath The path of the output file.
* @return The RuleType of the parsed rule or null when something went wrong.
* @throws IOException
*/
public RuleType transformCNLFile(String path, String outputPath) throws IOException {
LOG.trace("transforming CNL file with path: " + path);
RuleTypeStorageSingleton.getInstance().setOutputFile(outputPath);
ArchcnlStandaloneSetup setup = new ArchcnlStandaloneSetup();
Injector injector = setup.createInjectorAndDoEMFRegistration();
XtextResourceSet set = injector.getInstance(XtextResourceSet.class);
// load a resource by URI, in this case from the file system
URI uri = URI.createFileURI(path);
LOG.trace("uri: " + uri);
LOG.debug("Reading CNL file: " + path);
Resource resource = set.getResource(uri, true);
IResourceValidator validator = ((XtextResource) resource).getResourceServiceProvider().getResourceValidator();
List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
for (Issue issue : issues) {
LOG.error(issue.getMessage());
}
GeneratorDelegate generator = injector.getInstance(GeneratorDelegate.class);
// fsa wird nur als leer Hülle für den Aufruf erstellt, aber nicht weiter verwendet.
InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
LOG.trace("resource: " + resource);
try {
generator.doGenerate(resource, fsa);
} catch (UncheckedIOException e) {
throw new IOException("Failure while generating", e);
}
RuleType ruleType = RuleTypeStorageSingleton.getInstance().retrieveTypeOfRule(id);
id++;
return ruleType;
}
Aggregations