Class IndentationContext
- java.lang.Object
-
- com.github.javaparser.printer.lexicalpreservation.IndentationContext
-
public class IndentationContext extends java.lang.ObjectMaintains 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
Constructors Constructor Description IndentationContext()Creates a new IndentationContext with empty indentation.IndentationContext(java.util.List<TextElement> initialIndentation)Creates a new IndentationContext with the specified initial indentation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears all indentation, resetting to zero indentation.voiddecrease()Decreases indentation by one level.booleanequals(java.lang.Object o)java.util.List<TextElement>getCurrent()Returns a copy of the current indentation elements.inthashCode()voidincrease()Increases indentation by one level.voidset(java.util.List<TextElement> newIndentation)Replaces the current indentation with the specified elements.intsize()Returns the number of indentation characters currently stored.java.lang.StringtoString()
-
-
-
Constructor Detail
-
IndentationContext
public IndentationContext()
Creates a new IndentationContext with empty indentation.
-
IndentationContext
public IndentationContext(java.util.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 Detail
-
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 java.util.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(java.util.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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-