Class IndentationContext
java.lang.Object
com.github.javaparser.printer.lexicalpreservation.IndentationContext
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 Summary
ConstructorsConstructorDescriptionCreates a new IndentationContext with empty indentation.IndentationContext(List<TextElement> initialIndentation) Creates a new IndentationContext with the specified initial indentation. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all indentation, resetting to zero indentation.voiddecrease()Decreases indentation by one level.booleanReturns a copy of the current indentation elements.inthashCode()voidincrease()Increases indentation by one level.voidset(List<TextElement> newIndentation) Replaces the current indentation with the specified elements.intsize()Returns the number of indentation characters currently stored.toString()
-
Constructor Details
-
IndentationContext
public IndentationContext()Creates a new IndentationContext with empty indentation. -
IndentationContext
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
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
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
-
equals
-
hashCode
-