Class CodeFormatter
- java.lang.Object
-
- org.apache.bsf.util.cf.CodeFormatter
-
public class CodeFormatter extends java.lang.ObjectACodeFormatterbean is used to format raw Java code. It indents, word-wraps, and replaces tab characters with an amount of space characters equal to the size of theindentationStepproperty. To create and use aCodeFormatter, you simply instantiate a newCodeFormatterbean, and invokeformatCode(Reader source, Writer target)with appropriate arguments.- Author:
- Matthew J. Duftler
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_DELIMThe default set of delimiters.static intDEFAULT_MAXThe default maximum line length.static java.lang.StringDEFAULT_S_DELIMThe default set of sticky delimiters.static intDEFAULT_STEPThe default size of the indentation step.
-
Constructor Summary
Constructors Constructor Description CodeFormatter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidformatCode(java.io.Reader source, java.io.Writer target)Formats the code read fromsource, and writes the formatted code totarget.java.lang.StringgetDelimiters()Gets the set of delimiters.intgetIndentationStep()Gets the size of the indentation step.intgetMaxLineLength()Gets the maximum line length.java.lang.StringgetStickyDelimiters()Gets the set of sticky delimiters.voidsetDelimiters(java.lang.String newDelimiters)Sets the set of delimiters; default set is"(+".voidsetIndentationStep(int newIndentationStep)Sets the size of the indentation step; default size is2.voidsetMaxLineLength(int newMaxLineLength)Sets the (desired) maximum line length; default length is74.voidsetStickyDelimiters(java.lang.String newStickyDelimiters)Sets the set of sticky delimiters; default set is",".
-
-
-
Field Detail
-
DEFAULT_MAX
public static final int DEFAULT_MAX
The default maximum line length.- See Also:
- Constant Field Values
-
DEFAULT_STEP
public static final int DEFAULT_STEP
The default size of the indentation step.- See Also:
- Constant Field Values
-
DEFAULT_DELIM
public static final java.lang.String DEFAULT_DELIM
The default set of delimiters.- See Also:
- Constant Field Values
-
DEFAULT_S_DELIM
public static final java.lang.String DEFAULT_S_DELIM
The default set of sticky delimiters.- See Also:
- Constant Field Values
-
-
Method Detail
-
formatCode
public void formatCode(java.io.Reader source, java.io.Writer target)Formats the code read fromsource, and writes the formatted code totarget.- Parameters:
source- where to read the unformatted code from.target- where to write the formatted code to.
-
getDelimiters
public java.lang.String getDelimiters()
Gets the set of delimiters.- Returns:
- the set of delimiters.
- See Also:
setDelimiters(java.lang.String)
-
getIndentationStep
public int getIndentationStep()
Gets the size of the indentation step.- Returns:
- the size of the indentation step.
- See Also:
setIndentationStep(int)
-
getMaxLineLength
public int getMaxLineLength()
Gets the maximum line length.- Returns:
- the maximum line length.
- See Also:
setMaxLineLength(int)
-
getStickyDelimiters
public java.lang.String getStickyDelimiters()
Gets the set of sticky delimiters.- Returns:
- the set of sticky delimiters.
- See Also:
setStickyDelimiters(java.lang.String)
-
setDelimiters
public void setDelimiters(java.lang.String newDelimiters)
Sets the set of delimiters; default set is"(+".Each character represents one delimiter. If a line is ready to be word-wrapped and a delimiter is encountered, the delimiter will appear as the first character on the following line. A quotation mark,
"or', opening a string is always a delimiter, whether you specify it or not.- Parameters:
newDelimiters- the new set of delimiters.- See Also:
getDelimiters()
-
setIndentationStep
public void setIndentationStep(int newIndentationStep)
Sets the size of the indentation step; default size is2.This is the number of spaces that lines will be indented (when appropriate).
- Parameters:
newIndentationStep- the new size of the indentation step.- See Also:
getIndentationStep()
-
setMaxLineLength
public void setMaxLineLength(int newMaxLineLength)
Sets the (desired) maximum line length; default length is74.If a token is longer than the requested maximum line length, then the line containing that token will obviously be longer than the desired maximum.
- Parameters:
newMaxLineLength- the new maximum line length.- See Also:
getMaxLineLength()
-
setStickyDelimiters
public void setStickyDelimiters(java.lang.String newStickyDelimiters)
Sets the set of sticky delimiters; default set is",".Each character represents one sticky delimiter. If a line is ready to be word-wrapped and a sticky delimiter is encountered, the sticky delimiter will appear as the last character on the current line. A quotation mark,
"or', closing a string is always a sticky delimiter, whether you specify it or not.- Parameters:
newStickyDelimiters- the new set of sticky delimiters.- See Also:
getStickyDelimiters()
-
-