public class AvoidStarImportCheck extends Check
Check that finds import statements that use the * notation.
Rationale: Importing all classes from a package or static members from a class leads to tight coupling between packages or classes and might lead to problems when a new version of a library introduces name clashes.
An example of how to configure the check is:
<module name="AvoidStarImport"> <property name="excludes" value="java.io,java.net,java.lang.Math"/> <property name="allowClassImports" value="false"/> <property name="allowStaticMemberImports" value="false"/> </module>The optional "excludes" property allows for certain packages like java.io or java.net to be exempted from the rule. It also is used to allow certain classes like java.lang.Math or java.io.File to be excluded in order to support static member imports. The optional "allowClassImports" when set to true, will allow starred class imports but will not affect static member imports. The optional "allowStaticMemberImports" when set to true will allow starred static member imports but will not affect class imports.
Constructor and Description |
---|
AvoidStarImportCheck() |
Modifier and Type | Method and Description |
---|---|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
void |
setAllowClassImports(boolean allow)
Sets whether or not to allow all non-static class imports.
|
void |
setAllowStaticMemberImports(boolean allow)
Sets whether or not to allow all static member imports.
|
void |
setExcludes(String[] excludesParam)
Sets the list of packages or classes to be exempt from the check.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLine, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
public AvoidStarImportCheck()
public int[] getDefaultTokens()
Check
getDefaultTokens
in class Check
TokenTypes
public void setExcludes(String[] excludesParam)
excludesParam
- a list of package names/fully-qualifies class names
where star imports are okpublic void setAllowClassImports(boolean allow)
allow
- true to allow false to disallowpublic void setAllowStaticMemberImports(boolean allow)
allow
- true to allow false to disallowpublic void visitToken(DetailAST ast)
Check
visitToken
in class Check
ast
- the token to processCopyright © 2001–2015. All rights reserved.