Class SourcePathMatcher
java.lang.Object
com.google.errorprone.util.SourcePathMatcher
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,.kt, or.ktssource file (e.g.,java/com/google/foo/Bar.java,java/com/google/foo/Bar.kt). - 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 (*, ?)
and regex grouping ((, )) are not supported. Multiple paths can be separated by | (e.g.,
java/foo/|javatests/foo/), allowing multiple paths to be combined into a single string
constant.
-
Method Summary
Modifier and TypeMethodDescriptionstatic SourcePathMatcherCreates aSourcePathMatcherfrom the given path patterns (exact file paths or directory prefixes ending with/).static SourcePathMatcherCreates aSourcePathMatcherfrom the given path patterns (exact file paths or directory prefixes ending with/).static SourcePathMatcherempty()Returns an emptySourcePathMatcher.booleanmatches(VisitorState state) Returnstrueif the compilation unit instatematches any of the patterns in this matcher.booleanReturnstrueif the given path matches any of the patterns in this matcher.Validates the given path patterns, returning an error message if any pattern is invalid, orOptional.empty()if all patterns are valid.
-
Method Details
-
empty
Returns an emptySourcePathMatcher. -
create
Creates aSourcePathMatcherfrom the given path patterns (exact file paths or directory prefixes ending with/). -
create
Creates aSourcePathMatcherfrom the given path patterns (exact file paths or directory prefixes ending with/). -
validate
Validates the given path patterns, returning an error message if any pattern is invalid, orOptional.empty()if all patterns are valid. -
matches
Returnstrueif the given path matches any of the patterns in this matcher. -
matches
Returnstrueif the compilation unit instatematches any of the patterns in this matcher.
-