Class XMLFormattingConstraints

java.lang.Object
org.eclipse.lemminx.services.format.XMLFormattingConstraints

public class XMLFormattingConstraints extends Object
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>:

  1. <root> creates constraints with indentLevel=0, copies to child constraints with indentLevel=1.
  2. <a> receives indentLevel=1, copies to child constraints with indentLevel=2.
  3. <b/> receives indentLevel=2, formatted inline.
  4. </a> propagates remaining availableLineWidth back to <root>'s constraints.
Author:
Angelo ZERR
  • Constructor Details

    • XMLFormattingConstraints

      public XMLFormattingConstraints()
  • Method Details

    • copyConstraints

      public void copyConstraints(XMLFormattingConstraints constraints)
      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

      public FormatElementCategory getFormatElementCategory()
      Returns the format element category that determines whitespace handling.
      Returns:
      the current format element category.
    • setFormatElementCategory

      public void setFormatElementCategory(FormatElementCategory formatElementCategory)
      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 before maxLineWidth is 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()
      Returns true if all children should be formatted as block elements (one child per line). Only used in expand mode.

      Use case: <p>text <b>bold</b></p> with mixedContent=expand → <p>\n text\n <b>bold</b>\n</p>.

      Returns:
      true if wrap-all-children mode is active.
    • setWrapAllChildren

      public void setWrapAllChildren(boolean wrapAllChildren)
      Sets the wrap-all-children flag.
      Parameters:
      wrapAllChildren - true to force all children to block layout.
    • isSoftWrapped

      public boolean isSoftWrapped()
      Returns true if content was soft-wrapped due to maxLineWidth overflow during child formatting.
      Returns:
      true if soft wrapping occurred.
    • setSoftWrapped

      public void setSoftWrapped(boolean softWrapped)
      Sets the soft-wrapped flag.
      Parameters:
      softWrapped - true when text or element wrapping occurred.
    • isStartTagCrossedLine

      public boolean isStartTagCrossedLine()
    • setStartTagCrossedLine

      public void setStartTagCrossedLine(boolean startTagCrossedLine)