Search in sources :

Example 1 with XtextGeneratorLanguage

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

the class XtextGenerator method initialize.

public void initialize() {
    if ((this.injector == null)) {
        XtextGenerator.LOG.info("Initializing Xtext generator");
        new StandaloneSetup().addRegisterGeneratedEPackage("org.eclipse.xtext.common.types.TypesPackage");
        this.initializeEncoding();
        this.injector = this.createInjector();
        this.injector.injectMembers(this);
        CodeConfig _instance = this.injector.<CodeConfig>getInstance(CodeConfig.class);
        final Procedure1<CodeConfig> _function = (CodeConfig it) -> {
            it.initialize(this.injector);
        };
        ObjectExtensions.<CodeConfig>operator_doubleArrow(_instance, _function);
        this.projectConfig.initialize(this.injector);
        this.cleaner.initialize(this.injector);
        this.standaloneSetup.initialize(this.injector);
        for (final XtextGeneratorLanguage language : this.languageConfigs) {
            {
                final Injector languageInjector = this.createLanguageInjector(this.injector, language);
                language.initialize(languageInjector);
            }
        }
    }
}
Also used : XtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage) IXtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.IXtextGeneratorLanguage) Injector(com.google.inject.Injector) XtextGeneratorStandaloneSetup(org.eclipse.xtext.xtext.generator.XtextGeneratorStandaloneSetup) XtextStandaloneSetup(org.eclipse.xtext.XtextStandaloneSetup) StandaloneSetup(org.eclipse.emf.mwe.utils.StandaloneSetup) CodeConfig(org.eclipse.xtext.xtext.generator.CodeConfig)

Example 2 with XtextGeneratorLanguage

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

the class XtextGenerator method generateExecutableExtensionFactory.

protected void generateExecutableExtensionFactory(final IXtextGeneratorLanguage language) {
    IXtextGeneratorFileSystemAccess _srcGen = this.projectConfig.getEclipsePlugin().getSrcGen();
    boolean _tripleNotEquals = (_srcGen != null);
    if (_tripleNotEquals) {
        this.templates.createEclipsePluginExecutableExtensionFactory(language, IterableExtensions.<XtextGeneratorLanguage>head(this.languageConfigs)).writeTo(this.projectConfig.getEclipsePlugin().getSrcGen());
    }
}
Also used : XtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage) IXtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.IXtextGeneratorLanguage) IXtextGeneratorFileSystemAccess(org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess)

Example 3 with XtextGeneratorLanguage

use of org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage 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());
}
Also used : XtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage) IXtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.IXtextGeneratorLanguage) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TextFileAccess(org.eclipse.xtext.xtext.generator.model.TextFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 4 with XtextGeneratorLanguage

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

the class XtextGenerator method checkConfigurationInternal.

@Override
protected void checkConfigurationInternal(final Issues issues) {
    this.initialize();
    final MweIssues generatorIssues = new MweIssues(this, issues);
    this.configuration.checkConfiguration(generatorIssues);
    final HashMap<String, Grammar> uris = new HashMap<String, Grammar>();
    for (final XtextGeneratorLanguage language : this.languageConfigs) {
        {
            language.checkConfiguration(generatorIssues);
            Iterable<GeneratedMetamodel> _filter = Iterables.<GeneratedMetamodel>filter(language.getGrammar().getMetamodelDeclarations(), GeneratedMetamodel.class);
            for (final GeneratedMetamodel generatedMetamodel : _filter) {
                {
                    final String nsURI = generatedMetamodel.getEPackage().getNsURI();
                    boolean _containsKey = uris.containsKey(nsURI);
                    if (_containsKey) {
                        String _name = uris.get(nsURI).getName();
                        String _plus = ((("Duplicate generated grammar with nsURI \'" + nsURI) + "\' in ") + _name);
                        String _plus_1 = (_plus + " and ");
                        String _name_1 = language.getGrammar().getName();
                        String _plus_2 = (_plus_1 + _name_1);
                        generatorIssues.addError(_plus_2);
                    } else {
                        uris.put(nsURI, language.getGrammar());
                    }
                }
            }
        }
    }
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) XtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage) IXtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.IXtextGeneratorLanguage) HashMap(java.util.HashMap) MweIssues(org.eclipse.xtext.xtext.generator.MweIssues) Grammar(org.eclipse.xtext.Grammar)

Example 5 with XtextGeneratorLanguage

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

the class XtextGenerator method invokeInternal.

@Override
protected void invokeInternal(final WorkflowContext ctx, final ProgressMonitor monitor, final Issues issues) {
    this.initialize();
    try {
        this.cleaner.clean();
        for (final XtextGeneratorLanguage language : this.languageConfigs) {
            try {
                String _name = language.getGrammar().getName();
                String _plus = ("Generating " + _name);
                XtextGenerator.LOG.info(_plus);
                language.generate();
                this.generateSetups(language);
                this.generateModules(language);
                this.generateExecutableExtensionFactory(language);
            } catch (final Throwable _t) {
                if (_t instanceof Exception) {
                    final Exception e = (Exception) _t;
                    this.handleException(e, issues);
                } else {
                    throw Exceptions.sneakyThrow(_t);
                }
            }
        }
        XtextGenerator.LOG.info("Generating common infrastructure");
        this.generatePluginXmls();
        this.generateManifests();
        this.generateActivator();
        this.generateServices();
    } catch (final Throwable _t_1) {
        if (_t_1 instanceof Exception) {
            final Exception e_1 = (Exception) _t_1;
            this.handleException(e_1, issues);
        } else {
            throw Exceptions.sneakyThrow(_t_1);
        }
    }
}
Also used : XtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage) IXtextGeneratorLanguage(org.eclipse.xtext.xtext.generator.IXtextGeneratorLanguage) CompositeGeneratorException(org.eclipse.xtext.xtext.generator.CompositeGeneratorException) IOException(java.io.IOException)

Aggregations

IXtextGeneratorLanguage (org.eclipse.xtext.xtext.generator.IXtextGeneratorLanguage)5 XtextGeneratorLanguage (org.eclipse.xtext.xtext.generator.XtextGeneratorLanguage)5 Injector (com.google.inject.Injector)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 StandaloneSetup (org.eclipse.emf.mwe.utils.StandaloneSetup)1 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)1 GeneratedMetamodel (org.eclipse.xtext.GeneratedMetamodel)1 Grammar (org.eclipse.xtext.Grammar)1 XtextStandaloneSetup (org.eclipse.xtext.XtextStandaloneSetup)1 CodeConfig (org.eclipse.xtext.xtext.generator.CodeConfig)1 CompositeGeneratorException (org.eclipse.xtext.xtext.generator.CompositeGeneratorException)1 MweIssues (org.eclipse.xtext.xtext.generator.MweIssues)1 XtextGeneratorStandaloneSetup (org.eclipse.xtext.xtext.generator.XtextGeneratorStandaloneSetup)1 IXtextGeneratorFileSystemAccess (org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess)1 TextFileAccess (org.eclipse.xtext.xtext.generator.model.TextFileAccess)1 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)1