Enum Class FormatElementCategory

java.lang.Object
java.lang.Enum<FormatElementCategory>
org.eclipse.lemminx.services.format.FormatElementCategory
All Implemented Interfaces:
Serializable, Comparable<FormatElementCategory>, Constable

public enum FormatElementCategory extends Enum<FormatElementCategory>
Classification of an XML element that determines how the formatter handles its whitespace. The category is computed from the element's content model (children, text, or both) and from xml:space attributes.

The category drives every formatting decision in DOMElementFormatter: indentation of children, wrapping at maxLineWidth, whitespace collapsing, and preservation.

Author:
Angelo ZERR
See Also:
  • Enum Constant Details

    • IgnoreSpace

      public static final FormatElementCategory IgnoreSpace
      Element contains only child elements (no text content). All whitespace between children is insignificant and is replaced with newlines and proper indentation.

      Use case:

       <root><a><b/></a></root>
       →
       <root>
         <a>
           <b />
         </a>
       </root>
       
    • NormalizeSpace

      public static final FormatElementCategory NormalizeSpace
      Element contains only text (no child elements). Consecutive whitespace characters are collapsed to a single space. Line breaks are preserved unless joinContentLines is enabled.

      Use case:

       <p>  hello   world  </p>  →  <p>hello world</p>
       
    • MixedContent

      public static final FormatElementCategory MixedContent
      Element contains both text and child elements. Inline flow is preserved: a single whitespace between text and elements is significant. Child elements only wrap to new lines when maxLineWidth is exceeded or indentation needs normalizing.

      Use case (no overflow — stays inline):

       <p>text <b>bold</b> more</p>  →  unchanged
       

      Use case (overflow — element wraps):

       <p>text <a>aaa</a><b>bbb</b></p>
       →
       <p>text <a>aaa</a>
         <b>bbb</b></p>
       
    • PreserveSpace

      public static final FormatElementCategory PreserveSpace
      Element has xml:space="preserve" — all whitespace is significant. No changes are made to spacing within this element. Child elements may belong to a different category and may be reformatted independently.

      Attribute values are always treated as preserve-space regardless of the element's category.

      Use case:

       <pre xml:space="preserve">  keep  spaces  </pre>  →  unchanged
       
  • Method Details

    • values

      public static FormatElementCategory[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static FormatElementCategory valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null