Class FileImportControl

java.lang.Object
com.puppycrawl.tools.checkstyle.checks.imports.AbstractImportControl
com.puppycrawl.tools.checkstyle.checks.imports.FileImportControl

class FileImportControl extends AbstractImportControl
Represents an import rules for a specific file. Only the file name is considered and only files processed by TreeWalker. The file's extension is ignored.
  • Field Details

    • name

      private final String name
      The name for the file.
    • patternForExactMatch

      private final Pattern patternForExactMatch
      The regex pattern for exact matches - only not null if regex is true.
    • regex

      private final boolean regex
      If this file name represents a regular expression.
  • Constructor Details

    • FileImportControl

      FileImportControl(PkgImportControl parent, String name, boolean regex)
      Construct a file node.
      Parameters:
      parent - the parent node.
      name - the name of the file.
      regex - flags interpretation of name as regex pattern.
  • Method Details

    • encloseInGroup

      private static String encloseInGroup(String expression)
      Enclose expression in a (non-capturing) group.
      Parameters:
      expression - the input regular expression
      Returns:
      a grouped pattern.
    • createPatternForExactMatch

      private static Pattern createPatternForExactMatch(String expression)
      Creates a Pattern from expression.
      Parameters:
      expression - a self-contained regular expression matching the full file name exactly.
      Returns:
      a Pattern.
    • locateFinest

      public AbstractImportControl locateFinest(String forPkg, String forFileName)
      Description copied from class: AbstractImportControl
      Search down the tree to locate the finest match for a supplied package.
      Specified by:
      locateFinest in class AbstractImportControl
      Parameters:
      forPkg - the package to search for.
      forFileName - the file name to search for.
      Returns:
      the finest match, or null if no match at all.
    • matchesExactly

      protected boolean matchesExactly(String pkg, String fileName)
      Description copied from class: AbstractImportControl
      Check for equality of this with pkg.
      Specified by:
      matchesExactly in class AbstractImportControl
      Parameters:
      pkg - the package to compare with.
      fileName - the file name to compare with.
      Returns:
      if it matches.