Search in sources :

Example 1 with ContentAssistGrammarNaming

use of org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method generateContentAssistTokenSource.

public JavaFileAccess generateContentAssistTokenSource() {
    JavaFileAccess _xblockexpression = null;
    {
        @Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
        final JavaFileAccess file = this.fileFactory.createJavaFile(naming.getTokenSourceClass(this.getGrammar()));
        final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
            return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("BEGIN", "INDENT", "OPEN")).contains(it.getName().toUpperCase()));
        };
        final Iterable<TerminalRule> open = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function);
        final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
            return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("END", "DEDENT", "CLOSE")).contains(it.getName().toUpperCase()));
        };
        final Iterable<TerminalRule> close = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function_1);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("public class ");
                String _simpleName = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                _builder.append(AbstractIndentationTokenSource.class);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("public ");
                String _simpleName_1 = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName_1, "\t");
                _builder.append("(");
                _builder.append(TokenSource.class, "\t");
                _builder.append(" delegate) {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("super(delegate);");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected boolean shouldSplitTokenImpl(");
                _builder.append(Token.class, "\t");
                _builder.append(" token) {");
                _builder.newLineIfNotEmpty();
                {
                    final Function1<TerminalRule, TerminalRule> _function = (TerminalRule it) -> {
                        return AntlrGrammarGenUtil.<TerminalRule>getOriginalElement(it);
                    };
                    final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
                        String _upperCase = it.getName().toUpperCase();
                        return Boolean.valueOf(Objects.equal(_upperCase, "WS"));
                    };
                    boolean _exists = IterableExtensions.<TerminalRule>exists(ListExtensions.<TerminalRule, TerminalRule>map(GrammarUtil.allTerminalRules(XtextAntlrGeneratorFragment2.this.getGrammar()), _function), _function_1);
                    if (_exists) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return token.getType() == ");
                        TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass, "\t\t");
                        _builder.append(".RULE_WS;");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected int getBeginTokenType() {");
                _builder.newLine();
                {
                    int _size = IterableExtensions.size(open);
                    boolean _equals = (_size == 1);
                    if (_equals) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return ");
                        TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass_1, "\t\t");
                        _builder.append(".");
                        String _ruleName = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(open));
                        _builder.append(_ruleName, "\t\t");
                        _builder.append(";");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected int getEndTokenType() {");
                _builder.newLine();
                {
                    int _size_1 = IterableExtensions.size(close);
                    boolean _equals_1 = (_size_1 == 1);
                    if (_equals_1) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return ");
                        TypeReference _internalParserClass_2 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass_2, "\t\t");
                        _builder.append(".");
                        String _ruleName_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(close));
                        _builder.append(_ruleName_1, "\t\t");
                        _builder.append(";");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected boolean shouldEmitPendingEndTokens() {");
                _builder.newLine();
                _builder.append("\t\t");
                _builder.append("return false;");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        file.setContent(_client);
        _xblockexpression = file;
    }
    return _xblockexpression;
}
Also used : TokenSource(org.antlr.runtime.TokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Token(org.antlr.runtime.Token) JavaFileAccess(org.eclipse.xtext.xtext.generator.model.JavaFileAccess) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) TerminalRule(org.eclipse.xtext.TerminalRule)

Example 2 with ContentAssistGrammarNaming

use of org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method generateContentAssistGrammar.

