Package org.eclipse.xtext.formatting2

Xtext formatting infrastructure since Xtext 2.8.

See: Description

Package org.eclipse.xtext.formatting2 Description

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.

Since:
2.8
Author:
Moritz Eysholdt - Initial contribution and API
See Also:
Use the IFormatter2 to invoke the formatter, Extend the AbstractFormatter2 to implement a formatter, The FormatterRequest is a per-execution scoped configuration for the formatter. Per-language configuration is handled by the injector or {@link org.eclipse.xtext.formatting2.AbstractFormatter2}.