public class LineLengthExtendedCheck
extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
Rationale: Long lines are hard to read in printouts or if developers have limited screen space for the source code, e.g. if the IDE displays additional information like project tree, class hierarchy, etc.
Note: Support for the special handling of imports in CheckStyle Version 2 has been dropped as it is a special case of regexp: The user can set the ignorePattern to "^import" and achieve the same effect.
The default maximum allowable line length is 80 characters. To change the maximum, set property max.
To ignore lines in the check, set property ignorePattern to a regular expression for the lines to ignore.
An example of how to configure the check is:
<module name="LineLength"/>
An example of how to configure the check to accept lines up to 120 characters long is:
<module name="LineLength">
<property name="max" value="120"/>
</module>
An example of how to configure the check to ignore lines that begin with " * ", followed by just one word, such as within a Javadoc comment, is:
<module name="LineLength">
<property name="ignorePattern" value="^ *\* *[^ ]+$"/>
</module>
There are some exceptions for class, constructor, field and method declarations. To ignore to check such lines there are enable|disable options. By default they have "false" values.
| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_KEY
Warning message key.
|
| Constructor and Description |
|---|
LineLengthExtendedCheck()
Creates a new
LineLengthCheck instance. |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST) |
void |
finishTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST) |
int[] |
getAcceptableTokens() |
int[] |
getDefaultTokens() |
int[] |
getRequiredTokens() |
void |
setIgnoreClass(boolean value)
Enable|Disable checking class declaration length.
|
void |
setIgnoreConstructor(boolean value)
Enable|Disable checking constructor declaration length.
|
void |
setIgnoreField(boolean value)
Enable|Disable checking field declaration length.
|
void |
setIgnoreMethod(boolean value)
Enable|Disable checking method declaration length.
|
void |
setIgnorePattern(String format)
Set the ignore pattern.
|
void |
setMax(int length)
Setter for the field max.
|
void |
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast) |
clearMessages, destroy, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeveritypublic static final String MSG_KEY
public LineLengthExtendedCheck()
LineLengthCheck instance.public void setIgnoreField(boolean value)
value - check field declaration length.public void setIgnoreMethod(boolean value)
value - check method declaration length.public void setIgnoreConstructor(boolean value)
value - check constructor declaration length.public void setIgnoreClass(boolean value)
value - check class declaration length.public int[] getDefaultTokens()
getDefaultTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getAcceptableTokens()
getAcceptableTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getRequiredTokens()
getRequiredTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
visitToken in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic void beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)
beginTree in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic void finishTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)
finishTree in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic void setMax(int length)
length - the maximum length of a linepublic final void setIgnorePattern(String format)
format - a String valueIllegalArgumentException - unable to parse aFormatCopyright © 2021. All rights reserved.