com.intellij.formatting
Interface FormattingModel


public interface FormattingModel

Defines the formatting model for a file. A formatting model defines how a file is broken into non-whitespace blocks and different types of whitespace (alignment, indents and wraps) between them.

Typically, a plugin does not need to provide a complete FormattingModel implementation - it can either use a complete implementation provided by FormattingModelProvider.createFormattingModelForPsiFile(com.intellij.psi.PsiFile, Block, com.intellij.psi.codeStyle.CodeStyleSettings) or implement the necessary extra features and delegate the rest to the factory implementation.

See Also:
FormattingModelBuilder.createModel(com.intellij.psi.PsiElement, com.intellij.psi.codeStyle.CodeStyleSettings), FormattingModelProvider.createFormattingModelForPsiFile(com.intellij.psi.PsiFile, Block, com.intellij.psi.codeStyle.CodeStyleSettings)

Method Summary
 void commitChanges()
          Commits the changes made by the formatter to the document.
 FormattingDocumentModel getDocumentModel()
          Returns the formatting document model, which allows the formatter to access information about the document containing the text to be formatted.
 Block getRootBlock()
          Returns the root block of the formatting model.
 TextRange replaceWhiteSpace(TextRange textRange, java.lang.String whiteSpace)
          Replaces the contents of the specified text range in the document with the specified text string consisting of whitespace characters.
 TextRange shiftIndentInsideRange(TextRange range, int indent)
          Indents every line except for the first in the specified text range representing a multiline block by the specified amount.
 

Method Detail

getRootBlock

@NotNull
Block getRootBlock()
Returns the root block of the formatting model. The root block corresponds to the top-level element passed to FormattingModelBuilder.createModel(com.intellij.psi.PsiElement, com.intellij.psi.codeStyle.CodeStyleSettings).

Returns:
the root block of the model.

getDocumentModel

@NotNull
FormattingDocumentModel getDocumentModel()
Returns the formatting document model, which allows the formatter to access information about the document containing the text to be formatted.

Returns:
the formatting document model.

replaceWhiteSpace

TextRange replaceWhiteSpace(TextRange textRange,
                            java.lang.String whiteSpace)
Replaces the contents of the specified text range in the document with the specified text string consisting of whitespace characters. If necessary, other characters may be inserted in addition to the passed whitespace (for example, \ characters for breaking lines in languages like Python).

Parameters:
textRange - the text range to replace with whitespace.
whiteSpace - the whitespace to replace with.
Returns:
new white space text range

shiftIndentInsideRange

TextRange shiftIndentInsideRange(TextRange range,
                                 int indent)
Indents every line except for the first in the specified text range representing a multiline block by the specified amount.

Parameters:
range - the text range to indent.
indent - the amount by which every line should be indented.
Returns:
the text range covering the block with added indents.

commitChanges

void commitChanges()
Commits the changes made by the formatter to the document. Called after the formatter has finished making all changes in a formatting operation.