public class UnusedImports
extends com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck
UnusedImportsCheck that fixes a couple of problems, including correctly processing
@link expressions that are not properly terminated on the same line, correctly processing JavaDoc @param lines,
and correctly processing method parameters contained with @link expressions.
Unfortunately, the base class is not easily overwritten, and thus a fair amount of the logic has to be incorporated here.
| Modifier and Type | Field and Description |
|---|---|
private boolean |
collect |
private static String[] |
DEBUG_CLASSNAMES |
private static Set<String> |
DEBUG_CLASSNAMES_SET |
private Set<com.puppycrawl.tools.checkstyle.api.FullIdent> |
imports |
private static Pattern |
LINK_VALUE_IN_TEXT_PATTERN
A regular expression for finding the first word within a JavaDoc "@link" text.
|
private static Pattern |
LINK_VALUE_PATTERN
A regular expression for finding the first classname referenced in a "@link" reference.
|
private static Pattern |
PARTS_OF_CLASS_OR_REFERENCE_PATTERN
A regular expression for finding the class name (group 1) and the method parameters (group 2) within a JavaDoc "@link"
reference.
|
private boolean |
print |
private boolean |
processJavaDoc |
private Set<String> |
referenced |
| Constructor and Description |
|---|
UnusedImports() |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST) |
void |
finishTree(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST) |
private void |
print(Object... messages) |
protected void |
processClassOrMethodReference(String text) |
protected void |
processIdent(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
Collects references made by IDENT.
|
private void |
processImport(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
Collects the details of imports.
|
protected void |
processJavaDocLinkParameters(com.puppycrawl.tools.checkstyle.api.DetailAST aAST) |
protected void |
processJavaDocTag(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag tag) |
private void |
processStaticImport(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
Collects the details of static imports.
|
void |
setProcessJavadoc(boolean aValue) |
void |
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST) |
getAcceptableTokens, getDefaultTokens, getRequiredTokensclearMessages, destroy, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityprivate static final String[] DEBUG_CLASSNAMES
private static final Pattern LINK_VALUE_IN_TEXT_PATTERN
(.*?)(?:\s+|#|\$)(.*)
private static final Pattern PARTS_OF_CLASS_OR_REFERENCE_PATTERN
([\w.]+)(?:\#?\w+)?(?:\(([^\)]+)\))?.*
private static final Pattern LINK_VALUE_PATTERN
\{\@link\s+([^}]*)
private boolean collect
private boolean processJavaDoc
private final Set<com.puppycrawl.tools.checkstyle.api.FullIdent> imports
private boolean print
public void setProcessJavadoc(boolean aValue)
setProcessJavadoc in class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheckpublic void beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST)
beginTree in class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheckpublic void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
visitToken in class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheckprotected void processIdent(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
aAST - the IDENT node to process stuffprotected void processJavaDocLinkParameters(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
protected void processJavaDocTag(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag tag)
protected void processClassOrMethodReference(String text)
private void processImport(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
aAST - node containing the import detailsprivate void processStaticImport(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
aAST - node containing the static import detailspublic void finishTree(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST)
finishTree in class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheckprivate void print(Object... messages)
Copyright © 2021 JBoss by Red Hat. All rights reserved.