Search in sources :

Example 1 with Binding

use of org.eclipse.xtext.generator.Binding in project xtext-eclipse by eclipse.

the class IdeaPluginGenerator method compileGuiceModuleIdeaGenerated.

public CharSequence compileGuiceModuleIdeaGenerated(final Grammar grammar, final Set<Binding> bindings) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package ");
    String _packageName = this._ideaPluginClassNames.toPackageName(this._ideaPluginClassNames.getAbstractIdeaModuleName(grammar));
    _builder.append(_packageName);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("public class ");
    String _simpleName = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getAbstractIdeaModuleName(grammar));
    _builder.append(_simpleName);
    _builder.append(" extends org.eclipse.xtext.idea.DefaultIdeaModule {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.newLine();
    {
        for (final Binding it : bindings) {
            {
                if (((!it.getValue().isProvider()) && ((List<String>) Conversions.doWrapArray(it.getValue().getStatements())).isEmpty())) {
                    _builder.append("\t");
                    _builder.append("// contributed by ");
                    String _contributedBy = it.getContributedBy();
                    _builder.append(_contributedBy, "\t");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    {
                        boolean _isSingleton = it.getKey().isSingleton();
                        if (_isSingleton) {
                            _builder.append("@org.eclipse.xtext.service.SingletonBinding");
                            {
                                boolean _isEagerSingleton = it.getKey().isEagerSingleton();
                                if (_isEagerSingleton) {
                                    _builder.append("(eager=true)");
                                }
                            }
                        }
                    }
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("public ");
                    {
                        String _expression = it.getValue().getExpression();
                        boolean _tripleEquals = (_expression == null);
                        if (_tripleEquals) {
                            _builder.append("Class<? extends ");
                            String _type = it.getKey().getType();
                            _builder.append(_type, "\t");
                            _builder.append(">");
                        } else {
                            String _type_1 = it.getKey().getType();
                            _builder.append(_type_1, "\t");
                        }
                    }
                    _builder.append(" ");
                    String _bindMethodName = this.bindMethodName(it);
                    _builder.append(_bindMethodName, "\t");
                    _builder.append("() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return ");
                    {
                        String _expression_1 = it.getValue().getExpression();
                        boolean _tripleNotEquals = (_expression_1 != null);
                        if (_tripleNotEquals) {
                            String _expression_2 = it.getValue().getExpression();
                            _builder.append(_expression_2, "\t\t");
                        } else {
                            String _typeName = it.getValue().getTypeName();
                            _builder.append(_typeName, "\t\t");
                            _builder.append(".class");
                        }
                    }
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                } else {
                    boolean _isEmpty = ((List<String>) Conversions.doWrapArray(it.getValue().getStatements())).isEmpty();
                    if (_isEmpty) {
                        _builder.append("\t");
                        _builder.append("// contributed by ");
                        String _contributedBy_1 = it.getContributedBy();
                        _builder.append(_contributedBy_1, "\t");
                        _builder.newLineIfNotEmpty();
                        _builder.append("\t");
                        {
                            boolean _isSingleton_1 = it.getKey().isSingleton();
                            if (_isSingleton_1) {
                                _builder.append("@org.eclipse.xtext.service.SingletonBinding");
                                {
                                    boolean _isEagerSingleton_1 = it.getKey().isEagerSingleton();
                                    if (_isEagerSingleton_1) {
                                        _builder.append("(eager=true)");
                                    }
                                }
                            }
                        }
                        _builder.newLineIfNotEmpty();
                        _builder.append("\t");
                        _builder.append("public ");
                        {
                            String _expression_3 = it.getValue().getExpression();
                            boolean _tripleEquals_1 = (_expression_3 == null);
                            if (_tripleEquals_1) {
                                _builder.append("Class<? extends com.google.inject.Provider<");
                                String _type_2 = it.getKey().getType();
                                _builder.append(_type_2, "\t");
                                _builder.append(">>");
                            } else {
                                _builder.append("com.google.inject.Provider<");
                                String _type_3 = it.getKey().getType();
                                _builder.append(_type_3, "\t");
                                _builder.append(">");
                            }
                        }
                        _builder.append(" ");
                        String _bindMethodName_1 = this.bindMethodName(it);
                        _builder.append(_bindMethodName_1, "\t");
                        _builder.append("() {");
                        _builder.newLineIfNotEmpty();
                        _builder.append("\t");
                        _builder.append("\t");
                        _builder.append("return ");
                        {
                            String _expression_4 = it.getValue().getExpression();
                            boolean _tripleNotEquals_1 = (_expression_4 != null);
                            if (_tripleNotEquals_1) {
                                String _expression_5 = it.getValue().getExpression();
                                _builder.append(_expression_5, "\t\t");
                            } else {
                                String _typeName_1 = it.getValue().getTypeName();
                                _builder.append(_typeName_1, "\t\t");
                                _builder.append(".class");
                            }
                        }
                        _builder.append(";");
                        _builder.newLineIfNotEmpty();
                        _builder.append("\t");
                        _builder.append("}");
                        _builder.newLine();
                    } else {
                        _builder.append("\t");
                        _builder.append("// contributed by ");
                        String _contributedBy_2 = it.getContributedBy();
                        _builder.append(_contributedBy_2, "\t");
                        _builder.newLineIfNotEmpty();
                        _builder.append("\t");
                        _builder.append("public void ");
                        String _bindMethodName_2 = this.bindMethodName(it);
                        _builder.append(_bindMethodName_2, "\t");
                        _builder.append("(com.google.inject.Binder binder) {");
                        _builder.newLineIfNotEmpty();
                        {
                            String[] _statements = it.getValue().getStatements();
                            for (final String statement : _statements) {
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append(statement, "\t\t");
                                {
                                    boolean _endsWith = statement.endsWith(";");
                                    boolean _not = (!_endsWith);
                                    if (_not) {
                                        _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();
    return _builder;
}
Also used : Binding(org.eclipse.xtext.generator.Binding) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List)

Example 2 with Binding

use of org.eclipse.xtext.generator.Binding in project dsl-devkit by dsldevkit.

the class BuilderIntegrationFragment method getGuiceBindingsUi.

/**
 * {@inheritDoc}
 */
@Override
public Set<Binding> getGuiceBindingsUi(final Grammar grammar) {
    final Set<Binding> bindings = super.getGuiceBindingsUi(grammar);
    final BindFactory factory = new BindFactory();
    factory.addConfiguredBinding(IResourceDescriptions.class.getName() + "BuilderScope", "binder.bind(" + IResourceDescriptions.class.getName() + ".class" + ").annotatedWith(com.google.inject.name.Names.named(" + ResourceDescriptionsProvider.class.getName() + ".NAMED_BUILDER_SCOPE)).to(" + "com.avaloq.tools.ddk.xtext.builder.CurrentDescriptions2.ResourceSetAware.class)");
    final Set<Binding> result = factory.getBindings();
    result.addAll(bindings);
    return result;
}
Also used : Binding(org.eclipse.xtext.generator.Binding) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) BindFactory(org.eclipse.xtext.generator.BindFactory)

Example 3 with Binding

use of org.eclipse.xtext.generator.Binding in project dsl-devkit by dsldevkit.

the class BuilderIntegrationFragment method getGuiceBindingsRt.

@Override
public Set<Binding> getGuiceBindingsRt(final Grammar grammar) {
    final Set<Binding> bindings = super.getGuiceBindingsRt(grammar);
    final BindFactory factory = new BindFactory();
    factory.addTypeToType(IContainer.Manager.class.getName(), "com.avaloq.tools.ddk.xtext.builder.CachingStateBasedContainerManager");
    factory.addTypeToType(LazyLinkingResource.class.getName(), LazyLinkingResource2.class.getName());
    factory.addTypeToType(LazyURIEncoder.class.getName(), FastLazyURIEncoder.class.getName());
    final Set<Binding> result = factory.getBindings();
    result.addAll(bindings);
    return result;
}
Also used : Binding(org.eclipse.xtext.generator.Binding) FastLazyURIEncoder(com.avaloq.tools.ddk.xtext.linking.FastLazyURIEncoder) LazyLinkingResource2(com.avaloq.tools.ddk.xtext.linking.LazyLinkingResource2) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) FastLazyURIEncoder(com.avaloq.tools.ddk.xtext.linking.FastLazyURIEncoder) LazyURIEncoder(org.eclipse.xtext.linking.lazy.LazyURIEncoder) BindFactory(org.eclipse.xtext.generator.BindFactory)

Example 4 with Binding

use of org.eclipse.xtext.generator.Binding in project xtext-eclipse by eclipse.

the class IdeaPluginGenerator method generate.

@Override
public void generate(final Grammar grammar, final Xtend2ExecutionContext ctx) {
    this._xtextIDEAGeneratorExtensions.installOutlets(ctx, this.ideaProjectPath, this.encoding, this.getNaming().getLineDelimiter());
    String outlet_src_gen = this._xtextIDEAGeneratorExtensions.getSrcGenOutlet(ctx).getName();
    String _xifexpression = null;
    if (this.srcGenOnly) {
        _xifexpression = outlet_src_gen;
    } else {
        _xifexpression = this._xtextIDEAGeneratorExtensions.getSrcOutlet(ctx).getName();
    }
    String outlet_src = _xifexpression;
    final BindFactory bindFactory = new BindFactory();
    bindFactory.addTypeToType("org.eclipse.xtext.parser.antlr.IAntlrTokenFileProvider", this._ideaPluginClassNames.getAntlrTokenFileProvider(grammar));
    bindFactory.addTypeToType("org.eclipse.xtext.parser.antlr.Lexer", this._ideaPluginClassNames.getPsiInternalLexerName(grammar));
    String _psiInternalLexerName = this._ideaPluginClassNames.getPsiInternalLexerName(grammar);
    String _plus = (((("binder.bind(org.eclipse.xtext.parser.antlr.Lexer.class)" + ".annotatedWith(com.google.inject.name.Names.named(") + "org.eclipse.xtext.parser.antlr.LexerBindings.RUNTIME") + ")).to(") + _psiInternalLexerName);
    String _plus_1 = (_plus + ".class)");
    bindFactory.addConfiguredBinding("RuntimeLexer", _plus_1);
    bindFactory.addTypeToType("com.intellij.lang.PsiParser", this._ideaPluginClassNames.getPsiParserName(grammar));
    bindFactory.addTypeToType("org.eclipse.xtext.idea.parser.TokenTypeProvider", this._ideaPluginClassNames.getTokenTypeProviderName(grammar));
    bindFactory.addTypeToType("com.intellij.lang.ParserDefinition", this._ideaPluginClassNames.getParserDefinitionName(grammar));
    bindFactory.addTypeToTypeSingleton("org.eclipse.xtext.idea.lang.IElementTypeProvider", this._ideaPluginClassNames.getElementTypeProviderName(grammar));
    bindFactory.addTypeToType("org.eclipse.xtext.idea.facet.AbstractFacetConfiguration", this._ideaPluginClassNames.getFacetConfiguration(grammar));
    String _facetTypeName = this._ideaPluginClassNames.getFacetTypeName(grammar);
    String _plus_2 = (_facetTypeName + ".TYPEID");
    bindFactory.addTypeToInstance("com.intellij.facet.FacetTypeId", _plus_2);
    boolean _doesUseXbase = XbaseGeneratorFragment.doesUseXbase(grammar);
    if (_doesUseXbase) {
        bindFactory.addTypeToType("org.eclipse.xtext.common.types.xtext.AbstractTypeScopeProvider", "org.eclipse.xtext.idea.common.types.StubBasedTypeScopeProvider");
        bindFactory.addTypeToType("org.eclipse.xtext.xbase.typesystem.internal.IFeatureScopeTracker.Provider", "org.eclipse.xtext.xbase.typesystem.internal.OptimizingFeatureScopeTrackerProvider");
        bindFactory.addConfiguredBinding("LanguageSpecificPsiModelAssociations", (("binder.bind(org.eclipse.xtext.psi.IPsiModelAssociations.class)." + "annotatedWith(org.eclipse.xtext.service.LanguageSpecific.class).") + "to(org.eclipse.xtext.idea.common.types.DerivedMemberAwarePsiModelAssociations.class)"));
        bindFactory.addTypeToType("org.eclipse.xtext.idea.highlighting.IHighlightingConfiguration", "org.eclipse.xtext.xbase.idea.highlighting.XbaseHighlightingConfiguration");
        bindFactory.addTypeToType("org.eclipse.xtext.idea.formatting.BlockFactory", "org.eclipse.xtext.xbase.idea.formatting.XbaseBlockFactory");
        bindFactory.addTypeToType("org.eclipse.xtext.idea.formatting.ChildAttributesProvider", "org.eclipse.xtext.xbase.idea.formatting.XbaseChildAttributesProvider");
        bindFactory.addTypeToType("org.eclipse.xtext.ide.editor.bracketmatching.IBracePairProvider", "org.eclipse.xtext.xbase.idea.bracketmatching.XbaseBracePairProvider");
        bindFactory.addTypeToType("org.eclipse.xtext.idea.findusages.IReferenceSearcher", "org.eclipse.xtext.xbase.idea.findusages.JvmElementAwareReferenceSearcher");
        bindFactory.addTypeToType("org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider", "org.eclipse.xtext.xbase.idea.facet.XbaseGeneratorConfigProvider");
        bindFactory.addTypeToType("org.eclipse.xtext.idea.findusages.WordsScannerProvider", "org.eclipse.xtext.xbase.idea.findusages.XbaseWordsScanner.XbaseWordsScannerProvider");
    }
    final Set<Binding> bindings = bindFactory.getBindings();
    ctx.writeFile(outlet_src, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getStandaloneSetupIdea(grammar)), this.compileStandaloneSetup(grammar));
    ctx.writeFile(outlet_src, this._ideaPluginClassNames.toXtendPath(this._ideaPluginClassNames.getIdeaSetup(grammar)), this.compileIdeaSetup(grammar));
    ctx.writeFile(outlet_src, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getIdeaModuleName(grammar)), this.compileIdeaModule(grammar));
    ctx.writeFile(outlet_src, this._ideaPluginClassNames.toXtendPath(this._ideaPluginClassNames.getCompletionContributor(grammar)), this.compileCompletionContributor(grammar));
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("META-INF/services/");
    String _name = ISetup.class.getName();
    _builder.append(_name);
    ctx.writeFile(outlet_src_gen, _builder.toString(), this.compileServicesISetup(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getAbstractCompletionContributor(grammar)), this.compileAbstractCompletionContributor(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getLanguageName(grammar)), this.compileLanguage(grammar));
    ctx.writeFile(outlet_src, this._ideaPluginClassNames.toXtendPath(this._ideaPluginClassNames.getFileTypeName(grammar)), this.compileFileType(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getAbstractFileTypeName(grammar)), this.compileAbstractFileType(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getFileTypeFactoryName(grammar)), this.compileFileTypeFactory(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getFileImplName(grammar)), this.compileFileImpl(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getTokenTypeProviderName(grammar)), this.compileTokenTypeProvider(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getElementTypeProviderName(grammar)), this.compileElementTypeProvider(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getParserDefinitionName(grammar)), this.compileParserDefinition(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getSyntaxHighlighterFactoryName(grammar)), this.compileSyntaxHighlighterFactory(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getSemanticHighlightVisitorName(grammar)), this.compileSemanticHighlightVisitor(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getAbstractIdeaModuleName(grammar)), this.compileGuiceModuleIdeaGenerated(grammar, bindings));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getExtensionFactoryName(grammar)), this.compileExtensionFactory(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getCodeBlockModificationListenerName(grammar)), this.compileCodeBlockModificationListener(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getPsiParserName(grammar)), this.compilePsiParser(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getAntlrTokenFileProvider(grammar)), this.compileAntlrTokenFileProvider(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getPomDeclarationSearcherName(grammar)), this.compilePomDeclarationSearcher(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getFacetTypeName(grammar)), this.compileFacetType(grammar));
    ctx.writeFile(outlet_src, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.getFacetConfiguration(grammar)), this.compileFacetConfiguration(grammar));
    ctx.writeFile(outlet_src_gen, this._ideaPluginClassNames.toJavaPath(this._ideaPluginClassNames.baseColorSettingsPage(grammar)), this.compileBaseColorSettingsPage(grammar));
    ctx.writeFile(outlet_src, this._ideaPluginClassNames.toXtendPath(this._ideaPluginClassNames.colorSettingsPage(grammar)), this.compileColorSettingsPage(grammar));
    OutputImpl output = new OutputImpl();
    this.addOutlet(output, IdeaPluginGenerator.PLUGIN, false, this.ideaProjectPath);
    this.addOutlet(output, IdeaPluginGenerator.META_INF_PLUGIN, false, (this.ideaProjectPath + "/META-INF"));
    this.addOutlet(output, IdeaPluginGenerator.META_INF_PLUGIN_GEN, true, (this.ideaProjectPath + "/META-INF"));
    if (this.deployable) {
        this.writeFile(output, IdeaPluginGenerator.META_INF_PLUGIN, "plugin.xml", this.compilePluginXml(grammar));
        this.writeFile(output, IdeaPluginGenerator.META_INF_PLUGIN_GEN, "plugin_gen.xml", this.compilePluginGenXml(grammar));
    }
}
Also used : Binding(org.eclipse.xtext.generator.Binding) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) BindFactory(org.eclipse.xtext.generator.BindFactory) OutputImpl(org.eclipse.xpand2.output.OutputImpl)

