Class CauseParameterInExceptionCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractCheck
-
- com.github.sevntu.checkstyle.checks.design.CauseParameterInExceptionCheck
-
- All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable
,com.puppycrawl.tools.checkstyle.api.Contextualizable
public class CauseParameterInExceptionCheck extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
Checks that any Exception class which matches the defined className regexp have at least one constructor with Exception cause as a parameter.Rationale:
"A special form of exception translation called exception chaining is appropriate in cases where the lower-level exception might be helpful to someone debugging the problem that caused the higher-level exception. The lower-level exception (the cause) is passed to the higher-level.." [Joshua Bloch - Effective Java 2nd Edition, Chapter 4, Item 61]Parameters:
- Exception classNames regexp. ("classNamesRegexp" option).
- regexp to ignore classes by names ("ignoredClassNamesRegexp" option).
- The names of classes which would be considered as Exception cause ("allowedCauseTypes" option).
- Since:
- 1.8.0
- Author:
- Daniil Yaroslavtsev
-
-
Constructor Summary
Constructors Constructor Description CauseParameterInExceptionCheck()
Creates the new check instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)
void
finishTree(com.puppycrawl.tools.checkstyle.api.DetailAST treeRootAST)
int[]
getAcceptableTokens()
int[]
getDefaultTokens()
int[]
getRequiredTokens()
void
setAllowedCauseTypes(String... allowedCauseTypes)
Sets the names of classes which would be considered as Exception cause.void
setClassNamesRegexp(String classNamesRegexp)
Sets the regexp for the names of classes, that should be checked.void
setIgnoredClassNamesRegexp(String ignoredClassNamesRegexp)
Sets the regexp for the names of classes, that should be ignored by check.void
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, destroy, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
-
-
-
-
Field Detail
-
MSG_KEY
public static final String MSG_KEY
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
-
Method Detail
-
setClassNamesRegexp
public void setClassNamesRegexp(String classNamesRegexp)
Sets the regexp for the names of classes, that should be checked.- Parameters:
classNamesRegexp
- String contains the regex to set for the names of classes, that should be checked.
-
setIgnoredClassNamesRegexp
public void setIgnoredClassNamesRegexp(String ignoredClassNamesRegexp)
Sets the regexp for the names of classes, that should be ignored by check.- Parameters:
ignoredClassNamesRegexp
- String contains the regex to set for the names of classes, that should be ignored by check.
-
setAllowedCauseTypes
public void setAllowedCauseTypes(String... allowedCauseTypes)
Sets the names of classes which would be considered as Exception cause.- Parameters:
allowedCauseTypes
- - the list of classNames separated by a comma. ClassName should be short, such as "NullpointerException", do not use full name - java.lang.NullpointerException;
-
getDefaultTokens
public int[] getDefaultTokens()
- Specified by:
getDefaultTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getAcceptableTokens
public int[] getAcceptableTokens()
- Specified by:
getAcceptableTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
getRequiredTokens
public int[] getRequiredTokens()
- Specified by:
getRequiredTokens
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
beginTree
public void beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)
- Overrides:
beginTree
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
visitToken
public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
- Overrides:
visitToken
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
finishTree
public void finishTree(com.puppycrawl.tools.checkstyle.api.DetailAST treeRootAST)
- Overrides:
finishTree
in classcom.puppycrawl.tools.checkstyle.api.AbstractCheck
-
-