Class XMLFormattingConstraints
java.lang.Object
org.eclipse.lemminx.services.format.XMLFormattingConstraints
Mutable state passed through the formatting tree to track the current
formatting context: how deep the indentation is, how much line width
remains, and which
FormatElementCategory applies.
Each element creates a copy of its parent's constraints before
formatting its children (so child formatting does not corrupt the
parent's tracking), then propagates the final
availableLineWidth back to the parent after the end tag.
Flow example for <root><a><b/></a></root>:
<root>creates constraints with indentLevel=0, copies to child constraints with indentLevel=1.<a>receives indentLevel=1, copies to child constraints with indentLevel=2.<b/>receives indentLevel=2, formatted inline.</a>propagates remaining availableLineWidth back to<root>'s constraints.
- Author:
- Angelo ZERR
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcopyConstraints(XMLFormattingConstraints constraints) Copies all constraint values from another instance.intReturns the number of characters remaining on the current line beforemaxLineWidthis exceeded.Returns the format element category that determines whitespace handling.intReturns the current indentation nesting depth.intReturns the indent level for mixed content text wrapping.booleanReturnstrueif content was soft-wrapped due tomaxLineWidthoverflow during child formatting.booleanbooleanReturnstrueif all children should be formatted as block elements (one child per line).voidsetAvailableLineWidth(int availableLineWidth) Sets the available line width.voidsetFormatElementCategory(FormatElementCategory formatElementCategory) Sets the format element category.voidsetIndentLevel(int indentLevel) Sets the indentation nesting depth.voidsetMixedContentIndentLevel(int mixedContentIndentLevel) Sets the indent level used for mixed content text wrapping.voidsetSoftWrapped(boolean softWrapped) Sets the soft-wrapped flag.voidsetStartTagCrossedLine(boolean startTagCrossedLine) voidsetWrapAllChildren(boolean wrapAllChildren) Sets the wrap-all-children flag.
-
Constructor Details
-
XMLFormattingConstraints
public XMLFormattingConstraints()
-
-
Method Details
-
copyConstraints
Copies all constraint values from another instance. Used to create child constraints from the parent before formatting an element's children.- Parameters:
constraints- the source constraints to copy from (must not be null).
-
getFormatElementCategory
Returns the format element category that determines whitespace handling.- Returns:
- the current format element category.
-
setFormatElementCategory
Sets the format element category.- Parameters:
formatElementCategory- the category to set.
-
getAvailableLineWidth
public int getAvailableLineWidth()Returns the number of characters remaining on the current line beforemaxLineWidthis exceeded.- Returns:
- remaining line width (negative means the line is overflowed).
-
setAvailableLineWidth
public void setAvailableLineWidth(int availableLineWidth) Sets the available line width.- Parameters:
availableLineWidth- the remaining width to set.
-
getIndentLevel
public int getIndentLevel()Returns the current indentation nesting depth.- Returns:
- the indent level (0 = root level).
-
setIndentLevel
public void setIndentLevel(int indentLevel) Sets the indentation nesting depth.- Parameters:
indentLevel- the indent level to set.
-
getMixedContentIndentLevel
public int getMixedContentIndentLevel()Returns the indent level for mixed content text wrapping. Zero means "not yet captured" — the regular indent level is used.- Returns:
- the mixed content indent level, or 0 if not set.
-
setMixedContentIndentLevel
public void setMixedContentIndentLevel(int mixedContentIndentLevel) Sets the indent level used for mixed content text wrapping.- Parameters:
mixedContentIndentLevel- the indent level to set.
-
isWrapAllChildren
public boolean isWrapAllChildren()Returnstrueif all children should be formatted as block elements (one child per line). Only used inexpandmode.Use case:
<p>text <b>bold</b></p>withmixedContent=expand→<p>\n text\n <b>bold</b>\n</p>.- Returns:
trueif wrap-all-children mode is active.
-
setWrapAllChildren
public void setWrapAllChildren(boolean wrapAllChildren) Sets the wrap-all-children flag.- Parameters:
wrapAllChildren-trueto force all children to block layout.
-
isSoftWrapped
public boolean isSoftWrapped()Returnstrueif content was soft-wrapped due tomaxLineWidthoverflow during child formatting.- Returns:
trueif soft wrapping occurred.
-
setSoftWrapped
public void setSoftWrapped(boolean softWrapped) Sets the soft-wrapped flag.- Parameters:
softWrapped-truewhen text or element wrapping occurred.
-
isStartTagCrossedLine
public boolean isStartTagCrossedLine() -
setStartTagCrossedLine
public void setStartTagCrossedLine(boolean startTagCrossedLine)
-