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 Constructor Description 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 Modifier and Type Method Description intadjustOffsetWithLeftWhitespaces(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)voidformat(DOMNode child, XMLFormattingConstraints parentConstraints, int start, int end, List<org.eclipse.lsp4j.TextEdit> edits)voidformatAttributeValue(DOMAttr attr, XMLFormattingConstraints parentConstraints, List<org.eclipse.lsp4j.TextEdit> edits)voidformatChildren(DOMNode currentDOMNode, XMLFormattingConstraints parentConstraints, int start, int end, List<org.eclipse.lsp4j.TextEdit> edits)static intgetExistingNewLineCount(String text, int offset, String delimiter)Return the number of new lines in the whitespaces to the left of the given offset.FormatElementCategorygetFormatElementCategory(DOMElement element, XMLFormattingConstraints parentConstraints)Returns the format element category of the given DOM element.intgetLineAtOffset(int offset)intgetLineBreakOffset(int startAttr, int start)intgetMaxLineWidth()intgetNormalizedLength(int from, int to)intgetOffsetWithPreserveLineBreaks(int from, int to, int tabSize, boolean isInsertSpaces)booleanisMaxLineWidthSupported()voidremoveLeftSpaces(int leftLimit, int to, List<org.eclipse.lsp4j.TextEdit> edits)intreplaceLeftSpacesWithIndentation(int indentLevel, int leftLimit, int to, boolean addLineSeparator, List<org.eclipse.lsp4j.TextEdit> edits)voidreplaceLeftSpacesWithIndentationPreservedNewLines(int spaceStart, int spaceEnd, int indentLevel, List<org.eclipse.lsp4j.TextEdit> edits)intreplaceLeftSpacesWithIndentationWithMultiNewLines(int indentLevel, int leftLimit, int offset, int newLineCount, List<org.eclipse.lsp4j.TextEdit> edits)intreplaceLeftSpacesWithIndentationWithOffsetSpaces(int indentSpace, int leftLimit, int to, boolean addLineSeparator, List<org.eclipse.lsp4j.TextEdit> edits)voidreplaceLeftSpacesWithOneSpace(int leftLimit, int to, List<org.eclipse.lsp4j.TextEdit> edits)booleanshouldCollapseEmptyElement(DOMElement element, SharedSettings sharedSettings)
-
-
-
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)
-
-