Class SourcePathMatcher

java.lang.Object
com.google.errorprone.util.SourcePathMatcher

public final class SourcePathMatcher extends Object

Matcher for canonical source file paths supporting exact source file paths and directory prefixes.

Matches are evaluated against canonical repository/workspace-relative paths as returned by ASTHelpers.getSourcePath(CompilationUnitTree).

Supported Pattern Syntax

  • Exact file paths: Matches the exact relative path for a .java source file (e.g., java/com/google/foo/Bar.java).
  • Directory prefixes: Trailing / matches any file in the directory hierarchy (e.g., java/com/google/foo/).

Patterns must be repository-relative and must not start with a leading /. Wildcards (*, ?) are not supported.

  • Method Details

    • empty

      public static SourcePathMatcher empty()
      Returns an empty SourcePathMatcher.
    • create

      public static SourcePathMatcher create(String... pathPatterns)
      Creates a SourcePathMatcher from the given path patterns (exact file paths or directory prefixes ending with /).
    • create

      public static SourcePathMatcher create(Iterable<String> pathPatterns)
      Creates a SourcePathMatcher from the given path patterns (exact file paths or directory prefixes ending with /).
    • matches

      public boolean matches(String canonicalPath)
      Returns true if the given canonical path matches any of the patterns in this matcher.
    • matches

      public boolean matches(VisitorState state)
      Returns true if the compilation unit in state matches any of the patterns in this matcher.