关于 generate-interface-uml
generate-interface-uml 是一项技能,可依据代码库中的相似接口生成 PlantUML 时序图和类图,帮助开发者梳理 API、实现及 IPC 调用链,也支持生成对比图。
主要功能
- 01生成时序图
- 02生成类图
- 03分析参考接口与调用链
- 04将 PlantUML 文件保存到指定目录
- 05生成可选的接口对比图
适用场景
- 01为新 API 接口编写图示文档
- 02梳理实现或 IPC 调用流程
- 03将新接口与现有接口进行比较
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ openharmonyinsight/ openharmony-skills --skill generate-interface-uml安装后在 Claude Code 中输入/generate-interface-uml确认已加载。
详细介绍
接口 UML 生成器
此技能基于代码库中现有的类似接口,帮助为新接口生成 PlantUML 时序图和类图。
适用场景
用户想为以下内容创建 UML 图(时序图、类图):
- 新 API 接口
- 新方法实现
- 接口调用链
- IPC 通信流程
工作流
步骤 1:收集基本信息
从用户提供的信息开始(通常只有接口名称),然后通过提问收集:
必要信息:
- 接口名称 - 例如:
AddGlocalBlackList、RemoveGlocalBlackList - 参数 - 输入参数及其类型是什么?
- 返回类型 - 接口返回什么?
- 参考接口 - 是否有可用作模板的现有类似接口?
可选信息(按需询问): 5. 输出目录 - PlantUML 文件应保存在哪里? 6. 图表类型 - 时序图?类图?还是两者都要? 7. 调用链终点 - 最终调用哪个类/方法?
步骤 2:分析参考接口
在代码库中搜索参考接口,了解调用链:
# Find the reference interface implementation
grep -r "SetFocusAppInfo" --include="*.h" --include="*.cpp"
需要检查的关键文件:
- 客户端接口:
RSInterfaces、RSRenderInterface - IPC 层:
RSIClientToRenderConnection、RSClientToRenderConnection - 服务端:
RSRenderPipelineAgent、RSMainThread - 目标类:接口最终执行的类
步骤 3:生成 PlantUML 图表
时序图模板
@startuml InterfaceName序列图
title InterfaceName 接口调用时序图
autonumber
skinparam maxMessageSize 150
skinparam boxPadding 10
actor "客户端应用" as Client
box "客户端进程 (Client Process)" #LightBlue
participant "RSInterfaces" as RSInterfaces
participant "RSRenderInterface" as RSRenderInterface
participant "RSRenderPipelineClient\n(IPC Proxy)" as IPCProxy
end box
box "跨进程通信 (IPC)" #LightYellow
participant "Binder/Hipc\n通信通道" as Binder
end box
box "服务端进程 (Render Service)" #LightGreen
participant "RSClientToRenderConnection\n(IPC Stub)" as IPCStub
participant "RSRenderPipelineAgent" as Agent
participant "RSMainThread" as MainThread
participant "TargetClass\n(在RSMainThread线程中执行)" as Target
end box
== 客户端调用流程 ==
Client -> RSInterfaces: InterfaceName(params)
activate RSInterfaces
RSInterfaces -> RSRenderInterface: InterfaceName(params)
activate RSRenderInterface
RSRenderInterface -> IPCProxy: InterfaceName(params)
activate IPCProxy
== 跨进程IPC调用 ==
IPCProxy -> Binder: IPC调用\nInterfaceName
activate Binder
Binder -> IPCStub: 接收IPC调用\nInterfaceName
activate IPCStub
== 服务端处理流程 ==
IPCStub -> Agent: InterfaceName(params)
activate Agent
Agent -> Agent: ScheduleMainThreadTask(\nlambda任务)
Agent -> MainThread: PostTask(\n执行InterfaceName)
activate MainThread
MainThread -> Target: TargetMethod(params)
activate Target
note right of Target
描述具体操作
end note
Target --> MainThread: 返回
deactivate Target
MainThread --> Agent: 任务完成
deactivate MainThread
Agent --> IPCStub: 返回结果\n(ERR_OK)
deactivate Agent
IPCStub --> Binder: 返回IPC结果
deactivate IPCStub
Binder --> IPCProxy: 返回IPC结果
deactivate Binder
IPCProxy --> RSRenderInterface: 返回结果
deactivate IPCProxy
RSRenderInterface --> RSInterfaces: 返回结果
deactivate RSRenderInterface
RSInterfaces --> Client: 返回结果
deactivate RSInterfaces
@enduml
类图模板
@startuml InterfaceName类图
title InterfaceName系列接口涉及的类关系图
skinparam classAttributeIconSize 0
skinparam class {
BackgroundColor<<client>> LightBlue
BackgroundColor<<service>> LightGreen
BackgroundColor<<static>> LightYellow
BorderColor Black
}
package "客户端 (Client)" <<client>> {
class RSInterfaces {
+ {static} GetInstance(): RSInterfaces&
+ InterfaceName(params): ReturnType
--
- renderInterface_: RSRenderInterface*
}
class RSRenderInterface {
+ InterfaceName(params): ReturnType
--
- renderPipelineClient_: RSRenderPipelineClient*
}
RSInterfaces --> RSRenderInterface
}
package "IPC通信层" {
interface RSIClientToRenderConnection {
+ InterfaceName(params, ErrorCode&): ErrCode
}
class RSClientToRenderConnection {
+ InterfaceName(params, ErrorCode&): ErrCode
--
- renderPipelineAgent_: sptr<RSRenderPipelineAgent>
}
RSClientToRenderConnection ..|> RSIClientToRenderConnection
}
package "服务端 (Render Service)" <<service>> {
class RSRenderPipelineAgent {
+ InterfaceName(params, ErrorCode&): ErrCode
--
- rsRenderPipeline_: std::shared_ptr<RSRenderPipeline>
}
class RSMainThread {
+ PostTask(RSTask): void
+ ScheduleTask(Task): std::future<Return>
--
- mainThreadId_: std::thread::id
}
}
package "TargetClass (静态类)" <<static>> {
class TargetClass {
+ {static} TargetMethod(params): void
--
- {static} member_: Type
}
}
RSRenderInterface --> RSIClientToRenderConnection: 通过IPC调用
RSClientToRenderConnection --> RSRenderPipelineAgent
RSRenderPipelineAgent ..> RSMainThread: ScheduleMainThreadTask
RSRenderPipelineAgent ..> TargetClass: 调用静态方法
@enduml
步骤 4:保存 PlantUML 文件
将生成的 PlantUML 文件写入指定目录:
- 使用描述性文件名:
InterfaceName_sequence.puml、InterfaceName_ClassDiagram.puml - 如有需要,添加 UTF-8 BOM 以支持中文字符
- 保存到用户指定的输出目录
步骤 5:可选 - 创建对比图
如果要与现有接口进行比较,请创建对比图,展示:
- 参数差异
- 调用链差异
- 目标类差异
要向用户提出的问题
- 接口名称:你想为哪些接口生成 UML?
- 参考接口:应参考哪个现有接口?
- 参数:新接口的参数类型是什么?
- 返回类型:接口应返回什么?
- 目标类:接口最终调用哪个类?(例如:ScreenSpecialLayerInfo、RSMainThread)
- 线程要求:是否需要在特定线程中执行?(例如:RSMainThread 线程)
- 输出目录:PlantUML 文件应保存在哪里?
使用示例
用户提供:
Generate UML for AddGlocalBlackList, RemoveGlocalBlackList, SetGlocalBlackList
提出后续问题:
- “参数类型应该是什么?” →
const std::vector<NodeId>& - “哪个现有接口类似?” →
SetFocusAppInfo - “它最终调用哪个类?” →
ScreenSpecialLayerInfo - “输出目录是什么?” → 当前代码目录
生成输出:
AddGlocalBlackList_sequence.pumlRemoveGlocalBlackList_sequence.pumlSetGlocalBlackList_sequence.pumlInterfaceName_ClassDiagram.puml
提示
- 如果代码库使用中文,请在图表标题和注释中使用中文
- 在时序图中加入
autonumber - 使用颜色区分客户端/服务端/静态层
- 添加注释说明关键操作
- 使用
== Section Name ==对相关步骤进行分组
评论
支持 Markdown