Class ForbidCertainImportsCheck
- 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.coding.ForbidCertainImportsCheck
 
 
 
 
- 
- All Implemented Interfaces:
- com.puppycrawl.tools.checkstyle.api.Configurable,- com.puppycrawl.tools.checkstyle.api.Contextualizable
 
 public class ForbidCertainImportsCheck extends com.puppycrawl.tools.checkstyle.api.AbstractCheckForbids certain imports usage in certain packages. You can configure this check using the following parameters:- Package qualified name regexp;
- Forbidden imports regexp;
- Forbidden imports excludes regexp.
 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: - Package name regexp = ".*ui.*"
- Forbidden imports regexp = ".*dao.*"
- Forbidden imports excludes regexp = "^.+Exception$"
 You can cover more sophisticated rules by means of few check instances. - Since:
- 1.8.0
- Author:
- Daniil Yaroslavtsev
 
- 
- 
Constructor SummaryConstructors Constructor Description ForbidCertainImportsCheck()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)int[]getAcceptableTokens()int[]getDefaultTokens()StringgetForbiddenImportRegexp()Gets the regexp is used for matching forbidden imports.int[]getRequiredTokens()voidsetForbiddenImportsExcludesRegexp(String forbiddenImportsExcludesRegexp)Sets the regexp for excluding imports from checking.voidsetForbiddenImportsRegexp(String forbiddenImportsRegexp)Sets the regexp for matching forbidden imports.voidsetPackageNameRegexp(String packageNameRegexp)Sets the regexp for matching package fully qualified name.voidvisitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)- 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheckclearViolations, destroy, finishTree, 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.AbstractViolationReporterfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
 
- 
 
- 
- 
- 
Field Detail- 
MSG_KEYpublic static final String MSG_KEY The key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
setPackageNameRegexppublic void setPackageNameRegexp(String packageNameRegexp) Sets the regexp for matching package fully qualified name.- Parameters:
- packageNameRegexp- regexp for package fully qualified name matching.
 
 - 
getForbiddenImportRegexppublic String getForbiddenImportRegexp() Gets the regexp is used for matching forbidden imports.- Returns:
- regexp for forbidden imports matching.
 
 - 
setForbiddenImportsRegexppublic void setForbiddenImportsRegexp(String forbiddenImportsRegexp) Sets the regexp for matching forbidden imports.- Parameters:
- forbiddenImportsRegexp- regexp for matching forbidden imports.
 
 - 
setForbiddenImportsExcludesRegexppublic void setForbiddenImportsExcludesRegexp(String forbiddenImportsExcludesRegexp) Sets the regexp for excluding imports from checking.- Parameters:
- forbiddenImportsExcludesRegexp- String contains a regexp for excluding imports from checking.
 
 - 
getDefaultTokenspublic int[] getDefaultTokens() - Specified by:
- getDefaultTokensin class- com.puppycrawl.tools.checkstyle.api.AbstractCheck
 
 - 
getAcceptableTokenspublic int[] getAcceptableTokens() - Specified by:
- getAcceptableTokensin class- com.puppycrawl.tools.checkstyle.api.AbstractCheck
 
 - 
getRequiredTokenspublic int[] getRequiredTokens() - Specified by:
- getRequiredTokensin class- com.puppycrawl.tools.checkstyle.api.AbstractCheck
 
 - 
beginTreepublic void beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST) - Overrides:
- beginTreein class- com.puppycrawl.tools.checkstyle.api.AbstractCheck
 
 - 
visitTokenpublic void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast) - Overrides:
- visitTokenin class- com.puppycrawl.tools.checkstyle.api.AbstractCheck
 
 
- 
 
-