Skip to content

[OSS26] 查找方法被调用点 find_callers_by_method_name #139

Description

@ponyha

接口介绍

反向引用查询:给定一个方法的全限定名,返回仓库内所有调用该方法的位置 — 包括调用方所在方法、行号、调用表达式片段;支持把通过父类/接口间接调用到该方法的位置也算上。

工具名

find_callers_by_method_name

背景与目标

调用关系是程序分析的核心。从安全审计角度看:

  • 找到所有调用 Runtime.exec 的位置 → 命令注入入口
  • 找到所有调用 Cipher.getInstance("DES") 的位置 → 弱加密风险定位
  • 修一个 API 时确认所有上游调用都更新了

这是 YASA 跨仓审计的基础能力之一,本任务先做单仓库版,后续可扩展跨仓。

输入参数

参数 类型 必填 说明
method_full_name string 被调方法全限定名
parameter_types string[] 形参类型,重载消歧
repository_path string 仓库本地绝对路径
include_test_code bool 默认 false
include_inherited_callers bool 默认 true。true 时:调用方法的实际类型是子类,但目标解析到父类方法也算上
max_results int 默认 200

输出结构

{
  "target_method": "com.example.dao.UserDao.findById",
  "total_callers": 12,
  "callers": [
    {
      "caller_method_full_name": "com.example.service.UserService.getUserOrThrow",
      "file_path": "src/main/java/com/example/service/UserService.java",
      "line_number": 47,
      "call_expression_snippet": "User user = userDao.findById(id);",
      "caller_class": "com.example.service.UserService",
      "is_test_code": false
    }
  ]
}

验收标准

  • 正确解析以下调用形式:
    • 普通实例调用 obj.method(...)
    • 静态调用 Cls.method(...)
    • 链式调用 a.b().method(...)
    • 方法引用 Foo::method
    • 通过接口/父类调用(由 include_inherited_callers 控制)
  • 跳过注释、字符串内的伪命中
  • 单元测试覆盖:静态/实例/方法引用/链式/匿名类内调用
  • 中等仓库(~5k Java 文件)响应 < 10s
  • 必要时建立调用图索引(可作为后续上游链路工具的底座)

预估工作量

7-10 人日(团队协作:索引构建 + 类型解析 + 调用点提取分头做)

Metadata

Metadata

Assignees

No one assigned

    Labels

    OSS26-TeamOSS26 需要团队协作的复杂任务

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions