org.eclipse.xtext.generator.GeneratorDelegate Java Examples
The following examples show how to use
org.eclipse.xtext.generator.GeneratorDelegate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompilationTestHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void doGenerate() { if (access == null) { doValidation(); access = fileSystemAccessProvider.get(); access.setOutputConfigurations(outputConfigurations); for (Resource resource : sources) { if (resource instanceof XtextResource) { access.setProjectName(PROJECT_NAME); XtextResource xtextResource = (XtextResource) resource; IResourceServiceProvider resourceServiceProvider = xtextResource.getResourceServiceProvider(); GeneratorDelegate generator = resourceServiceProvider.get(GeneratorDelegate.class); if (generator != null) { GeneratorContext context = new GeneratorContext(); context.setCancelIndicator(CancelIndicator.NullImpl); generator.generate(xtextResource, access, context); } } } generatedCode = newHashMap(); for (final GeneratedFile e : access.getGeneratedFiles()) { if (e.getJavaClassName() != null) { generatedCode.put(e.getJavaClassName(), e.getContents().toString()); } } } }
Example #2
Source File: CompilationTestHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void doGenerate() { if (access == null) { doValidation(); access = fileSystemAccessProvider.get(); access.setOutputConfigurations(outputConfigurations); for (Resource resource : sources) { if (resource instanceof XtextResource) { access.setProjectName(PROJECT_NAME); XtextResource xtextResource = (XtextResource) resource; IResourceServiceProvider resourceServiceProvider = xtextResource.getResourceServiceProvider(); GeneratorDelegate generator = resourceServiceProvider.get(GeneratorDelegate.class); if (generator != null) { GeneratorContext context = new GeneratorContext(); context.setCancelIndicator(CancelIndicator.NullImpl); generator.generate(xtextResource, access, context); } } } generatedCode = newHashMap(); for (final GeneratedFile e : access.getGeneratedFiles()) { if (e.getJavaClassName() != null) { generatedCode.put(e.getJavaClassName(), e.getContents().toString()); } } } }
Example #3
Source File: XStatefulIncrementalBuilder.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** 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.setResultGeneratedFile(source, uri); return contents; }); fileSystemAccess.setBeforeDelete((uri) -> { newMappings.deleteGenerated(uri); request.setResultDeleteFile(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.setResultDeleteFile(noLongerCreated); } catch (IOException e) { Exceptions.sneakyThrow(e); } } } }
Example #4
Source File: LanguageAccess.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public GeneratorDelegate getGenerator() { return resourceServiceProvider.get(GeneratorDelegate.class); }
Example #5
Source File: IncrementalBuilder.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * Generate code for the given resource */ protected void generate(Resource resource, BuildRequest request, Source2GeneratedMapping newMappings) { IResourceServiceProvider serviceProvider = getResourceServiceProvider(resource); GeneratorDelegate generator = serviceProvider.get(GeneratorDelegate.class); if (generator == null) { return; } Set<URI> previous = newMappings.deleteSource(resource.getURI()); URIBasedFileSystemAccess fileSystemAccess = createFileSystemAccess(serviceProvider, resource); fileSystemAccess.setBeforeWrite((uri, outputCfgName, contents) -> { newMappings.addSource2Generated(resource.getURI(), uri, outputCfgName); previous.remove(uri); request.getAfterGenerateFile().apply(resource.getURI(), uri); return contents; }); fileSystemAccess.setBeforeDelete((uri) -> { newMappings.deleteGenerated(uri); request.getAfterDeleteFile().apply(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); } } 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, Collections.emptyMap()); request.getAfterDeleteFile().apply(noLongerCreated); } catch (IOException e) { throw new RuntimeIOException(e); } } }