Search in sources :

Example 26 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.

the class SemanticRegionFinderTest method regionForKeywordPairs2.

@Test
public void regionForKeywordPairs2() {
    @Extension final RegionAccessTestLanguageGrammarAccess.ParenthesizedElements rule = this._regionAccessTestLanguageGrammarAccess.getParenthesizedAccess();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("5 (a + ((b) + c) + d)");
    final Expression expr = this.<Expression>parseAs(_builder, Expression.class);
    final ISemanticRegionsFinder finder = this.toAccess(expr).regionForRootEObject().getAllRegionsFor();
    final String actual1 = this.pairsToString(finder.keywordPairs("(", ")"));
    final String actual2 = this.pairsToString(finder.keywordPairs(rule.getLeftParenthesisKeyword_0(), rule.getRightParenthesisKeyword_2()));
    final String expected = "(b); ((b) + c); (a + ((b) + c) + d)";
    Assert.assertEquals(expected, actual1);
    Assert.assertEquals(expected, actual2);
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) Expression(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Expression) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) RegionAccessTestLanguageGrammarAccess(org.eclipse.xtext.formatting2.regionaccess.internal.services.RegionAccessTestLanguageGrammarAccess) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder) Test(org.junit.Test)

Example 27 with Extension

use of org.eclipse.xtext.xbase.lib.Extension 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 28 with Extension

use of org.eclipse.xtext.xbase.lib.Extension 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)

Example 29 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method generateProductionGrammar.

protected void generateProductionGrammar() {
    @Extension final GrammarNaming naming = this.productionNaming;
    final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getRuntime().getSrcGen();
    this.productionGenerator.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.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) GrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming) IXtextGeneratorFileSystemAccess(org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess)

Example 30 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.

the class FormattableDocumentTest method conditionalFormatting1.

@Test
public void conditionalFormatting1() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(10));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("kwlist  kw1  kw2");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<KWList> _function_2 = new GenericFormatter<KWList>() {

            @Override
            protected void format(final KWList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                final ISubFormatter _function = (IFormattableSubDocument doc) -> {
                    @Extension final IFormattableSubDocument fits = doc.requireFitsInLine();
                    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
                        it_1.oneSpace();
                    };
                    fits.append(regions.regionFor(model).keyword("kwlist"), _function_1);
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
                        it_1.oneSpace();
                    };
                    fits.append(regions.regionFor(model).keyword("kw1"), _function_2);
                };
                final ISubFormatter _function_1 = (IFormattableSubDocument doc) -> {
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
                        it_1.newLine();
                    };
                    doc.append(regions.regionFor(model).keyword("kwlist"), _function_2);
                    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it_1) -> {
                        it_1.newLine();
                    };
                    doc.append(regions.regionFor(model).keyword("kw1"), _function_3);
                };
                document.formatConditionally(model, _function, _function_1);
            }
        };
        it.setFormatter(_function_2);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("kwlist");
        _builder_1.newLine();
        _builder_1.append("kw1");
        _builder_1.newLine();
        _builder_1.append("kw2");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) KWList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) IFormattableSubDocument(org.eclipse.xtext.formatting2.IFormattableSubDocument) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Extension(org.eclipse.xtext.xbase.lib.Extension) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) ISubFormatter(org.eclipse.xtext.formatting2.ISubFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

Extension (org.eclipse.xtext.xbase.lib.Extension)34 List (java.util.List)11 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)11 CompletionList (org.eclipse.lsp4j.CompletionList)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 Test (org.junit.Test)8 Position (org.eclipse.lsp4j.Position)6 ContentAssistGrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming)6 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)4 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)4 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)4 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)4 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)4 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)4 Set (java.util.Set)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 Data (org.eclipse.xtend.lib.annotations.Data)3 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)3 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)3 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)3