Class UnusedImports

java.lang.Object
com.puppycrawl.tools.checkstyle.api.AutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractCheck
com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck
io.debezium.checkstyle.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
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
     
    private static final String[]
     
    private static final Set<String>
     
    private final Set<com.puppycrawl.tools.checkstyle.api.FullIdent>
     
    private static final Pattern
    A regular expression for finding the first word within a JavaDoc "@link" text.
    private static final Pattern
    A regular expression for finding the first classname referenced in a "@link" reference.
    private static final Pattern
    A regular expression for finding the class name (group 1) and the method parameters (group 2) within a JavaDoc "@link" reference.
    private boolean
     
    private boolean
     
    private final Set<String>
     

    Fields inherited from class com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck

    MSG_KEY
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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
     
    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, leaveToken

    Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck

    clearViolations, destroy, getFileContents, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEBUG_CLASSNAMES

      private static final String[] DEBUG_CLASSNAMES
    • DEBUG_CLASSNAMES_SET

      private static final Set<String> DEBUG_CLASSNAMES_SET
    • 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+)?(?:\(([^\)]+)\))?.*
       
    • 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 Details

    • UnusedImports

      public UnusedImports()
  • Method Details

    • 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)