protected void generateContentAssistGrammar() {
    @Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
    final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getGenericIde().getSrcGen();
    this.contentAssistGenerator.generate(this.getGrammar(), this.getOptions(), fsa);
    this.runAntlr(naming.getParserGrammar(this.getGrammar()), naming.getLexerGrammar(this.getGrammar()), fsa);
    this.simplifyUnorderedGroupPredicatesIfRequired(this.getGrammar(), fsa, naming.getInternalParserClass(this.getGrammar()));
    this.splitParserAndLexerIfEnabled(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
    this.normalizeTokens(fsa, naming.getLexerGrammar(this.getGrammar()).getTokensFileName());
    this.suppressWarnings(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
    this.normalizeLineDelimiters(fsa, naming.getLexerClass(this.getGrammar()), naming.getInternalParserClass(this.getGrammar()));
    if (this.removeBacktrackingGuards) {
        this.removeBackTrackingGuards(fsa, naming.getInternalParserClass(this.getGrammar()), this.lookaheadThreshold);
    }
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) IXtextGeneratorFileSystemAccess(org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess)

Example 3 with ContentAssistGrammarNaming

use of org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method generateContentAssistParser.

public JavaFileAccess generateContentAssistParser() {
    @Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
    final GeneratedJavaFileAccess file = this.fileFactory.createGeneratedJavaFile(naming.getParserClass(this.getGrammar()));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = naming.getParserClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _parserSuperClass = naming.getParserSuperClass(XtextAntlrGeneratorFragment2.this.getGrammar(), XtextAntlrGeneratorFragment2.this.partialParsing);
            _builder.append(_parserSuperClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            StringConcatenationClient _initNameMappings = XtextAntlrGeneratorFragment2.this.initNameMappings(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_initNameMappings, "\t");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("private ");
            TypeReference _grammarAccess = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_grammarAccess, "\t");
            _builder.append(" grammarAccess;");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_internalParserClass, "\t");
            _builder.append(" createParser() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_internalParserClass_1, "\t\t");
            _builder.append(" result = new ");
            TypeReference _internalParserClass_2 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_internalParserClass_2, "\t\t");
            _builder.append("(null);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("result.setGrammarAccess(grammarAccess);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return result;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            {
                boolean _hasSyntheticTerminalRule = XtextAntlrGeneratorFragment2.this.hasSyntheticTerminalRule();
                if (_hasSyntheticTerminalRule) {
                    _builder.append("\t");
                    _builder.append("@Override");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("protected ");
                    _builder.append(TokenSource.class, "\t");
                    _builder.append(" createLexer(");
                    _builder.append(CharStream.class, "\t");
                    _builder.append(" stream) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return new ");
                    TypeReference _tokenSourceClass = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                    _builder.append(_tokenSourceClass, "\t\t");
                    _builder.append("(super.createLexer(stream));");
                    _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 String getRuleName(");
            _builder.append(AbstractElement.class, "\t");
            _builder.append(" element) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return nameMappings.getRuleName(element);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected String[] getInitialHiddenTokens() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return new String[] { ");
            {
                List<String> _initialHiddenTokens = XtextAntlrGeneratorFragment2.this.grammarUtil.initialHiddenTokens(XtextAntlrGeneratorFragment2.this.getGrammar());
                boolean _hasElements = false;
                for (final String hidden : _initialHiddenTokens) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate(", ", "\t\t");
                    }
                    _builder.append("\"");
                    _builder.append(hidden, "\t\t");
                    _builder.append("\"");
                }
            }
            _builder.append(" };");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            TypeReference _grammarAccess_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_grammarAccess_1, "\t");
            _builder.append(" getGrammarAccess() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return this.grammarAccess;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void setGrammarAccess(");
            TypeReference _grammarAccess_2 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_grammarAccess_2, "\t");
            _builder.append(" grammarAccess) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("this.grammarAccess = grammarAccess;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public NameMappings getNameMappings() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return nameMappings;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void setNameMappings(NameMappings nameMappings) {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("this.nameMappings = nameMappings;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client);
    return file;
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) TokenSource(org.antlr.runtime.TokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) List(java.util.List) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) CharStream(org.antlr.runtime.CharStream)

Example 4 with ContentAssistGrammarNaming

use of org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method addUiBindingsAndImports.

protected void addUiBindingsAndImports() {
    @Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
    final TypeReference caLexerClass = naming.getLexerClass(this.getGrammar());
    ManifestAccess _manifest = this.getProjectConfig().getGenericIde().getManifest();
    boolean _tripleNotEquals = (_manifest != null);
    if (_tripleNotEquals) {
        ManifestAccess _manifest_1 = this.getProjectConfig().getGenericIde().getManifest();
        final Procedure1<ManifestAccess> _function = (ManifestAccess it) -> {
            Set<String> _exportedPackages = it.getExportedPackages();
            String _packageName = caLexerClass.getPackageName();
            String _packageName_1 = naming.getParserClass(this.getGrammar()).getPackageName();
            String _packageName_2 = naming.getInternalParserClass(this.getGrammar()).getPackageName();
            Iterables.<String>addAll(_exportedPackages, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_packageName, _packageName_1, _packageName_2)));
        };
        ObjectExtensions.<ManifestAccess>operator_doubleArrow(_manifest_1, _function);
    }
    GuiceModuleAccess.BindingFactory _addTypeToType = new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.contentassist.IProposalConflictHelper"), TypeReference.typeRef("org.eclipse.xtext.ui.editor.contentassist.antlr.AntlrProposalConflictHelper"));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            TypeReference _lexerSuperClass = naming.getLexerSuperClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_lexerSuperClass);
            _builder.append(".class)");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".annotatedWith(");
            _builder.append(Names.class, "\t");
            _builder.append(".named(");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ide.LexerIdeBindings");
            _builder.append(_typeRef, "\t");
            _builder.append(".CONTENT_ASSIST))");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".to(");
            _builder.append(caLexerClass, "\t");
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
        }
    };
    GuiceModuleAccess.BindingFactory _addConfiguredBinding = _addTypeToType.addConfiguredBinding("ContentAssistLexer", _client);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            _builder.append(Lexer.class);
            _builder.append(".class)");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".annotatedWith(");
            _builder.append(Names.class, "\t");
            _builder.append(".named(");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ide.LexerIdeBindings");
            _builder.append(_typeRef, "\t");
            _builder.append(".HIGHLIGHTING))");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".to(");
            TypeReference _lexerClass = XtextAntlrGeneratorFragment2.this.productionNaming.getLexerClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_lexerClass, "\t");
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
        }
    };
    GuiceModuleAccess.BindingFactory _addConfiguredBinding_1 = _addConfiguredBinding.addConfiguredBinding("HighlightingLexer", _client_1);
    StringConcatenationClient _client_2 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            _builder.append(ITokenDefProvider.class);
            _builder.append(".class)");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".annotatedWith(");
            _builder.append(Names.class, "\t");
            _builder.append(".named(");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ide.LexerIdeBindings");
            _builder.append(_typeRef, "\t");
            _builder.append(".HIGHLIGHTING))");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".to(");
            _builder.append(AntlrTokenDefProvider.class, "\t");
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
        }
    };
    GuiceModuleAccess.BindingFactory _addConfiguredBinding_2 = _addConfiguredBinding_1.addConfiguredBinding("HighlightingTokenDefProvider", _client_2);
    TypeReference _typeReference = new TypeReference("org.eclipse.xtext.ui.editor.contentassist", "ContentAssistContext.Factory");
    GuiceModuleAccess.BindingFactory _addTypeToType_1 = _addConfiguredBinding_2.addTypeToType(_typeReference, TypeReference.typeRef("org.eclipse.xtext.ui.editor.contentassist.antlr.DelegatingContentAssistContextFactory")).addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.IContentAssistParser"), naming.getParserClass(this.getGrammar()));
    StringConcatenationClient _client_3 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            _builder.append(caLexerClass);
            _builder.append(".class).toProvider(");
            _builder.append(LexerProvider.class);
            _builder.append(".create(");
            _builder.append(caLexerClass);
            _builder.append(".class));");
            _builder.newLineIfNotEmpty();
        }
    };
    final GuiceModuleAccess.BindingFactory uiBindings = _addTypeToType_1.addConfiguredBinding("ContentAssistLexerProvider", _client_3);
    boolean _hasSyntheticTerminalRule = this.hasSyntheticTerminalRule();
    if (_hasSyntheticTerminalRule) {
        uiBindings.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.CompletionPrefixProvider"), TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.IndentationAwareCompletionPrefixProvider"));
    }
    uiBindings.contributeTo(this.getLanguage().getEclipsePluginGenModule());
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) Set(java.util.Set) ManifestAccess(org.eclipse.xtext.xtext.generator.model.ManifestAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 5 with ContentAssistGrammarNaming

use of org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method addIdeBindingsAndImports.

protected void addIdeBindingsAndImports() {
    @Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
    ManifestAccess _manifest = this.getProjectConfig().getGenericIde().getManifest();
    boolean _tripleNotEquals = (_manifest != null);
    if (_tripleNotEquals) {
        ManifestAccess _manifest_1 = this.getProjectConfig().getGenericIde().getManifest();
        final Procedure1<ManifestAccess> _function = (ManifestAccess it) -> {
            Set<String> _exportedPackages = it.getExportedPackages();
            String _packageName = naming.getLexerClass(this.getGrammar()).getPackageName();
            String _packageName_1 = naming.getParserClass(this.getGrammar()).getPackageName();
            String _packageName_2 = naming.getInternalParserClass(this.getGrammar()).getPackageName();
            Iterables.<String>addAll(_exportedPackages, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_packageName, _packageName_1, _packageName_2)));
            Set<String> _requiredBundles = it.getRequiredBundles();
            _requiredBundles.add("org.antlr.runtime");
        };
        ObjectExtensions.<ManifestAccess>operator_doubleArrow(_manifest_1, _function);
    }
    GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            TypeReference _lexerSuperClass = naming.getLexerSuperClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_lexerSuperClass);
            _builder.append(".class)");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".annotatedWith(");
            _builder.append(Names.class, "\t");
            _builder.append(".named(");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ide.LexerIdeBindings");
            _builder.append(_typeRef, "\t");
            _builder.append(".CONTENT_ASSIST))");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".to(");
            TypeReference _lexerClass = naming.getLexerClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_lexerClass, "\t");
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
        }
    };
    final GuiceModuleAccess.BindingFactory ideBindings = _bindingFactory.addConfiguredBinding("ContentAssistLexer", _client).addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.IContentAssistParser"), naming.getParserClass(this.getGrammar())).addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.IProposalConflictHelper"), TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.AntlrProposalConflictHelper"));
    if (this.partialParsing) {
        ideBindings.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory"), TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.PartialContentAssistContextFactory"));
    }
    boolean _hasSyntheticTerminalRule = this.hasSyntheticTerminalRule();
    if (_hasSyntheticTerminalRule) {
        ideBindings.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.CompletionPrefixProvider"), TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.IndentationAwareCompletionPrefixProvider"));
    }
    ideBindings.contributeTo(this.getLanguage().getIdeGenModule());
}
Also used : GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) Extension(org.eclipse.xtext.xbase.lib.Extension) ManifestAccess(org.eclipse.xtext.xtext.generator.model.ManifestAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Aggregations

ContentAssistGrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming)5 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)4 Extension (org.eclipse.xtext.xbase.lib.Extension)4 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)4 Set (java.util.Set)2 TokenSource (org.antlr.runtime.TokenSource)2 AbstractIndentationTokenSource (org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource)2 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)2 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)2 ManifestAccess (org.eclipse.xtext.xtext.generator.model.ManifestAccess)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CharStream (org.antlr.runtime.CharStream)1 Token (org.antlr.runtime.Token)1 TerminalRule (org.eclipse.xtext.TerminalRule)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1 IXtextGeneratorFileSystemAccess (org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess)1 JavaFileAccess (org.eclipse.xtext.xtext.generator.model.JavaFileAccess)1