Skip to content

[OSS26] 列出类的全部方法 list_methods_by_class_name #138

Description

@ponyha

接口介绍

给定类全限定名,一次性返回该类的所有方法清单(签名、可见性、起止行号、注解),可选附带方法源码或仅返回签名;支持是否包含从父类/接口继承的方法。

工具名

list_methods_by_class_name

背景与目标

LLM Agent 经常需要"扫一遍某个类全貌"才能决定下一步看哪个方法。文件级读 + 自己拆方法 token 太重。这个工具把类的方法清单作为一次性结构化输出返回,是上层链路的目录级入口。

输入参数

参数 类型 必填 说明
class_full_name string 类全限定名
repository_path string 仓库本地绝对路径
include_inherited bool 默认 false。true 时把继承自父类/接口的方法也列出(不返 source,只返签名)
include_private bool 默认 true
include_source bool 默认 true。false 时只返签名,适合先打目录再按需取源码

输出结构

{
  "class_full_name": "com.example.UserController",
  "file_path": "src/main/java/com/example/UserController.java",
  "class_start_line": 14,
  "class_end_line": 312,
  "extends_class": "com.example.BaseController",
  "implements_interfaces": ["com.example.RequestValidator"],
  "total_methods": 8,
  "methods": [
    {
      "method_signature": "getUser(HttpServletRequest, String): ResponseEntity<User>",
      "method_short_name": "getUser",
      "visibility": "public",
      "is_static": false,
      "is_abstract": false,
      "start_line": 87,
      "end_line": 105,
      "annotations": ["@GetMapping(\"/users/{id}\")"],
      "source": "@GetMapping(\"/users/{id}\")\npublic ResponseEntity<User> getUser(...) { ... }",
      "inherited_from": null
    }
  ]
}

验收标准

  • 正确处理嵌套类:返回当前类的方法,不串到内部类
  • 继承方法标识 inherited_from 字段
  • 构造器、静态初始化块作为特殊条目返回
  • include_source=false 时返回不带 source 的轻量版
  • 单元测试覆盖:重载、抽象方法、内部类干扰、空类
  • 中等仓库响应 < 3s

预估工作量

2-3 人日

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