antgroup / antgroup/YASA-Engine
[OSS26] 按方法体模式搜代码 search_code_by_body_pattern
Open
Nobody has claimed this yet.
OSS26-中等难度
- Dominant language
- TypeScript
- Stars
- 323
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
接口介绍
在方法体内按正则模式匹配代码片段,定位调用、赋值、异常处理等结构;命中位置返回所在方法的全限定名,与签名级搜索的核心区别是知道"命中点属于哪个方法"。
工具名
search_code_by_body_pattern
背景与目标
签名级搜索只能命中方法签名本身,本工具解决方法体内部的模式匹配,适合:
- 找所有调用了
Runtime.exec(...)的方法 - 找所有 catch 了异常但只打了 log 没 rethrow 的方法
- 找所有读取
request.getParameter后直接拼到 SQL 的方法
比签名搜索难一档:方法体可能横跨多行,需要 AST 边界感知,不能用纯 line regex。
输入参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
pattern |
string | 是 | 正则模式,如 Runtime\s*\.\s*exec\s*\( |
repository_path |
string | 是 | 仓库本地绝对路径 |
path_prefix |
string | 否 | 限定搜索子目录 |
language |
string | 否 | 默认 java |
multi_line |
bool | 否 | 默认 true,跨行匹配 |
max_results |
int | 否 | 默认 100 |
输出结构
{
"pattern": "Runtime\\s*\\.\\s*exec\\s*\\(",
"total_matches": 5,
"results": [
{
"file_path": "src/main/java/com/example/Cmd.java",
"containing_method": "com.example.Cmd.run",
"method_start_line": 42,
"method_end_line": 58,
"match_line": 47,
"match_snippet": "Runtime.getRuntime().exec(userInput);",
"snippet_with_context": " public void run(String userInput) {\n ...\n Runtime.getRuntime().exec(userInput);\n ...\n }"
}
]
}
验收标准
- 命中位置必须返回所在方法的全限定名(
containing_method),这是与关键词搜索的关键区别 - 多行匹配正确(默认 multi_line=true)
- 命中位置必须在真正的方法体内,不能命中字段初始化、import、注释
- 单元测试覆盖:跨行匹配、嵌套方法(lambda/匿名类)、注释内伪命中过滤
- 中等仓库响应 < 5s
预估工作量
3-5 人日(关键在方法体边界识别)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing signature-level search entry point and its tests, then trace how UAST identifies method boundaries. Implement the method-body pattern search against the stated inputs and output fields, and verify multiline matches, nested methods, comment filtering, and the under-5-second response target.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- devtools, search, security
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100