Package org.apache.openjpa.lib.util
Class CodeFormat
java.lang.Object
org.apache.openjpa.lib.util.CodeFormat
- All Implemented Interfaces:
Cloneable
Encapsulates some common Java source code formatting options. The
class can also be used as a buffer for formatted Java code.
- Author:
- Abe White
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAppend the given value to the internal buffer.append
(boolean val) Append the given value to the internal buffer.append
(byte val) Append the given value to the internal buffer.append
(char val) Append the given value to the internal buffer.append
(double val) Append the given value to the internal buffer.append
(float val) Append the given value to the internal buffer.append
(int val) Append the given value to the internal buffer.append
(long val) Append the given value to the internal buffer.append
(short val) Append the given value to the internal buffer.Append the given value to the internal buffer.void
clear()
Clear the internal code buffer.clone()
Make a copy of this code format object with all the same formatting settings.closeBrace
(int tabLevel) Append the given value to the internal buffer.Append the given value to the internal buffer.endl()
Append the given value to the internal buffer.endl
(int num) Append the given value to the internal buffer.endl
(int num, int tabs) Append the given value to the internal buffer.extendsDec
(int tabLevel) Append the given value to the internal buffer.Append the given value to the internal buffer.Return {#getLinesBetweenSections} + 1 new line characters.boolean
Whether to place braces at the same tab level as the code within the block.boolean
Whether to place opening braces on the same line as the block declaration, or on the next line.Return the internal code buffer.getCloseBrace
(int tabLevel) Close brace string.Close parentheses string.getEndl()
Return a new line character.getEndl
(int num) Return the given number of new line characters.getEndl
(int num, int tabs) Return the given number of new line characters, followed by the given tab level indentation.getExtendsDec
(int tabLevel) Extends declaration.getFieldName
(String fieldName) Return the field name for given suggested name, possibly adding leading underscore.getImplementsDec
(int tabLevel) Implements declaration.int
The number of empty lines between code sections.getOpenBrace
(int tabLevel) Open brace string.getOpenParen
(boolean methodOrIf) Open parentheses string.getParametrizedType
(String[] typenames) Returns parametrized type string for given type(s).Paired parentheses for empty method parameters.boolean
Whether to place an underscore before private field names.boolean
Whether to place a space before parentheses.boolean
Whether to place a space within parentheses.getTab()
Tab string.getTab
(int tabLevel) Tab string.int
The number of spaces to use for tabs; 0 means to use actual tab characters.getThrowsDec
(int tabLevel) Throws declaration.implementsDec
(int tabLevel) Append the given value to the internal buffer.int
length()
Return the length of the internal buffer.openBrace
(int tabLevel) Append the given value to the internal buffer.openParen
(boolean methodOrIf) Append the given value to the internal buffer.parens()
Append the given value to the internal buffer.void
setBraceAtSameTabLevel
(boolean braceAtSameTabLevel) Whether to place braces at the same tab level as the code within the block.void
setBraceOnSameLine
(boolean braceOnSameLine) Whether to place opening braces on the same line as the block declaration, or on the next line.void
setLinesBetweenSections
(int linesBetweenSections) The number of empty lines between sections.void
setScoreBeforeFieldName
(boolean scoreBeforeFieldName) Whether to place an underscore before private field names.void
setSpaceBeforeParen
(boolean spaceBeforeParen) Whether to place a space before parentheses.void
setSpaceInParen
(boolean spaceInParen) Whether to place a space within parentheses.void
setTabSpaces
(int tab) The number of spaces to use for tabs; 0 means to use actual tab characters.tab()
Append the given value to the internal buffer.tab
(int tabLevel) Append the given value to the internal buffer.throwsDec
(int tabLevel) Append the given value to the internal buffer.toString()
Return the internal buffer as a string.
-
Constructor Details
-
CodeFormat
public CodeFormat()
-
-
Method Details
-
getTabSpaces
public int getTabSpaces()The number of spaces to use for tabs; 0 means to use actual tab characters. Defaults to 0. -
setTabSpaces
public void setTabSpaces(int tab) The number of spaces to use for tabs; 0 means to use actual tab characters. Defaults to 0. -
getSpaceBeforeParen
public boolean getSpaceBeforeParen()Whether to place a space before parentheses. Defaults to false. -
setSpaceBeforeParen
public void setSpaceBeforeParen(boolean spaceBeforeParen) Whether to place a space before parentheses. Defaults to false. -
getSpaceInParen
public boolean getSpaceInParen()Whether to place a space within parentheses. Defaults to false. -
setSpaceInParen
public void setSpaceInParen(boolean spaceInParen) Whether to place a space within parentheses. Defaults to false. -
getBraceOnSameLine
public boolean getBraceOnSameLine()Whether to place opening braces on the same line as the block declaration, or on the next line. Defaults to same line. -
setBraceOnSameLine
public void setBraceOnSameLine(boolean braceOnSameLine) Whether to place opening braces on the same line as the block declaration, or on the next line. Defaults to same line. -
getBraceAtSameTabLevel
public boolean getBraceAtSameTabLevel()Whether to place braces at the same tab level as the code within the block. Defaults to false. -
setBraceAtSameTabLevel
public void setBraceAtSameTabLevel(boolean braceAtSameTabLevel) Whether to place braces at the same tab level as the code within the block. Defaults to false. -
getScoreBeforeFieldName
public boolean getScoreBeforeFieldName()Whether to place an underscore before private field names. Defaults to false. -
setScoreBeforeFieldName
public void setScoreBeforeFieldName(boolean scoreBeforeFieldName) Whether to place an underscore before private field names. Defaults to false. -
getLinesBetweenSections
public int getLinesBetweenSections()The number of empty lines between code sections. Defaults to 1. -
setLinesBetweenSections
public void setLinesBetweenSections(int linesBetweenSections) The number of empty lines between sections. Defaults to 1. -
getEndl
Return a new line character. -
getEndl
Return the given number of new line characters. -
getEndl
Return the given number of new line characters, followed by the given tab level indentation. -
getAfterSection
Return {#getLinesBetweenSections} + 1 new line characters. -
getOpenParen
Open parentheses string. Users can choose to place spaces before and within parentheses. -
getCloseParen
Close parentheses string. Users can choose to place spaces within parentheses. -
getParens
Paired parentheses for empty method parameters. Users can choose to place spaces before parentheses. -
getOpenBrace
Open brace string. Users can choose to place braces on the same line, or on a new line, and can choose the indenting level.- Parameters:
tabLevel
- the tab level of code within the brace
-
getCloseBrace
Close brace string. Users can choose to place braces on the same line, or on a new line, and can choose the indenting level.- Parameters:
tabLevel
- the tab level of code within the brace
-
getExtendsDec
Extends declaration. Uses configuration ofopenBrace(int)
, but prints "extends" instead of a brace. -
getImplementsDec
Implements declaration. Uses configuration ofopenBrace(int)
, but prints "implements" instead of a brace. -
getThrowsDec
Throws declaration. Uses configuration ofopenBrace(int)
, but prints "throws" instead of a brace. -
getTab
Tab string. Users can choose to use spaces or tab characters. -
getTab
Tab string. Users can choose to use spaces or tab characters.- Parameters:
tabLevel
- the number of tabs
-
getParametrizedType
Returns parametrized type string for given type(s). -
getFieldName
Return the field name for given suggested name, possibly adding leading underscore. -
getBuffer
Return the internal code buffer. -
append
Append the given value to the internal buffer. -
append
Append the given value to the internal buffer. -
append
Append the given value to the internal buffer. -
append
Append the given value to the internal buffer. -
append
Append the given value to the internal buffer. -
append
Append the given value to the internal buffer. -
append
Append the given value to the internal buffer. -
append
Append the given value to the internal buffer. -
append
Append the given value to the internal buffer. -
endl
Append the given value to the internal buffer.- See Also:
-
endl
Append the given value to the internal buffer.- See Also:
-
endl
Append the given value to the internal buffer.- See Also:
-
afterSection
Append the given value to the internal buffer.- See Also:
-
openParen
Append the given value to the internal buffer.- See Also:
-
closeParen
Append the given value to the internal buffer.- See Also:
-
parens
Append the given value to the internal buffer.- See Also:
-
openBrace
Append the given value to the internal buffer.- See Also:
-
closeBrace
Append the given value to the internal buffer.- See Also:
-
extendsDec
Append the given value to the internal buffer.- See Also:
-
implementsDec
Append the given value to the internal buffer.- See Also:
-
throwsDec
Append the given value to the internal buffer.- See Also:
-
tab
Append the given value to the internal buffer.- See Also:
-
tab
Append the given value to the internal buffer.- See Also:
-
fieldName
Append the given value to the internal buffer.- See Also:
-
clear
public void clear()Clear the internal code buffer. -
toString
Return the internal buffer as a string. -
length
public int length()Return the length of the internal buffer. -
clone
Make a copy of this code format object with all the same formatting settings.
-