类 GrepTool
java.lang.Object
com.agentsflex.tool.commons.GrepTool
Pure Java grep implementation that doesn't require external ripgrep installation. Uses
Java NIO.2 for file traversal and regex Pattern/Matcher for searching.
Generated with Claude Code AI assistant.
- 作者:
- Christian Tzolov, Claude Code, Michael Yang
-
嵌套类概要
嵌套类修饰符和类型类说明static classprivate static interfaceFunctional interface for file processingstatic enumOutput modes for grep -
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static GrepTool.Builderbuilder()private List<PathMatcher>buildGlobMatchers(String glob, String type) Build glob matchers from glob pattern or file typeprivate intcountMatchesInFile(Path file, Pattern pattern) Count matches in a fileprivate booleanfileContainsPattern(Path file, Pattern pattern) Check if file contains the patternfindMatchesWithContext(Path file, Pattern pattern, int beforeContext, int afterContext, boolean lineNumbers) Find matches with context linesgrep(String pattern, String path, String glob, GrepTool.OutputMode outputMode, Integer contextBefore, Integer contextAfter, Integer context, Boolean showLineNumbers, Boolean caseInsensitive, String type, Integer headLimit, Integer offset, Boolean multiline) private booleanisIgnoredPath(Path path) Check if a file should be ignored (common ignore patterns)private booleanmatchesGlob(Path file, List<PathMatcher> matchers) Check if a file matches any of the glob matchersprivate voidprocessFiles(Path searchPath, List<PathMatcher> matchers, GrepTool.FileProcessor processor) Process files in the search pathprivate StringsearchContent(Path searchPath, Pattern pattern, List<PathMatcher> matchers, int beforeContext, int afterContext, boolean lineNumbers, Integer headLimit, Integer offset) Search and show matching content with context (content mode)private StringsearchCount(Path searchPath, Pattern pattern, List<PathMatcher> matchers, Integer headLimit, Integer offset) Search and count matches per file (count mode)private StringsearchFilesWithMatches(Path searchPath, Pattern pattern, List<PathMatcher> matchers, Integer headLimit, Integer offset) Search for files containing matches (files_with_matches mode)
-
字段详细资料
-
maxOutputLength
-
maxDepth
-
maxLineLength
-
workingDirectory
-
FILE_TYPE_EXTENSIONS
-
-
构造器详细资料
-
GrepTool
public GrepTool()已过时。Usebuilder()instead.Default constructor with default values for all configuration parameters. -
GrepTool
Constructor with configurable parameters.- 参数:
maxOutputLength- Maximum output length before truncation (default: 100000)maxDepth- Maximum directory traversal depth to prevent infinite recursion (default: 100)maxLineLength- Maximum line length to process, longer lines are skipped (default: 10000)workingDirectory- The working directory to use when path is not specified. If null, defaults to current JVM working directory.
-
-
方法详细资料
-
grep
-
buildGlobMatchers
Build glob matchers from glob pattern or file type -
matchesGlob
Check if a file matches any of the glob matchers -
searchFilesWithMatches
private String searchFilesWithMatches(Path searchPath, Pattern pattern, List<PathMatcher> matchers, Integer headLimit, Integer offset) throws IOException Search for files containing matches (files_with_matches mode)- 抛出:
IOException
-
searchCount
private String searchCount(Path searchPath, Pattern pattern, List<PathMatcher> matchers, Integer headLimit, Integer offset) throws IOException Search and count matches per file (count mode)- 抛出:
IOException
-
searchContent
private String searchContent(Path searchPath, Pattern pattern, List<PathMatcher> matchers, int beforeContext, int afterContext, boolean lineNumbers, Integer headLimit, Integer offset) throws IOException Search and show matching content with context (content mode)- 抛出:
IOException
-
processFiles
private void processFiles(Path searchPath, List<PathMatcher> matchers, GrepTool.FileProcessor processor) throws IOException Process files in the search path- 抛出:
IOException
-
isIgnoredPath
Check if a file should be ignored (common ignore patterns) -
fileContainsPattern
Check if file contains the pattern -
countMatchesInFile
Count matches in a file -
findMatchesWithContext
private List<String> findMatchesWithContext(Path file, Pattern pattern, int beforeContext, int afterContext, boolean lineNumbers) Find matches with context lines -
builder
-
builder()instead.