public class RedundantImportCheck extends AbstractCheck
Checks for redundant import statements. An import statement is considered redundant if:
java.lang
package, e.g. importing java.lang.String.To configure the check:
<module name="RedundantImport"/>
Example:
package Test;
import static Test.MyClass.*; // OK, static import
import static java.lang.Integer.MAX_VALUE; // OK, static import
import Test.MyClass; // violation, imported from the same package as the current package
import java.lang.String; // violation, the class imported is from the 'java.lang' package
import java.util.Scanner; // OK
import java.util.Scanner; // violation, it is a duplicate of another import
public class MyClass{ };
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
import.duplicate
import.lang
import.same
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
private java.util.Set<FullIdent> |
imports
Set of the imports.
|
static java.lang.String |
MSG_DUPLICATE
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_LANG
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_SAME
A key is pointing to the warning message text in "messages.properties"
file.
|
private java.lang.String |
pkgName
Name of package in file.
|
private java.util.Set<FullIdent> |
staticImports
Set of static imports.
|
| Constructor and Description |
|---|
RedundantImportCheck() |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTree(DetailAST aRootAST)
Called before the starting to process a tree.
|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
private static boolean |
isFromPackage(java.lang.String importName,
java.lang.String pkg)
Determines if an import statement is for types from a specified package.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
clearViolations, destroy, finishTree, getFileContents, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final java.lang.String MSG_LANG
public static final java.lang.String MSG_SAME
public static final java.lang.String MSG_DUPLICATE
private final java.util.Set<FullIdent> staticImports
private java.lang.String pkgName
public RedundantImportCheck()
public void beginTree(DetailAST aRootAST)
AbstractCheckbeginTree in class AbstractCheckaRootAST - the root of the treepublic int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processprivate static boolean isFromPackage(java.lang.String importName, java.lang.String pkg)
importName - the import namepkg - the package nameCopyright © 2001-2022. All Rights Reserved.