Class AbstractImportRule

java.lang.Object
com.puppycrawl.tools.checkstyle.checks.imports.AbstractImportRule
Direct Known Subclasses:
ClassImportRule, PkgImportRule

abstract class AbstractImportRule extends Object
Base class for import rules.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final boolean
    Indicates whether to allow access or not.
    private final boolean
    Indicates if the rule only applies to this package.
    private final boolean
    Indicates if the name is to be interpreted as a regular expression.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractImportRule(boolean allow, boolean localOnly, boolean regExp)
    Constructs an instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected AccessResult
    calculateResult(boolean matched)
    Returns the appropriate AccessResult based on whether there was a match and if the rule is to allow access.
    boolean
    Return true if the guard is to only be applied locally or false.
    protected boolean
    Return true if the name is to be interpreted as a regular expression or false.
    abstract AccessResult
    verifyImport(String forImport)
    Verifies whether a package name is used.

    Methods inherited from class java.lang.Object

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

    • allowed

      private final boolean allowed
      Indicates whether to allow access or not.
    • localOnly

      private final boolean localOnly
      Indicates if the rule only applies to this package.
    • regExp

      private final boolean regExp
      Indicates if the name is to be interpreted as a regular expression.
  • Constructor Details

    • AbstractImportRule

      protected AbstractImportRule(boolean allow, boolean localOnly, boolean regExp)
      Constructs an instance.
      Parameters:
      allow - whether to allow access.
      localOnly - whether the rule is to be applied locally only.
      regExp - whether the name is to be interpreted as a regular expression.
  • Method Details

    • verifyImport

      public abstract AccessResult verifyImport(String forImport)
      Verifies whether a package name is used.
      Parameters:
      forImport - the import to check.
      Returns:
      a result AccessResult indicating whether it can be used.
    • isLocalOnly

      public boolean isLocalOnly()
      Return true if the guard is to only be applied locally or false.
      Returns:
      whether the guard is to only be applied locally.
    • isRegExp

      protected boolean isRegExp()
      Return true if the name is to be interpreted as a regular expression or false.
      Returns:
      whether the name is to be interpreted as a regular expression.
    • calculateResult

      protected AccessResult calculateResult(boolean matched)
      Returns the appropriate AccessResult based on whether there was a match and if the rule is to allow access.
      Parameters:
      matched - indicates whether there was a match.
      Returns:
      An appropriate AccessResult.