Search in sources :

Example 96 with TypeReference

use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createEclipsePluginExecutableExtensionFactory.

public JavaFileAccess createEclipsePluginExecutableExtensionFactory(final IXtextGeneratorLanguage langConfig, final IXtextGeneratorLanguage activatorLanguage) {
    final Grammar grammar = langConfig.getGrammar();
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getEclipsePluginExecutableExtensionFactory(grammar));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* This class was generated. Customizations should only happen in a newly");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* introduced subclass. ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
        }
    };
    file.setTypeComment(_client);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getEclipsePluginExecutableExtensionFactory(grammar).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            TypeReference _typeRef_1 = TypeReference.typeRef("org.osgi.framework.Bundle");
            _builder.append(_typeRef_1, "\t");
            _builder.append(" getBundle() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return ");
            TypeReference _typeRef_2 = TypeReference.typeRef("org.eclipse.core.runtime.Platform");
            _builder.append(_typeRef_2, "\t\t");
            _builder.append(".getBundle(");
            TypeReference _eclipsePluginActivator = XtextGeneratorTemplates.this.naming.getEclipsePluginActivator();
            _builder.append(_eclipsePluginActivator, "\t\t");
            _builder.append(".PLUGIN_ID);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            _builder.append(Injector.class, "\t");
            _builder.append(" getInjector() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            TypeReference _eclipsePluginActivator_1 = XtextGeneratorTemplates.this.naming.getEclipsePluginActivator();
            _builder.append(_eclipsePluginActivator_1, "\t\t");
            _builder.append(" activator = ");
            TypeReference _eclipsePluginActivator_2 = XtextGeneratorTemplates.this.naming.getEclipsePluginActivator();
            _builder.append(_eclipsePluginActivator_2, "\t\t");
            _builder.append(".getInstance();");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return activator != null ? activator.getInjector(");
            TypeReference _eclipsePluginActivator_3 = XtextGeneratorTemplates.this.naming.getEclipsePluginActivator();
            _builder.append(_eclipsePluginActivator_3, "\t\t");
            _builder.append(".");
            String _replaceAll = langConfig.getGrammar().getName().toUpperCase().replaceAll("\\.", "_");
            _builder.append(_replaceAll, "\t\t");
            _builder.append(") : null;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client_1);
    return file;
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 97 with TypeReference

use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createIdeGenModule.

public JavaFileAccess createIdeGenModule(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    TypeReference _elvis = null;
    TypeReference _superClass = langConfig.getIdeGenModule().getSuperClass();
    if (_superClass != null) {
        _elvis = _superClass;
    } else {
        TypeReference _genericIdeDefaultModule = this.naming.getGenericIdeDefaultModule(it);
        _elvis = _genericIdeDefaultModule;
    }
    final TypeReference superClass = _elvis;
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getGenericIdeGenModule(it));
    file.setImportNestedTypeThreshold(JavaFileAccess.DONT_IMPORT_NESTED_TYPES);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* Manual modifications go to {@link ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getGenericIdeModule(it).getSimpleName();
            _builder.append(_simpleName, " ");
            _builder.append("}.");
            _builder.newLineIfNotEmpty();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
        }
    };
    file.setTypeComment(_client);
    List<IClassAnnotation> _annotations = file.getAnnotations();
    SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
    _annotations.add(_suppressWarningsAnnotation);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public abstract class ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getGenericIdeGenModule(it).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(superClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            {
                Set<GuiceModuleAccess.Binding> _bindings = langConfig.getIdeGenModule().getBindings();
                for (final GuiceModuleAccess.Binding binding : _bindings) {
                    _builder.append("\t");
                    StringConcatenationClient _createBindingMethod = XtextGeneratorTemplates.this.createBindingMethod(binding);
                    _builder.append(_createBindingMethod, "\t");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client_1);
    file.setMarkedAsGenerated(true);
    return file;
}
Also used : SingletonBinding(org.eclipse.xtext.service.SingletonBinding) GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)

Example 98 with TypeReference

use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createIdeSetup.

public JavaFileAccess createIdeSetup(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    boolean _isPreferXtendStubs = this.codeConfig.isPreferXtendStubs();
    if (_isPreferXtendStubs) {
        TypeReference _genericIdeSetup = this.naming.getGenericIdeSetup(it);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("/**");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Initialization support for running Xtext languages as language servers.");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*/");
                _builder.newLine();
                _builder.append("class ");
                String _simpleName = XtextGeneratorTemplates.this.naming.getGenericIdeSetup(it).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _runtimeSetup = XtextGeneratorTemplates.this.naming.getRuntimeSetup(it);
                _builder.append(_runtimeSetup);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("override createInjector() {");
                _builder.newLine();
                _builder.append("\t\t");
                _builder.append(Guice.class, "\t\t");
                _builder.append(".createInjector(");
                _builder.append(Modules2.class, "\t\t");
                _builder.append(".mixin(new ");
                TypeReference _runtimeModule = XtextGeneratorTemplates.this.naming.getRuntimeModule(it);
                _builder.append(_runtimeModule, "\t\t");
                _builder.append(", new ");
                TypeReference _genericIdeModule = XtextGeneratorTemplates.this.naming.getGenericIdeModule(it);
                _builder.append(_genericIdeModule, "\t\t");
                _builder.append("))");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        return this.fileAccessFactory.createXtendFile(_genericIdeSetup, _client);
    } else {
        TypeReference _genericIdeSetup_1 = this.naming.getGenericIdeSetup(it);
        StringConcatenationClient _client_1 = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("/**");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Initialization support for running Xtext languages as language servers.");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*/");
                _builder.newLine();
                _builder.append("public class ");
                String _simpleName = XtextGeneratorTemplates.this.naming.getGenericIdeSetup(it).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _runtimeSetup = XtextGeneratorTemplates.this.naming.getRuntimeSetup(it);
                _builder.append(_runtimeSetup);
                _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(" createInjector() {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("return ");
                _builder.append(Guice.class, "\t\t");
                _builder.append(".createInjector(");
                _builder.append(Modules2.class, "\t\t");
                _builder.append(".mixin(new ");
                TypeReference _runtimeModule = XtextGeneratorTemplates.this.naming.getRuntimeModule(it);
                _builder.append(_runtimeModule, "\t\t");
                _builder.append("(), new ");
                TypeReference _genericIdeModule = XtextGeneratorTemplates.this.naming.getGenericIdeModule(it);
                _builder.append(_genericIdeModule, "\t\t");
                _builder.append("()));");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        return this.fileAccessFactory.createJavaFile(_genericIdeSetup_1, _client_1);
    }
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 99 with TypeReference

use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createIdeaGenModule.

public JavaFileAccess createIdeaGenModule(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    TypeReference _elvis = null;
    TypeReference _superClass = langConfig.getIdeaGenModule().getSuperClass();
    if (_superClass != null) {
        _elvis = _superClass;
    } else {
        TypeReference _ideaDefaultModule = this.naming.getIdeaDefaultModule(it);
        _elvis = _ideaDefaultModule;
    }
    final TypeReference superClass = _elvis;
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getIdeaGenModule(it));
    file.setImportNestedTypeThreshold(JavaFileAccess.DONT_IMPORT_NESTED_TYPES);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* Manual modifications go to {@link ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getIdeaModule(it).getSimpleName();
            _builder.append(_simpleName, " ");
            _builder.append("}.");
            _builder.newLineIfNotEmpty();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
        }
    };
    file.setTypeComment(_client);
    List<IClassAnnotation> _annotations = file.getAnnotations();
    SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
    _annotations.add(_suppressWarningsAnnotation);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public abstract class ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getIdeaGenModule(it).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(superClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            {
                Set<GuiceModuleAccess.Binding> _bindings = langConfig.getIdeaGenModule().getBindings();
                for (final GuiceModuleAccess.Binding binding : _bindings) {
                    _builder.append("\t");
                    StringConcatenationClient _createBindingMethod = XtextGeneratorTemplates.this.createBindingMethod(binding);
                    _builder.append(_createBindingMethod, "\t");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client_1);
    return file;
}
Also used : SingletonBinding(org.eclipse.xtext.service.SingletonBinding) GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)

Example 100 with TypeReference

use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createEclipsePluginActivator.

public JavaFileAccess createEclipsePluginActivator(final IXtextProjectConfig projectConfig, final List<? extends IXtextGeneratorLanguage> langConfigs) {
    final TypeReference activator = this.naming.getEclipsePluginActivator();
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(activator);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* This class was generated. Customizations should only happen in a newly");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* introduced subclass. ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
        }
    };
    file.setTypeComment(_client);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = activator.getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.ui.plugin.AbstractUIPlugin");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public static final String PLUGIN_ID = \"");
            String _name = projectConfig.getEclipsePlugin().getName();
            _builder.append(_name, "\t");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
            {
                for (final IXtextGeneratorLanguage lang : langConfigs) {
                    _builder.append("\t");
                    _builder.append("public static final String ");
                    String _replaceAll = lang.getGrammar().getName().toUpperCase().replaceAll("\\.", "_");
                    _builder.append(_replaceAll, "\t");
                    _builder.append(" = \"");
                    String _name_1 = lang.getGrammar().getName();
                    _builder.append(_name_1, "\t");
                    _builder.append("\";");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("private static final ");
            _builder.append(Logger.class, "\t");
            _builder.append(" logger = ");
            _builder.append(Logger.class, "\t");
            _builder.append(".getLogger(");
            String _simpleName_1 = activator.getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("private static ");
            String _simpleName_2 = activator.getSimpleName();
            _builder.append(_simpleName_2, "\t");
            _builder.append(" INSTANCE;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("private ");
            _builder.append(Map.class, "\t");
            _builder.append("<String, ");
            _builder.append(Injector.class, "\t");
            _builder.append("> injectors = ");
            _builder.append(Collections.class, "\t");
            _builder.append(".synchronizedMap(");
            _builder.append(Maps.class, "\t");
            _builder.append(".<String, ");
            _builder.append(Injector.class, "\t");
            _builder.append("> newHashMapWithExpectedSize(1));");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void start(");
            TypeReference _typeRef_1 = TypeReference.typeRef("org.osgi.framework.BundleContext");
            _builder.append(_typeRef_1, "\t");
            _builder.append(" context) throws Exception {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("super.start(context);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("INSTANCE = this;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void stop(");
            TypeReference _typeRef_2 = TypeReference.typeRef("org.osgi.framework.BundleContext");
            _builder.append(_typeRef_2, "\t");
            _builder.append(" context) throws Exception {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("injectors.clear();");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("INSTANCE = null;");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("super.stop(context);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public static ");
            String _simpleName_3 = activator.getSimpleName();
            _builder.append(_simpleName_3, "\t");
            _builder.append(" getInstance() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return INSTANCE;");
            _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(" getInjector(String language) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("synchronized (injectors) {");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append(Injector.class, "\t\t\t");
            _builder.append(" injector = injectors.get(language);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("if (injector == null) {");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("injectors.put(language, injector = createInjector(language));");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("return injector;");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            _builder.append(Injector.class, "\t");
            _builder.append(" createInjector(String language) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("try {");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append(com.google.inject.Module.class, "\t\t\t");
            _builder.append(" runtimeModule = getRuntimeModule(language);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append(com.google.inject.Module.class, "\t\t\t");
            _builder.append(" sharedStateModule = getSharedStateModule();");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append(com.google.inject.Module.class, "\t\t\t");
            _builder.append(" uiModule = getUiModule(language);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append(com.google.inject.Module.class, "\t\t\t");
            _builder.append(" mergedModule = ");
            _builder.append(Modules2.class, "\t\t\t");
            _builder.append(".mixin(runtimeModule, sharedStateModule, uiModule);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("return ");
            _builder.append(Guice.class, "\t\t\t");
            _builder.append(".createInjector(mergedModule);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("} catch (Exception e) {");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("logger.error(\"Failed to create injector for \" + language);");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("logger.error(e.getMessage(), e);");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("throw new RuntimeException(\"Failed to create injector for \" + language, e);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            _builder.append(com.google.inject.Module.class, "\t");
            _builder.append(" getRuntimeModule(String grammar) {");
            _builder.newLineIfNotEmpty();
            {
                for (final IXtextGeneratorLanguage lang_1 : langConfigs) {
                    _builder.append("\t\t");
                    _builder.append("if (");
                    String _replaceAll_1 = lang_1.getGrammar().getName().toUpperCase().replaceAll("\\.", "_");
                    _builder.append(_replaceAll_1, "\t\t");
                    _builder.append(".equals(grammar)) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("return new ");
                    TypeReference _runtimeModule = XtextGeneratorTemplates.this.naming.getRuntimeModule(lang_1.getGrammar());
                    _builder.append(_runtimeModule, "\t\t\t");
                    _builder.append("();");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("}");
                    _builder.newLine();
                }
            }
            _builder.append("\t\t");
            _builder.append("throw new IllegalArgumentException(grammar);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            _builder.append(com.google.inject.Module.class, "\t");
            _builder.append(" getUiModule(String grammar) {");
            _builder.newLineIfNotEmpty();
            {
                for (final IXtextGeneratorLanguage lang_2 : langConfigs) {
                    _builder.append("\t\t");
                    _builder.append("if (");
                    String _replaceAll_2 = lang_2.getGrammar().getName().toUpperCase().replaceAll("\\.", "_");
                    _builder.append(_replaceAll_2, "\t\t");
                    _builder.append(".equals(grammar)) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("return new ");
                    TypeReference _eclipsePluginModule = XtextGeneratorTemplates.this.naming.getEclipsePluginModule(lang_2.getGrammar());
                    _builder.append(_eclipsePluginModule, "\t\t\t");
                    _builder.append("(this);");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("}");
                    _builder.newLine();
                }
            }
            _builder.append("\t\t");
            _builder.append("throw new IllegalArgumentException(grammar);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            _builder.append(com.google.inject.Module.class, "\t");
            _builder.append(" getSharedStateModule() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return new ");
            TypeReference _typeRef_3 = TypeReference.typeRef("org.eclipse.xtext.ui.shared.SharedStateModule");
            _builder.append(_typeRef_3, "\t\t");
            _builder.append("();");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client_1);
    return file;
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) IXtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.IXtextGeneratorLanguage) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Aggregations

TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)154 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)119 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)27 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)24 Grammar (org.eclipse.xtext.Grammar)23 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)21 ManifestAccess (org.eclipse.xtext.xtext.generator.model.ManifestAccess)17 List (java.util.List)14 Set (java.util.Set)12 Test (org.junit.Test)12 JavaFileAccess (org.eclipse.xtext.xtext.generator.model.JavaFileAccess)11 PluginXmlAccess (org.eclipse.xtext.xtext.generator.model.PluginXmlAccess)11 IClassAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation)10 AbstractRule (org.eclipse.xtext.AbstractRule)9 SuppressWarningsAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)8 IBundleProjectConfig (org.eclipse.xtext.xtext.generator.model.project.IBundleProjectConfig)8 ContentAssistGrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming)7 EObject (org.eclipse.emf.ecore.EObject)6 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)6 ArrayList (java.util.ArrayList)5