Skip to content

[OSS26] 按方法名读取方法源码 read_method_source_by_method_name #137

Description

@ponyha

接口介绍

给定方法的全限定名(可选形参类型用于重载消歧),精准返回该方法的源码片段(可选携带 Javadoc 与注解),不带文件其他部分;有重载且未消歧时返回所有候选。

工具名

read_method_source_by_method_name

背景与目标

文件级读取(read_file_by_path)是文件级粒度,LLM Agent 拿到上百行整文件后还要自己定位方法,token 开销大。本工具按"方法"为单位返回源码,是程序分析的最小颗粒上下文。

输入参数

参数 类型 必填 说明
method_full_name string 方法全限定名,如 com.example.UserController.getUser
parameter_types string[] 形参类型列表用于重载消歧;不填时:有重载则报错并返回所有候选
repository_path string 仓库本地绝对路径
include_javadoc bool 默认 true,是否带方法上方的 Javadoc 注释
include_annotations bool 默认 true,是否带方法上的注解

输出结构

{
  "method_full_name": "com.example.UserController.getUser",
  "method_signature": "getUser(HttpServletRequest, String): ResponseEntity<User>",
  "file_path": "src/main/java/com/example/UserController.java",
  "start_line": 87,
  "end_line": 105,
  "containing_class": "com.example.UserController",
  "source": "@GetMapping(\"/users/{id}\")\npublic ResponseEntity<User> getUser(HttpServletRequest req, @PathVariable String id) {\n    ...\n}",
  "javadoc": "/** Get a user by id */"
}

重载未消歧时:

{
  "method_full_name": "com.example.UserController.getUser",
  "found": false,
  "ambiguous": true,
  "candidates": [
    "getUser(HttpServletRequest, String): ResponseEntity<User>",
    "getUser(String): User"
  ]
}

验收标准

  • 正确返回方法的完整源码,包括嵌套 lambda/匿名类
  • 重载方法在不带 parameter_types 时返回 ambiguous + 候选
  • 注解、Javadoc 控制开关生效
  • 单元测试覆盖:重载、嵌套类方法、构造器、静态初始化块、抽象方法只声明
  • 中等仓库响应 < 3s

预估工作量

3-4 人日

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions