org.eclipse.xtext.generator.IGeneratorContext Java Examples
The following examples show how to use
org.eclipse.xtext.generator.IGeneratorContext.
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: ExtraLanguageGeneratorSupport.java From sarl with Apache License 2.0 | 6 votes |
@Override public void beforeGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { final IGenerator2 mainGenerator = getMainGenerator(); if (mainGenerator != null) { mainGenerator.beforeGenerate(input, fsa, context); } final Iterable<IRootGenerator> generators = getExtraGeneratorProvider().getGenerators(context, input); if (generators != null) { for (final IGenerator2 generator : generators) { try { generator.beforeGenerate(input, fsa, context); } catch (Throwable exception) { getLogger().log(Level.SEVERE, exception.getLocalizedMessage(), exception); } } } }
Example #2
Source File: ExtraLanguageGeneratorSupport.java From sarl with Apache License 2.0 | 6 votes |
@Override public void afterGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { final IGenerator2 mainGenerator = getMainGenerator(); if (mainGenerator != null) { mainGenerator.afterGenerate(input, fsa, context); } final Iterable<IRootGenerator> generators = getExtraGeneratorProvider().getGenerators(context, input); if (generators != null) { for (final IGenerator2 generator : generators) { try { generator.afterGenerate(input, fsa, context); } catch (Throwable exception) { getLogger().log(Level.SEVERE, exception.getLocalizedMessage(), exception); } } } }
Example #3
Source File: ExtraLanguageGeneratorSupport.java From sarl with Apache License 2.0 | 6 votes |
@Override public void doGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { final IGenerator2 mainGenerator = getMainGenerator(); if (mainGenerator != null) { mainGenerator.doGenerate(input, fsa, context); } final Iterable<IRootGenerator> generators = getExtraGeneratorProvider().getGenerators(context, input); if (generators != null) { for (final IGenerator2 generator : generators) { try { generator.doGenerate(input, fsa, context); } catch (Throwable exception) { getLogger().log(Level.SEVERE, exception.getLocalizedMessage(), exception); } } } }
Example #4
Source File: IndexTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public void doGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { TreeIterator<EObject> iter = input.getAllContents(); while (iter.hasNext()) { EObject e = iter.next(); if (e instanceof Entity) { Entity entity = (Entity) e; StringConcatenation builder = new StringConcatenation(); builder.append("Hello "); builder.append(entity.getName()); builder.append("!"); builder.newLineIfNotEmpty(); fsa.generateFile(entity.getName() + ".txt", builder); } } }
Example #5
Source File: AbstractExtraLanguageGeneratorProvider.java From sarl with Apache License 2.0 | 6 votes |
@Override public Iterable<IRootGenerator> getGenerators(IGeneratorContext context, Resource resource) { final IProject project = ProjectAdapter.getProject(resource); if (this.preferences.isGeneratorEnabled( getPreferenceID(), project)) { IRootGenerator gen; synchronized (this) { gen = this.generator == null ? null : this.generator.get(); if (gen == null) { gen = createGeneratorInstance(this.injector); this.generator = new SoftReference<>(gen); } } return Collections.singletonList(gen); } return Collections.emptyList(); }
Example #6
Source File: PartialSerializationTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { // Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class); // Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() { // // @Override // public String apply(Greeting greeting) { // return greeting.getName(); // } // }); // fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", ")); }
Example #7
Source File: GamlGenerator.java From gama with GNU General Public License v3.0 | 5 votes |
/** * @param input * @return */ // private String getFilenameFor(final GamlResource input) { // IPath path = GamlResourceServices.getPathOf(input); // final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); // path = file.getProjectRelativePath(); // final String s = path.toString(); // return s + ".meta"; // } @Override public void doGenerate(final Resource input, final IFileSystemAccess2 fsa, final IGeneratorContext context) { // TODO Auto-generated method stub }
Example #8
Source File: NestedRefsTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { // Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class); // Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() { // // @Override // public String apply(Greeting greeting) { // return greeting.getName(); // } // }); // fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", ")); }
Example #9
Source File: NoJdtTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class); Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() { @Override public String apply(Greeting greeting) { return greeting.getName(); } }); String fileName = resource.getURI().lastSegment(); if(fileName == null) fileName = "greetings"; fsa.generateFile(fileName+".txt", "People to greet: " + IteratorExtensions.join(names, ", ")); }
Example #10
Source File: FileAwareTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { // Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class); // Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() { // // @Override // public String apply(Greeting greeting) { // return greeting.getName(); // } // }); // fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", ")); }
Example #11
Source File: ExtraLanguageGeneratorContext.java From sarl with Apache License 2.0 | 5 votes |
/** Create the context for the given delegate. * * @param delegate the delegate. * @param fileSystemAccess the file system access. * @param generator the root generator. * @param resource the resource. * @param preferenceId the identifier of the container of the generator's preferences. */ public ExtraLanguageGeneratorContext(IGeneratorContext delegate, IFileSystemAccess2 fileSystemAccess, IRootGenerator generator, Resource resource, String preferenceId) { this.identifier = UUID.randomUUID(); this.generationDate = new Date(); this.preferenceId = preferenceId; this.delegate = delegate; this.fileSystemAccess = fileSystemAccess; this.resource = resource; this.rootGenerator = new WeakReference<>(generator); }
Example #12
Source File: AbstractExtraLanguageGenerator.java From sarl with Apache License 2.0 | 5 votes |
@Override public void beforeGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { final IExtraLanguageGeneratorContext generatorContext = createGeneratorContext(fsa, context, input); final EList<EObject> contents = input.getContents(); for (final EObject obj : contents) { if (canGenerateFor(obj)) { before(obj, generatorContext); final Iterator<EObject> iterator = EcoreUtil.getAllContents(obj, false); while (iterator.hasNext()) { final EObject subobj = iterator.next(); before(subobj, generatorContext); } } } }
Example #13
Source File: PartialContentAssistTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { // Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class); // Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() { // // @Override // public String apply(Greeting greeting) { // return greeting.getName(); // } // }); // fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", ")); }
Example #14
Source File: IndentationAwareUiTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { // Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class); // Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() { // // @Override // public String apply(Greeting greeting) { // return greeting.getName(); // } // }); // fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", ")); }
Example #15
Source File: RenameTestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { // Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class); // Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() { // // @Override // public String apply(Greeting greeting) { // return greeting.getName(); // } // }); // fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", ")); }
Example #16
Source File: AbstractExtraLanguageGenerator.java From sarl with Apache License 2.0 | 5 votes |
@Override public void doGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { final IExtraLanguageGeneratorContext generatorContext = createGeneratorContext(fsa, context, input); initializeContext(generatorContext); final EList<EObject> contents = input.getContents(); for (final EObject obj : contents) { if (canGenerateFor(obj)) { generate(obj, generatorContext); } } }
Example #17
Source File: AbstractExtraLanguageGenerator.java From sarl with Apache License 2.0 | 5 votes |
@Override public void afterGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { final IExtraLanguageGeneratorContext generatorContext = createGeneratorContext(fsa, context, input); final EList<EObject> contents = input.getContents(); for (final EObject obj : contents) { if (canGenerateFor(obj)) { final Iterator<EObject> iterator = EcoreUtil.getAllContents(obj, false); while (iterator.hasNext()) { final EObject subobj = iterator.next(); after(subobj, generatorContext); } after(obj, generatorContext); } } }
Example #18
Source File: AbstractExtraLanguageGenerator.java From sarl with Apache License 2.0 | 5 votes |
/** Create the generator context for this generator. * * @param fsa the file system access. * @param context the global context. * @param resource the resource. * @return the context. */ protected IExtraLanguageGeneratorContext createGeneratorContext(IFileSystemAccess2 fsa, IGeneratorContext context, Resource resource) { if (context instanceof IExtraLanguageGeneratorContext) { return (IExtraLanguageGeneratorContext) context; } return new ExtraLanguageGeneratorContext(context, fsa, this, resource, getPreferenceID()); }
Example #19
Source File: StatemachineGenerator.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) { String _className = this.className(resource); String _plus = (_className + ".java"); EObject _head = IterableExtensions.<EObject>head(resource.getContents()); fsa.generateFile(_plus, this.toJavaCode(((Statemachine) _head))); }
Example #20
Source File: ExtraLanguageGeneratorSupport.java From sarl with Apache License 2.0 | 5 votes |
/** Generate the file(s) from the input resource. * * @param input the input resource. * @param fsa the file system access. * @param context the generator context. */ public final void generate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { try { beforeGenerate(input, fsa, context); doGenerate(input, fsa, context); } finally { afterGenerate(input, fsa, context); } }
Example #21
Source File: ExtraLanguageGeneratorContext.java From sarl with Apache License 2.0 | 4 votes |
@Override public IGeneratorContext getDelegate() { return this.delegate; }
Example #22
Source File: PyGeneratorProvider.java From sarl with Apache License 2.0 | 4 votes |
@Override public Iterable<IRootGenerator> getGenerators(IGeneratorContext context, Resource resource) { final PyGenerator generator = this.injector.getInstance(PyGenerator.class); return Collections.singleton(generator); }
Example #23
Source File: NullExtraLanguageGeneratorProvider.java From sarl with Apache License 2.0 | 4 votes |
@Override public Iterable<IRootGenerator> getGenerators(IGeneratorContext context, Resource resource) { return Collections.emptyList(); }
Example #24
Source File: BromiumGenerator.java From bromium with MIT License | 4 votes |
@Override public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) { }
Example #25
Source File: GamlGenerator.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public void afterGenerate(final Resource input, final IFileSystemAccess2 fsa, final IGeneratorContext context) { // TODO Auto-generated method stub }
Example #26
Source File: GamlGenerator.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public void beforeGenerate(final Resource input, final IFileSystemAccess2 fsa, final IGeneratorContext context) { // TODO Auto-generated method stub }
Example #27
Source File: GeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void doGenerateJavaStubFile() { TypeReference _generatorStub = this.getGeneratorStub(this.getGrammar()); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("/**"); _builder.newLine(); _builder.append(" "); _builder.append("* Generates code from your model files on save."); _builder.newLine(); _builder.append(" "); _builder.append("* "); _builder.newLine(); _builder.append(" "); _builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation"); _builder.newLine(); _builder.append(" "); _builder.append("*/"); _builder.newLine(); _builder.append("public class "); String _simpleName = GeneratorFragment2.this.getGeneratorStub(GeneratorFragment2.this.getLanguage().getGrammar()).getSimpleName(); _builder.append(_simpleName); _builder.append(" extends "); _builder.append(AbstractGenerator.class); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append("\t"); _builder.append("@"); _builder.append(Override.class, "\t"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("public void doGenerate("); _builder.append(Resource.class, "\t"); _builder.append(" resource, "); _builder.append(IFileSystemAccess2.class, "\t"); _builder.append(" fsa, "); _builder.append(IGeneratorContext.class, "\t"); _builder.append(" context) {"); _builder.newLineIfNotEmpty(); _builder.append("//\t\tIterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class);"); _builder.newLine(); _builder.append("//\t\tIterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() {"); _builder.newLine(); _builder.append("//"); _builder.newLine(); _builder.append("//\t\t\t@"); _builder.append(Override.class); _builder.newLineIfNotEmpty(); _builder.append("//\t\t\tpublic String apply(Greeting greeting) {"); _builder.newLine(); _builder.append("//\t\t\t\treturn greeting.getName();"); _builder.newLine(); _builder.append("//\t\t\t}"); _builder.newLine(); _builder.append("//\t\t});"); _builder.newLine(); _builder.append("//\t\tfsa.generateFile(\"greetings.txt\", \"People to greet: \" + IteratorExtensions.join(names, \", \"));"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; this.fileAccessFactory.createJavaFile(_generatorStub, _client).writeTo(this.getProjectConfig().getRuntime().getSrc()); }
Example #28
Source File: GeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void doGenerateXtendStubFile() { TypeReference _generatorStub = this.getGeneratorStub(this.getGrammar()); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("/**"); _builder.newLine(); _builder.append(" "); _builder.append("* Generates code from your model files on save."); _builder.newLine(); _builder.append(" "); _builder.append("* "); _builder.newLine(); _builder.append(" "); _builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation"); _builder.newLine(); _builder.append(" "); _builder.append("*/"); _builder.newLine(); _builder.append("class "); String _simpleName = GeneratorFragment2.this.getGeneratorStub(GeneratorFragment2.this.getLanguage().getGrammar()).getSimpleName(); _builder.append(_simpleName); _builder.append(" extends "); _builder.append(AbstractGenerator.class); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append("\t"); _builder.append("override void doGenerate("); _builder.append(Resource.class, "\t"); _builder.append(" resource, "); _builder.append(IFileSystemAccess2.class, "\t"); _builder.append(" fsa, "); _builder.append(IGeneratorContext.class, "\t"); _builder.append(" context) {"); _builder.newLineIfNotEmpty(); _builder.append("//\t\tfsa.generateFile(\'greetings.txt\', \'People to greet: \' + "); _builder.newLine(); _builder.append("//\t\t\tresource.allContents"); _builder.newLine(); _builder.append("//\t\t\t\t.filter(Greeting)"); _builder.newLine(); _builder.append("//\t\t\t\t.map[name]"); _builder.newLine(); _builder.append("//\t\t\t\t.join(\', \'))"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; this.fileAccessFactory.createXtendFile(_generatorStub, _client).writeTo(this.getProjectConfig().getRuntime().getSrc()); }
Example #29
Source File: TestLanguageGenerator.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) { String _scheme = fsa.getURI("").scheme(); boolean _equals = Objects.equal(_scheme, "inmemory"); if (_equals) { return; } List<TypeDeclaration> _list = IteratorExtensions.<TypeDeclaration>toList(Iterators.<TypeDeclaration>filter(resource.getAllContents(), TypeDeclaration.class)); for (final TypeDeclaration type : _list) { String _name = type.getName(); String _plus = (_name + ".java"); StringConcatenation _builder = new StringConcatenation(); _builder.append("public class "); String _name_1 = type.getName(); _builder.append(_name_1); _builder.append(" {"); _builder.newLineIfNotEmpty(); { Iterable<Property> _filter = Iterables.<Property>filter(type.getMembers(), Property.class); for(final Property p : _filter) { _builder.append("\t"); _builder.append("private "); String _java = this.toJava(p.getType()); _builder.append(_java, "\t"); _builder.append(" "); String _name_2 = p.getName(); _builder.append(_name_2, "\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("public void set"); String _firstUpper = StringExtensions.toFirstUpper(p.getName()); _builder.append(_firstUpper, "\t"); _builder.append("("); String _java_1 = this.toJava(p.getType()); _builder.append(_java_1, "\t"); _builder.append(" "); String _name_3 = p.getName(); _builder.append(_name_3, "\t"); _builder.append(") {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("\t"); _builder.append("this."); String _name_4 = p.getName(); _builder.append(_name_4, "\t\t"); _builder.append(" = "); String _name_5 = p.getName(); _builder.append(_name_5, "\t\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("public "); String _java_2 = this.toJava(p.getType()); _builder.append(_java_2, "\t"); _builder.append(" get"); String _firstUpper_1 = StringExtensions.toFirstUpper(p.getName()); _builder.append(_firstUpper_1, "\t"); _builder.append("() {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("\t"); _builder.append("return this."); String _name_6 = p.getName(); _builder.append(_name_6, "\t\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); } } _builder.append("}"); _builder.newLine(); fsa.generateFile(_plus, _builder); } }
Example #30
Source File: XtendGenerator.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public void doGenerate(final Resource input, final IFileSystemAccess2 fsa, final IGeneratorContext context) { this.doGenerate(input, ((IFileSystemAccess) fsa)); }