Search in sources :

Example 91 with TypeReference

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());
}
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 92 with TypeReference

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

Example 93 with TypeReference

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

Example 94 with TypeReference

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

Example 95 with TypeReference

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;
}
Also used : XtextPackage(org.eclipse.xtext.XtextPackage) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Grammar(org.eclipse.xtext.Grammar) BinaryGrammarResourceFactoryImpl(org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation) EList(org.eclipse.emf.common.util.EList) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) EList(org.eclipse.emf.common.util.EList) List(java.util.List) 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