Class IndentationContext

java.lang.Object
com.github.javaparser.printer.lexicalpreservation.IndentationContext

public class IndentationContext extends Object
Maintains the current indentation state during lexical preservation operations. This class encapsulates a mutable list of indentation elements (spaces/tabs) that represents the current indentation level. It provides methods to increase/decrease indentation and query the current state. Instances of this class are typically created at the start of a difference application and maintained throughout the process.
  • Constructor Details

    • IndentationContext

      public IndentationContext()
      Creates a new IndentationContext with empty indentation.
    • IndentationContext

      public IndentationContext(List<TextElement> initialIndentation)
      Creates a new IndentationContext with the specified initial indentation. The provided list is copied to prevent external modifications.
      Parameters:
      initialIndentation - the initial indentation elements (will be copied)
  • Method Details

    • increase

      public void increase()
      Increases indentation by one level. Adds STANDARD_INDENTATION_SIZE space characters to the current indentation.
    • decrease

      public void decrease()
      Decreases indentation by one level. Removes up to STANDARD_INDENTATION_SIZE characters from the end of the current indentation. Does nothing if the current indentation has fewer elements than STANDARD_INDENTATION_SIZE.
    • getCurrent

      public List<TextElement> getCurrent()
      Returns a copy of the current indentation elements. The returned list is unmodifiable to prevent accidental modifications.
      Returns:
      unmodifiable view of current indentation elements
    • size

      public int size()
      Returns the number of indentation characters currently stored.
      Returns:
      count of indentation elements
    • clear

      public void clear()
      Clears all indentation, resetting to zero indentation.
    • set

      public void set(List<TextElement> newIndentation)
      Replaces the current indentation with the specified elements. The provided list is copied to prevent external modifications.
      Parameters:
      newIndentation - the new indentation elements (will be copied)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object