Package spoon.reflect.visitor
Class PrinterHelper
- java.lang.Object
-
- spoon.reflect.visitor.PrinterHelper
-
public class PrinterHelper extends Object
Supports configurable printing of text with indentations and line and column counting
-
-
Field Summary
Fields Modifier and Type Field Description protected StringBuffer
sbf
The string buffer in which the code is generated.protected boolean
shouldWriteTabs
-
Constructor Summary
Constructors Constructor Description PrinterHelper()
PrinterHelper(Environment env)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PrinterHelper
adjustEndPosition(CtElement e)
writes as many newlines as needed for the current line to match the end line of the passed elementPrinterHelper
adjustStartPosition(CtElement e)
writes as many newlines as needed to align the line number again between the element position and the current line numberprotected void
autoWriteTabs()
PrinterHelper
decTab()
Decrements the current number of tabs.Map<Integer,Integer>
getLineNumberMapping()
String
getLineSeparator()
int
getTabCount()
PrinterHelper
incTab()
Increments the current number of tabs.void
mapLine(CtElement e, CtCompilationUnit unitExpected)
void
putLineNumberMapping(int valueLine)
boolean
removeLine()
void
reset()
resets to the initial statevoid
setLineSeparator(String lineSeparator)
void
setShouldWriteTabs(boolean b)
PrinterHelper
setTabCount(int tabCount)
Sets the current number of tabs.String
toString()
void
undefineLine()
PrinterHelper
write(char c)
Outputs a char.PrinterHelper
write(String s)
Outputs a string.PrinterHelper
writeln()
Generates a new line.void
writeSpace()
writes a space ' '
-
-
-
Field Detail
-
sbf
protected final StringBuffer sbf
The string buffer in which the code is generated.
-
shouldWriteTabs
protected boolean shouldWriteTabs
-
-
Constructor Detail
-
PrinterHelper
public PrinterHelper()
-
PrinterHelper
public PrinterHelper(Environment env)
-
-
Method Detail
-
reset
public void reset()
resets to the initial state
-
write
public PrinterHelper write(String s)
Outputs a string.
-
write
public PrinterHelper write(char c)
Outputs a char.
-
writeln
public PrinterHelper writeln()
Generates a new line.
-
autoWriteTabs
protected void autoWriteTabs()
-
incTab
public PrinterHelper incTab()
Increments the current number of tabs.
-
decTab
public PrinterHelper decTab()
Decrements the current number of tabs.
-
getTabCount
public int getTabCount()
- Returns:
- the current number of tabs.
-
setTabCount
public PrinterHelper setTabCount(int tabCount)
Sets the current number of tabs.
-
removeLine
public boolean removeLine()
-
adjustStartPosition
public PrinterHelper adjustStartPosition(CtElement e)
writes as many newlines as needed to align the line number again between the element position and the current line number
-
adjustEndPosition
public PrinterHelper adjustEndPosition(CtElement e)
writes as many newlines as needed for the current line to match the end line of the passed element- Parameters:
e
- element whose line number will be preserved by adding newlines- Returns:
- PrinterHelper
-
undefineLine
public void undefineLine()
-
mapLine
public void mapLine(CtElement e, CtCompilationUnit unitExpected)
-
putLineNumberMapping
public void putLineNumberMapping(int valueLine)
-
getLineSeparator
public String getLineSeparator()
- Returns:
- current line separator. By default there is CR LF, LF or CR depending on the Operation system defined by System.getProperty("line.separator")
-
setLineSeparator
public void setLineSeparator(String lineSeparator)
- Parameters:
lineSeparator
- characters which will be printed as End of line. By default there is System.getProperty("line.separator")
-
writeSpace
public void writeSpace()
writes a space ' '
-
setShouldWriteTabs
public void setShouldWriteTabs(boolean b)
-
-