Example 5 with Binding

use of org.eclipse.xtext.generator.Binding in project dsl-devkit by dsldevkit.

the class FormatterFragment method getGuiceBindingsRt.

@Override
public Set<Binding> getGuiceBindingsRt(final Grammar grammar) {
    final Set<Binding> bindings = super.getGuiceBindingsRt(grammar);
    BindFactory bindFactory = new BindFactory();
    bindings.addAll(bindFactory.addTypeToType(INodeModelFormatter.class.getName(), RegionNodeModelFormatter.class.getName()).getBindings());
    bindings.addAll(bindFactory.addTypeToType(INodeModelStreamer.class.getName(), DirectNodeModelStreamer.class.getName()).getBindings());
    return bindings;
}
Also used : Binding(org.eclipse.xtext.generator.Binding) DirectNodeModelStreamer(com.avaloq.tools.ddk.xtext.formatting.DirectNodeModelStreamer) INodeModelStreamer(org.eclipse.xtext.formatting.INodeModelStreamer) INodeModelFormatter(org.eclipse.xtext.formatting.INodeModelFormatter) RegionNodeModelFormatter(com.avaloq.tools.ddk.xtext.formatting.RegionNodeModelFormatter) BindFactory(org.eclipse.xtext.generator.BindFactory)

Aggregations

Binding (org.eclipse.xtext.generator.Binding)5 BindFactory (org.eclipse.xtext.generator.BindFactory)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 DirectNodeModelStreamer (com.avaloq.tools.ddk.xtext.formatting.DirectNodeModelStreamer)1 RegionNodeModelFormatter (com.avaloq.tools.ddk.xtext.formatting.RegionNodeModelFormatter)1 FastLazyURIEncoder (com.avaloq.tools.ddk.xtext.linking.FastLazyURIEncoder)1 LazyLinkingResource2 (com.avaloq.tools.ddk.xtext.linking.LazyLinkingResource2)1 List (java.util.List)1 OutputImpl (org.eclipse.xpand2.output.OutputImpl)1 INodeModelFormatter (org.eclipse.xtext.formatting.INodeModelFormatter)1 INodeModelStreamer (org.eclipse.xtext.formatting.INodeModelStreamer)1 LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)1 LazyURIEncoder (org.eclipse.xtext.linking.lazy.LazyURIEncoder)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1