mcpField
G
generate-interface-uml

generate-interface-uml

github.com/openharmonyinsight開発3578 回インストール11 週間前に更新
リポジトリ

generate-interface-uml について

generate-interface-uml は、コードベース内の類似インターフェースを参考に、PlantUML のシーケンス図とクラス図を作成するスキルです。API の実装や IPC の呼び出し経路の整理に使え、比較図も作成できます。

主な機能

  1. 01シーケンス図の生成
  2. 02クラス図の生成
  3. 03参照インターフェースと呼び出し経路の分析
  4. 04指定ディレクトリへの PlantUML ファイル保存
  5. 05任意のインターフェース比較図の作成

活用シーン

  1. 01新しい API インターフェースの図による文書化
  2. 02実装または IPC 呼び出しフローの整理
  3. 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:基本情報を集める

ユーザーが提供した情報(多くの場合、インターフェース名のみ)をもとに始め、次の情報を集めるために質問します。

必須情報:

  1. インターフェース名 - 例:AddGlocalBlackList、RemoveGlocalBlackList
  2. パラメーター - 入力パラメーターとその型は何ですか?
  3. 戻り値の型 - インターフェースは何を返しますか?
  4. 参照インターフェース - テンプレートとして使える既存の類似インターフェースはありますか?

任意の情報(必要に応じて質問): 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:任意 - 比較図を作成する

既存のインターフェースと比較する場合、次の違いを示す比較図を作成します。

  • パラメーターの違い
  • 呼び出しチェーンの違い
  • 対象クラスの違い

ユーザーに尋ねる質問

  1. インターフェース名:UML を生成したいインターフェース名は何ですか?
  2. 参照インターフェース:参照として使用する既存のインターフェースはどれですか?
  3. パラメーター:新しいインターフェースのパラメーター型は何ですか?
  4. 戻り値の型:インターフェースは何を返しますか?
  5. 対象クラス:インターフェースが最終的に呼び出すクラスはどれですか?(例:ScreenSpecialLayerInfo、RSMainThread)
  6. スレッド要件:特定のスレッドで実行する必要はありますか?(例:RSMainThread スレッド)
  7. 出力ディレクトリ:PlantUML ファイルの保存先はどこですか?

使用例

ユーザーからの情報:

Generate UML for AddGlocalBlackList, RemoveGlocalBlackList, SetGlocalBlackList

追加で質問する内容:

  1. 「パラメーターの型は何ですか?」→ const std::vector<NodeId>&
  2. 「類似する既存のインターフェースはどれですか?」→ SetFocusAppInfo
  3. 「最終的に呼び出すクラスはどれですか?」→ ScreenSpecialLayerInfo
  4. 「出力ディレクトリはどこですか?」→ 現在のコードディレクトリ

生成する出力:

  • AddGlocalBlackList_sequence.puml
  • RemoveGlocalBlackList_sequence.puml
  • SetGlocalBlackList_sequence.puml
  • InterfaceName_ClassDiagram.puml

ヒント

  • コードベースで中国語が使われている場合は、図のタイトルや注釈にも中国語を使用します
  • シーケンス図には autonumber を含めます
  • 色分けを使って、クライアント/サービス/静的レイヤーを区別します
  • 重要な操作を説明する注釈を追加します
  • == Section Name == を使って、関連するステップをまとめます

コメント