Package org.eclipse.lemminx.services.format

## Class XMLFormatterDocument

- java.lang.Object
- - org.eclipse.lemminx.services.format.XMLFormatterDocument

    public class XMLFormatterDocument
    extends Object

XML formatter which generates several text edit to remove, add, update spaces / indent.

Author:
  Angelo ZERR

### Constructor Summary

Constructors
`XMLFormatterDocument​(DOMDocument xmlDocument, org.eclipse.lsp4j.Range range, SharedSettings sharedSettings, Collection<IFormatterParticipant> formatterParticipants)` XML formatter document.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`int` `adjustOffsetWithLeftWhitespaces​(int leftLimit, int to)`
`List<? extends org.eclipse.lsp4j.TextEdit>` `format()` Returns a List containing multiple TextEdit, containing the newly formatted changes of an XML document.
`List<? extends org.eclipse.lsp4j.TextEdit>` `format​(DOMDocument document, int start, int end)`
`void` `format​(DOMNode child, XMLFormattingConstraints parentConstraints, int start, int end, List<org.eclipse.lsp4j.TextEdit> edits)`
`void` `formatAttributeValue​(DOMAttr attr, XMLFormattingConstraints parentConstraints, List<org.eclipse.lsp4j.TextEdit> edits)`
`void` `formatChildren​(DOMNode currentDOMNode, XMLFormattingConstraints parentConstraints, int start, int end, List<org.eclipse.lsp4j.TextEdit> edits)`
`static int` `getExistingNewLineCount​(String text, int offset, String delimiter)` Return the number of new lines in the whitespaces to the left of the given offset.
`FormatElementCategory` `getFormatElementCategory​(DOMElement element, XMLFormattingConstraints parentConstraints)` Returns the format element category of the given DOM element.
`int` `getLineAtOffset​(int offset)`
`int` `getLineBreakOffset​(int startAttr, int start)`
`int` `getMaxLineWidth()`
`int` `getNormalizedLength​(int from, int to)`
`int` `getOffsetWithPreserveLineBreaks​(int from, int to, int tabSize, boolean isInsertSpaces)`
`boolean` `isMaxLineWidthSupported()`
`void` `removeLeftSpaces​(int leftLimit, int to, List<org.eclipse.lsp4j.TextEdit> edits)`
`int` `replaceLeftSpacesWithIndentation​(int indentLevel, int leftLimit, int to, boolean addLineSeparator, List<org.eclipse.lsp4j.TextEdit> edits)`
`void` `replaceLeftSpacesWithIndentationPreservedNewLines​(int spaceStart, int spaceEnd, int indentLevel, List<org.eclipse.lsp4j.TextEdit> edits)`
`int` `replaceLeftSpacesWithIndentationWithMultiNewLines​(int indentLevel, int leftLimit, int offset, int newLineCount, List<org.eclipse.lsp4j.TextEdit> edits)`
`int` `replaceLeftSpacesWithIndentationWithOffsetSpaces​(int indentSpace, int leftLimit, int to, boolean addLineSeparator, List<org.eclipse.lsp4j.TextEdit> edits)`
`void` `replaceLeftSpacesWithOneSpace​(int leftLimit, int to, List<org.eclipse.lsp4j.TextEdit> edits)`
`boolean` `shouldCollapseEmptyElement​(DOMElement element, SharedSettings sharedSettings)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### XMLFormatterDocument

    public XMLFormatterDocument​(DOMDocument xmlDocument,
                                org.eclipse.lsp4j.Range range,
                                SharedSettings sharedSettings,
                                Collection<IFormatterParticipant> formatterParticipants)

XML formatter document.

### Method Detail

#### format

    public List<? extends org.eclipse.lsp4j.TextEdit> format()
                                                      throws BadLocationException

Returns a List containing multiple TextEdit, containing the newly formatted changes of an XML document.

Returns:
  List containing multiple TextEdit of an XML document.
Throws:
  `BadLocationException`

#### format

    public List<? extends org.eclipse.lsp4j.TextEdit> format​(DOMDocument document,
                                                             int start,
                                                             int end)

#### format

    public void format​(DOMNode child,
                       XMLFormattingConstraints parentConstraints,
                       int start,
                       int end,
                       List<org.eclipse.lsp4j.TextEdit> edits)

#### formatChildren

    public void formatChildren​(DOMNode currentDOMNode,
                               XMLFormattingConstraints parentConstraints,
                               int start,
                               int end,
                               List<org.eclipse.lsp4j.TextEdit> edits)

#### formatAttributeValue

    public void formatAttributeValue​(DOMAttr attr,
                                     XMLFormattingConstraints parentConstraints,
                                     List<org.eclipse.lsp4j.TextEdit> edits)

#### removeLeftSpaces

    public void removeLeftSpaces​(int leftLimit,
                                 int to,
                                 List<org.eclipse.lsp4j.TextEdit> edits)

#### replaceLeftSpacesWithOneSpace

    public void replaceLeftSpacesWithOneSpace​(int leftLimit,
                                              int to,
                                              List<org.eclipse.lsp4j.TextEdit> edits)

#### adjustOffsetWithLeftWhitespaces

    public int adjustOffsetWithLeftWhitespaces​(int leftLimit,
                                               int to)

#### replaceLeftSpacesWithIndentation

    public int replaceLeftSpacesWithIndentation​(int indentLevel,
                                                int leftLimit,
                                                int to,
                                                boolean addLineSeparator,
                                                List<org.eclipse.lsp4j.TextEdit> edits)

#### replaceLeftSpacesWithIndentationWithMultiNewLines

    public int replaceLeftSpacesWithIndentationWithMultiNewLines​(int indentLevel,
                                                                 int leftLimit,
                                                                 int offset,
                                                                 int newLineCount,
                                                                 List<org.eclipse.lsp4j.TextEdit> edits)

#### replaceLeftSpacesWithIndentationWithOffsetSpaces

    public int replaceLeftSpacesWithIndentationWithOffsetSpaces​(int indentSpace,
                                                                int leftLimit,
                                                                int to,
                                                                boolean addLineSeparator,
                                                                List<org.eclipse.lsp4j.TextEdit> edits)

#### replaceLeftSpacesWithIndentationPreservedNewLines

    public void replaceLeftSpacesWithIndentationPreservedNewLines​(int spaceStart,
                                                                  int spaceEnd,
                                                                  int indentLevel,
                                                                  List<org.eclipse.lsp4j.TextEdit> edits)

#### getNormalizedLength

    public int getNormalizedLength​(int from,
                                   int to)

#### getOffsetWithPreserveLineBreaks

    public int getOffsetWithPreserveLineBreaks​(int from,
                                               int to,
                                               int tabSize,
                                               boolean isInsertSpaces)

#### getLineBreakOffset

    public int getLineBreakOffset​(int startAttr,
                                  int start)

#### getFormatElementCategory

    public FormatElementCategory getFormatElementCategory​(DOMElement element,
                                                          XMLFormattingConstraints parentConstraints)

Returns the format element category of the given DOM element.

Parameters:
  `element` - the DOM element.
  `parentConstraints` - the parent constraints.
Returns:
  the format element category of the given DOM element.

#### shouldCollapseEmptyElement

    public boolean shouldCollapseEmptyElement​(DOMElement element,
                                              SharedSettings sharedSettings)

#### getExistingNewLineCount

    public static int getExistingNewLineCount​(String text,
                                              int offset,
                                              String delimiter)

Return the number of new lines in the whitespaces to the left of the given offset.

Parameters:
  `text` - the xml text.
  `offset` - the offset to begin the count from.
  `delimiter` - the delimiter.
Returns:
  the number of new lines in the whitespaces to the left of the given offset.

#### isMaxLineWidthSupported

    public boolean isMaxLineWidthSupported()

#### getMaxLineWidth

    public int getMaxLineWidth()

#### getLineAtOffset

    public int getLineAtOffset​(int offset)