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);
}
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());
}
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());
}
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()));
}
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);
}
Aggregations