public class ForbidCertainImportsCheck
extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
Forbids certain imports usage in certain packages.
You can configure this check using the following parameters:This check loads packages qualified names without words "package","import" and semicolons, so, please, do NOT include "package" or "import" words (or semicolons) into config regexps.
Real-life example of usage: forbid to use all "*.ui.*" packages in "*.dao.*" packages, but ignore all Exception imports (such as org.springframework.dao.InvalidDataAccessResourceUsageException). For doing that, you should to use the following check parameters:
You can cover more sophisticated rules by means of few check instances.
| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_KEY
The key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
ForbidCertainImportsCheck() |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST) |
int[] |
getAcceptableTokens() |
int[] |
getDefaultTokens() |
String |
getForbiddenImportRegexp()
Gets the regexp is used for matching forbidden imports.
|
int[] |
getRequiredTokens() |
void |
setForbiddenImportsExcludesRegexp(String forbiddenImportsExcludesRegexp)
Sets the regexp for excluding imports from checking.
|
void |
setForbiddenImportsRegexp(String forbiddenImportsRegexp)
Sets the regexp for matching forbidden imports.
|
void |
setPackageNameRegexp(String packageNameRegexp)
Sets the regexp for matching package fully qualified name.
|
void |
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast) |
clearMessages, destroy, finishTree, 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 void setPackageNameRegexp(String packageNameRegexp)
packageNameRegexp - regexp for package fully qualified name matching.public String getForbiddenImportRegexp()
public void setForbiddenImportsRegexp(String forbiddenImportsRegexp)
forbiddenImportsRegexp - regexp for matching forbidden imports.public void setForbiddenImportsExcludesRegexp(String forbiddenImportsExcludesRegexp)
forbiddenImportsExcludesRegexp - String contains a regexp for excluding imports from checking.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 beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)
beginTree 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.AbstractCheckCopyright © 2021. All rights reserved.