use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class XtextGenerator method generateServices.
protected void generateServices() {
if (((this.projectConfig.getGenericIde().getSrcGen() == null) || this.languageConfigs.isEmpty())) {
return;
}
final TextFileAccess file = new TextFileAccess();
file.setPath("META-INF/services/org.eclipse.xtext.ISetup");
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
for (final XtextGeneratorLanguage lang : XtextGenerator.this.languageConfigs) {
TypeReference _genericIdeSetup = XtextGenerator.this.naming.getGenericIdeSetup(lang.getGrammar());
_builder.append(_genericIdeSetup);
_builder.newLineIfNotEmpty();
}
}
}
};
file.setContent(_client);
file.writeTo(this.projectConfig.getGenericIde().getSrcGen());
}
use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createRuntimeModule.
public JavaFileAccess createRuntimeModule(final IXtextGeneratorLanguage langConfig) {
final Grammar it = langConfig.getGrammar();
boolean _isPreferXtendStubs = this.codeConfig.isPreferXtendStubs();
if (_isPreferXtendStubs) {
TypeReference _runtimeModule = this.naming.getRuntimeModule(it);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Use this class to register components to be used at runtime / without the Equinox extension registry.");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getRuntimeModule(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _runtimeGenModule = XtextGeneratorTemplates.this.naming.getRuntimeGenModule(it);
_builder.append(_runtimeGenModule);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createXtendFile(_runtimeModule, _client);
} else {
TypeReference _runtimeModule_1 = this.naming.getRuntimeModule(it);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Use this class to register components to be used at runtime / without the Equinox extension registry.");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("public class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getRuntimeModule(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _runtimeGenModule = XtextGeneratorTemplates.this.naming.getRuntimeGenModule(it);
_builder.append(_runtimeGenModule);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createJavaFile(_runtimeModule_1, _client_1);
}
}
use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createEclipsePluginModule.
public JavaFileAccess createEclipsePluginModule(final IXtextGeneratorLanguage langConfig) {
final Grammar it = langConfig.getGrammar();
boolean _isPreferXtendStubs = this.codeConfig.isPreferXtendStubs();
if (_isPreferXtendStubs) {
TypeReference _eclipsePluginModule = this.naming.getEclipsePluginModule(it);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Use this class to register components to be used within the Eclipse IDE.");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("@");
_builder.append(FinalFieldsConstructor.class);
_builder.newLineIfNotEmpty();
_builder.append("class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getEclipsePluginModule(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _eclipsePluginGenModule = XtextGeneratorTemplates.this.naming.getEclipsePluginGenModule(it);
_builder.append(_eclipsePluginGenModule);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createXtendFile(_eclipsePluginModule, _client);
} else {
TypeReference _eclipsePluginModule_1 = this.naming.getEclipsePluginModule(it);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Use this class to register components to be used within the Eclipse IDE.");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("public class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getEclipsePluginModule(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _eclipsePluginGenModule = XtextGeneratorTemplates.this.naming.getEclipsePluginGenModule(it);
_builder.append(_eclipsePluginGenModule);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
String _simpleName_1 = XtextGeneratorTemplates.this.naming.getEclipsePluginModule(it).getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append("(");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.ui.plugin.AbstractUIPlugin");
_builder.append(_typeRef, "\t");
_builder.append(" plugin) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super(plugin);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createJavaFile(_eclipsePluginModule_1, _client_1);
}
}
use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createIdeaModule.
public JavaFileAccess createIdeaModule(final IXtextGeneratorLanguage langConfig) {
final Grammar it = langConfig.getGrammar();
boolean _isPreferXtendStubs = this.codeConfig.isPreferXtendStubs();
if (_isPreferXtendStubs) {
TypeReference _ideaModule = this.naming.getIdeaModule(it);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Use this class to register components to be used within IntelliJ IDEA.");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getIdeaModule(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _ideaGenModule = XtextGeneratorTemplates.this.naming.getIdeaGenModule(it);
_builder.append(_ideaGenModule);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createXtendFile(_ideaModule, _client);
} else {
TypeReference _ideaModule_1 = this.naming.getIdeaModule(it);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Use this class to register components to be used within IntelliJ IDEA.");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("public class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getIdeaModule(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _ideaGenModule = XtextGeneratorTemplates.this.naming.getIdeaGenModule(it);
_builder.append(_ideaGenModule);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createJavaFile(_ideaModule_1, _client_1);
}
}
use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createRuntimeGenSetup.
public JavaFileAccess createRuntimeGenSetup(final IXtextGeneratorLanguage langConfig) {
final Grammar it = langConfig.getGrammar();
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getRuntimeGenSetup(it));
XtextGeneratorTemplates.addBackwardsCompabibleImportsTo(langConfig, file);
List<IClassAnnotation> _annotations = file.getAnnotations();
SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
_annotations.add(_suppressWarningsAnnotation);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getRuntimeGenSetup(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" implements ");
_builder.append(ISetup.class);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
_builder.append(Injector.class, "\t");
_builder.append(" createInjectorAndDoEMFRegistration() {");
_builder.newLineIfNotEmpty();
{
EList<Grammar> _usedGrammars = langConfig.getGrammar().getUsedGrammars();
for (final Grammar usedGrammar : _usedGrammars) {
_builder.append("\t\t");
TypeReference _runtimeSetup = XtextGeneratorTemplates.this.naming.getRuntimeSetup(usedGrammar);
_builder.append(_runtimeSetup, "\t\t");
_builder.append(".doSetup();");
_builder.newLineIfNotEmpty();
}
}
{
boolean _isEmpty = langConfig.getGrammar().getUsedGrammars().isEmpty();
if (_isEmpty) {
_builder.append("\t\t");
_builder.append("// register default ePackages");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (!");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef, "\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(\"ecore\"))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_1, "\t\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("\"ecore\", new ");
TypeReference _typeRef_2 = TypeReference.typeRef("org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl");
_builder.append(_typeRef_2, "\t\t\t\t");
_builder.append("());");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("if (!");
TypeReference _typeRef_3 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_3, "\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(\"xmi\"))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
TypeReference _typeRef_4 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_4, "\t\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("\"xmi\", new ");
TypeReference _typeRef_5 = TypeReference.typeRef("org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl");
_builder.append(_typeRef_5, "\t\t\t\t");
_builder.append("());");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("if (!");
TypeReference _typeRef_6 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_6, "\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(\"xtextbin\"))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
TypeReference _typeRef_7 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_7, "\t\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("\"xtextbin\", new ");
_builder.append(BinaryGrammarResourceFactoryImpl.class, "\t\t\t\t");
_builder.append("());");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("if (!");
TypeReference _typeRef_8 = TypeReference.typeRef("org.eclipse.emf.ecore.EPackage");
_builder.append(_typeRef_8, "\t\t");
_builder.append(".Registry.INSTANCE.containsKey(");
_builder.append(XtextPackage.class, "\t\t");
_builder.append(".eNS_URI))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
TypeReference _typeRef_9 = TypeReference.typeRef("org.eclipse.emf.ecore.EPackage");
_builder.append(_typeRef_9, "\t\t\t");
_builder.append(".Registry.INSTANCE.put(");
_builder.append(XtextPackage.class, "\t\t\t");
_builder.append(".eNS_URI, ");
_builder.append(XtextPackage.class, "\t\t\t");
_builder.append(".eINSTANCE);");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("\t\t");
_builder.append(Injector.class, "\t\t");
_builder.append(" injector = createInjector();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("register(injector);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return injector;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
_builder.append(Injector.class, "\t");
_builder.append(" createInjector() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return ");
_builder.append(Guice.class, "\t\t");
_builder.append(".createInjector(new ");
TypeReference _runtimeModule = XtextGeneratorTemplates.this.naming.getRuntimeModule(it);
_builder.append(_runtimeModule, "\t\t");
_builder.append("());");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public void register(");
_builder.append(Injector.class, "\t");
_builder.append(" injector) {");
_builder.newLineIfNotEmpty();
{
List<StringConcatenationClient> _registrations = langConfig.getRuntimeGenSetup().getRegistrations();
for (final StringConcatenationClient reg : _registrations) {
_builder.append("\t\t");
_builder.append(reg, "\t\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
return file;
}
Aggregations