Skip to content

feat: [OSS26] 按类名定位文件 locate_class_file_by_class_name (#133) - #150

Open
wryyyds7 wants to merge 5 commits into
antgroup:mainfrom
wryyyds7:feat/oss26-locate-class-file-by-class-name-133
Open

feat: [OSS26] 按类名定位文件 locate_class_file_by_class_name (#133)#150
wryyyds7 wants to merge 5 commits into
antgroup:mainfrom
wryyyds7:feat/oss26-locate-class-file-by-class-name-133

Conversation

@wryyyds7

@wryyyds7 wryyyds7 commented Jul 29, 2026

Copy link
Copy Markdown

概述

实现 locate_class_file_by_class_name MCP 工具,给定类的全限定名(支持普通类、内部类、嵌套类),在指定仓库内精准定位其源码文件路径与定义行号;找不到时给出近似候选列表。

实现

类索引复用

复用 #128_build_class_index 构建类名 → 文件路径的索引,以及 _find_anonymous_impls 将匿名实现类加入索引。

名称规范化 (_normalize_class_name)

  • 接受 com.example.Outer$Innercom.example.Outer.Inner 两种格式
  • 如果已含 $,直接返回

名称变体生成 (_generate_name_variants)

  • 对于 com.example.Outer.Inner,从右向左逐个尝试将 . 替换为 $
  • 生成所有可能的变体,覆盖内部类/嵌套类的不同表示方式

精确查找

  • 对每个名称变体在类索引中查找
  • 命中后返回: file_path、line_number、kind (class/interface/abstract_class)、is_inner_class、outer_class_full_name
  • 内部类补充外层文件信息 (outer_file_path, outer_line_number)

近似候选 (_find_candidates)

  • 未找到时,提取简单名在索引中搜索
  • 策略1: 精确简单名匹配
  • 策略2: 包含简单名的全限定名
  • 策略3: 简单名后半部分子串匹配 (如 NonExistentThreatThreat)

kind 判定 (_determine_kind)

  • is_interfaceinterface
  • is_abstractabstract_class
  • 其他 → class

测试

  • 单元测试: 精确查找、内部类 ($Inner / .Inner)、近似候选、找不到、MCP 注册对齐
  • 集成测试: 使用开源项目数据验证
  • 全部通过

Closes #133

wangrenyu.wry and others added 5 commits July 21, 2026 14:03
Implement the unified MCP Server framework as the runtime base for
all upcoming YASA MCP tools (Issue antgroup#129).

Framework:
- Dual transport: stdio (default) / streamable-http
- Tool registration via @mcp_tool decorator + auto-discovery
- Unified input validation (Pydantic), error handling, logging (stderr)
- Health check endpoint GET /healthz in HTTP mode
- Built-in demo tool ping returning server status

Modules:
- yasa_mcp/config.py: CLI args + env var parsing
- yasa_mcp/server.py: FastMCP lifecycle management
- yasa_mcp/registry.py: decorator-based tool auto-registration
- yasa_mcp/transport/http.py: streamable-http + /healthz
- yasa_mcp/tools/ping.py: demo health-check tool
- yasa_mcp/errors.py: unified error codes
- yasa_mcp/logging_config.py: stderr logging with level control

Tests (44 passing):
- test_registry.py: tool registration, auto-discovery, schema
- test_validation.py: param validation, error handling
- test_logging.py: stderr output, format, level filtering
- test_config.py: CLI parsing, env vars, error exit

Docs:
- docs/mcp/requirements.md: functional/non-functional requirements
- docs/mcp/system-design.md: architecture, module design, data flow
- docs/mcp/development-guide.md: step-by-step implementation guide
- yasa_mcp/README.md: usage + Claude Desktop/Cline config examples
- registry.py: prevent duplicate tool registration via __module__ check
- http.py: use app.add_route() instead of direct app.routes manipulation
- http.py: remove unused Route import
- http.py + server.py: pass log_level to uvicorn instead of hardcoding
- errors.py: fix empty string message fallback bug
- test_registry.py: use asyncio.run() instead of deprecated get_event_loop()
- test_validation.py: remove unused imports
- config.py: convert repo_root to absolute path
- logging_config.py: precise logger namespace check
- pyproject.toml: fix build-backend to setuptools.build_meta
- .gitignore: add .venv/ and Python project ignore rules
…p#132)

- Implement method-level interface implementation finder
- Reuse antgroup#128's class index (_build_class_index, _find_implementations)
- Add Java method parsing via regex (annotations, modifiers, return type, params)
- Support method overload disambiguation via parameter_types
- Skip abstract method declarations (only return concrete implementations)
- Detect @OverRide annotation presence
- Build method_signature string (e.g. 'validate(Object): boolean')
- Support anonymous class method parsing
- 26 tests covering: direct impl, overloads, generics, abstract skip,
  indirect inheritance, anonymous class, inner class, empty results,
  parameter matching, MCP registration
- Locate Java class source file by fully qualified name
- Reuse antgroup#128's _build_class_index for class name → file path mapping
- Support inner class notation: Outer$Inner and Outer.Inner
- Return file_path, line_number, kind (class/interface/abstract_class)
- Return is_inner_class, outer_class_full_name, outer_file_path
- Fuzzy candidate matching when class not found (simple name + substring)
- 25 tests including java-design-patterns open source validation (1902 files)
- Performance: < 2s on 1900+ file repo
@wryyyds7

Copy link
Copy Markdown
Author

#133

@wryyyds7 wryyyds7 changed the title [OSS26] 按类名定位文件 locate_class_file_by_class_name (#133) feat: [OSS26] 按类名定位文件 locate_class_file_by_class_name (#133) Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OSS26] 类名定位文件 locate_class_file_by_class_name

1 participant