org.eclipse.xtext.generator.AbstractGenerator Java Examples

The following examples show how to use org.eclipse.xtext.generator.AbstractGenerator. 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: GeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
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 #2
Source File: GeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
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());
}