use of org.eclipse.xtext.formatting2.IFormatter2 in project xtext-core by eclipse.
the class FormattingService method format2.
protected List<ITextReplacement> format2(final XtextResource resource, final ITextRegion selection, final ITypedPreferenceValues preferences) {
final FormatterRequest request = this.formatterRequestProvider.get();
request.setAllowIdentityEdits(false);
request.setFormatUndefinedHiddenRegionsOnly(false);
if ((selection != null)) {
request.setRegions(Collections.<ITextRegion>unmodifiableList(CollectionLiterals.<ITextRegion>newArrayList(selection)));
}
if ((preferences != null)) {
request.setPreferences(preferences);
}
final ITextRegionAccess regionAccess = this.regionBuilder.forNodeModel(resource).create();
request.setTextRegionAccess(regionAccess);
final IFormatter2 formatter2 = this.formatter2Provider.get();
final List<ITextReplacement> replacements = formatter2.format(request);
return replacements;
}
use of org.eclipse.xtext.formatting2.IFormatter2 in project xtext-core by eclipse.
the class Formatter2Fragment2 method generate.
@Override
public void generate() {
boolean _isGenerateStub = this.isGenerateStub();
boolean _not = (!_isGenerateStub);
if (_not) {
return;
}
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("binder.bind(");
_builder.append(IPreferenceValuesProvider.class);
_builder.append(".class).annotatedWith(");
_builder.append(FormatterPreferences.class);
_builder.append(".class).to(");
_builder.append(FormatterPreferenceValuesProvider.class);
_builder.append(".class);");
}
};
final StringConcatenationClient statement = _client;
new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IFormatter2.class), this.getFormatter2Stub(this.getLanguage().getGrammar())).addConfiguredBinding(FormatterPreferences.class.getSimpleName(), statement).contributeTo(this.getLanguage().getRuntimeGenModule());
new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory"), TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory")).contributeTo(this.getLanguage().getEclipsePluginGenModule());
ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
boolean _tripleNotEquals = (_manifest != null);
if (_tripleNotEquals) {
Set<String> _exportedPackages = this.getProjectConfig().getRuntime().getManifest().getExportedPackages();
String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
String _plus = (_runtimeBasePackage + ".formatting2");
_exportedPackages.add(_plus);
}
this.doGenerateStubFile();
}
use of org.eclipse.xtext.formatting2.IFormatter2 in project xtext-core by eclipse.
the class Serializer method serialize.
protected void serialize(EObject obj, Appendable appendable, SaveOptions options) throws IOException {
ITextRegionAccess regionAccess = serializeToRegions(obj);
FormatterRequest request = formatterRequestProvider.get();
request.setFormatUndefinedHiddenRegionsOnly(!options.isFormatting());
request.setTextRegionAccess(regionAccess);
IFormatter2 formatter2 = formatter2Provider.get();
List<ITextReplacement> replacements = formatter2.format(request);
regionAccess.getRewriter().renderToAppendable(replacements, appendable);
}
use of org.eclipse.xtext.formatting2.IFormatter2 in project xtext-core by eclipse.
the class RegionDiffFormatter method format.
public List<ITextReplacement> format(ITextRegionAccess regions) {
IFormatter2 fmt = getFormatter();
if (regions instanceof ITextRegionAccessDiff) {
ITextRegionAccessDiff diff = (ITextRegionAccessDiff) regions;
FormatterRequest request = createFormatterRequest(diff);
List<ITextReplacement> replacements = fmt.format(request);
List<ITextReplacement> merged = mergeReplacements(diff, replacements);
return merged;
} else {
FormatterRequest request = createFormatterRequest(regions);
List<ITextReplacement> replacements = fmt.format(request);
return replacements;
}
}
Aggregations