本文整理汇总了Java中org.eclipse.xtext.generator.AbstractGenerator类的典型用法代码示例。如果您正苦于以下问题:Java AbstractGenerator类的具体用法?Java AbstractGenerator怎么用?Java AbstractGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractGenerator类属于org.eclipse.xtext.generator包,在下文中一共展示了AbstractGenerator类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGenerateXtendStubFile
import org.eclipse.xtext.generator.AbstractGenerator; //导入依赖的package包/类
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());
}
示例2: doGenerateJavaStubFile
import org.eclipse.xtext.generator.AbstractGenerator; //导入依赖的package包/类
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\[email protected]");
_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());
}