Package org.eclipse.xtext.formatting2
Xtext formatting infrastructure since Xtext 2.8.
A formatter is responsible for arranging line-wraps, indentation, whitespace, etc. in a text document to improve its readability and emphasize its structure. A formatter is not supposed to alter a document in a way that impacts the semantic model.
This infrastructure is capable of formatting documents based on the node model and based on the serializer's output. The actual formatting is done by constructing a list of text replacements. Applying the text replacements turns the unformatted document into a formatted document. Purpose of this infrastructure is to make it convenient for implementers to construct these text replacements.
To run the formatter, you'll need to construct a FormatterRequest,
get an instance of IFormatter2 from your language's Guice Injector,
and call IFormatter2.format(FormatterRequest). The result will be a list
of text replacements. Use ITextRegionRewriter
to apply the replacements to a String/CharSequence, if desired.
To implement a formatter or to understand how to implement a formatter, see
AbstractFormatter2.
IFormatter2Use the IFormatter2 to invoke the formatterAbstractFormatter2Extend the AbstractFormatter2 to implement a formatterFormatterRequestThe FormatterRequest is a per-execution scoped configuration for the formatter. Per-language configuration is handled by the injector orAbstractFormatter2.
- Since:
- 2.8
-
Interface Summary Interface Description IAutowrapFormatter A strategy for formatting that is to be applied on auto wrapping.IFormattableDocument A FormattableDocument is a stateful object that holds a list ofreplacers.IFormattableSubDocument A sub document describes the formatting for a part of the entire document.IFormatter2 Use this interface to invoke a formatter.IHiddenRegionFormatter AnIHiddenRegionFormatteris used to build a formatting setting for a hidden region.IHiddenRegionFormatting HiddenRegionFormatting specifies formatting information for a HiddenRegion.IMerger<T> Generic interface to describe an external merger for some mergable type.ISubFormatter An ISubFormatter is responsible to format a sub document.ITextReplacer A TextReplacer is responsible for atext regioninside aIFormattableDocumentand producesreplacementsfor that region.ITextReplacerContext Relevant state and methods during execution of atext replacer. -
Class Summary Class Description AbstractFormatter2 This is an abstract base class for language-specific formatters.AbstractJavaFormatter This is an abstract base class for language-specific formatters, intended to be extended with a java class.FormatterPreferenceKeys General preference keys used by this formatting infrastructure.FormatterPreferenceValuesProvider DefaultIPreferenceValuesProviderfor a formatter.FormatterRequest A request tells the formatter what and how to format. -
Exception Summary Exception Description ConflictingFormattingException An exception to indicate that a region of the document was formatted with conflicting settings.FormattingNotApplicableException This exception can be thrown by aISubFormatterto indicate that a conditional formatting attempt failed. -
Annotation Types Summary Annotation Type Description FormatterPreferences Marks an instance ofIPreferenceValuesProvideras the one that should be used by the formatter.