Class UnusedImports

  • All Implemented Interfaces:
    com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable

    public class UnusedImports
    extends com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck
    This is a specialization of the 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.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

        com.puppycrawl.tools.checkstyle.api.AutomaticBean.OutputStreamOptions
    • Constructor Summary

      Constructors 
      Constructor Description
      UnusedImports()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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)  
      • Methods inherited from class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck

        getAcceptableTokens, getDefaultTokens, getRequiredTokens
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck

        clearMessages, destroy, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

        finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

        configure, contextualize, getConfiguration, setupChild
    • Field Detail

      • DEBUG_CLASSNAMES

        private static final String[] DEBUG_CLASSNAMES
      • DEBUG_CLASSNAMES_SET

        private static final Set<String> DEBUG_CLASSNAMES_SET
      • LINK_VALUE_IN_TEXT_PATTERN

        private static final Pattern LINK_VALUE_IN_TEXT_PATTERN
        A regular expression for finding the first word within a JavaDoc "@link" text.
         (.*?)(?:\s+|#|\$)(.*)
         
      • PARTS_OF_CLASS_OR_REFERENCE_PATTERN

        private static final 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.
         ([\w.]+)(?:\#?\w+)?(?:\(([^\)]+)\))?.*
         
      • LINK_VALUE_PATTERN

        private static final Pattern LINK_VALUE_PATTERN
        A regular expression for finding the first classname referenced in a "@link" reference.
         \{\@link\s+([^}]*)
         
      • collect

        private boolean collect
      • processJavaDoc

        private boolean processJavaDoc
      • imports

        private final Set<com.puppycrawl.tools.checkstyle.api.FullIdent> imports
      • referenced

        private final Set<String> referenced
      • print

        private boolean print
    • Constructor Detail

      • UnusedImports

        public UnusedImports()
    • Method Detail

      • setProcessJavadoc

        public void setProcessJavadoc​(boolean aValue)
        Overrides:
        setProcessJavadoc in class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck
      • beginTree

        public void beginTree​(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST)
        Overrides:
        beginTree in class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck
      • visitToken

        public void visitToken​(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
        Overrides:
        visitToken in class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck
      • processIdent

        protected void processIdent​(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
        Collects references made by IDENT.
        Parameters:
        aAST - the IDENT node to process stuff
      • processJavaDocLinkParameters

        protected void processJavaDocLinkParameters​(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
      • processJavaDocTag

        protected void processJavaDocTag​(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag tag)
      • processClassOrMethodReference

        protected void processClassOrMethodReference​(String text)
      • processImport

        private void processImport​(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
        Collects the details of imports.
        Parameters:
        aAST - node containing the import details
      • processStaticImport

        private void processStaticImport​(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
        Collects the details of static imports.
        Parameters:
        aAST - node containing the static import details
      • finishTree

        public void finishTree​(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST)
        Overrides:
        finishTree in class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck
      • print

        private void print​(Object... messages)