VSCode PlantUML插件命令行生成源码对应的puml文件

使用PlantUml VSCode 快速生成UML
1.PlantUML

https://plantuml.com/zh/

一个UML的DSL语言, 网站有快速的显示地方, 语法也很简单.

https://plantuml.com/zh/running

有各种工具

目前推荐VS Code打开

2.GraphViz

绘图的

http://www.graphviz.org/Download_windows.php

需要设置一个路径

GRAPHVIZ_DOT

xxx\Graphviz\bin\dot.exe

3.VSCode 需要安装两个插件: PlantUML 和 Graphviz Preview

点击 VSCode 左下角齿轮按钮进入设置,在用户设置脚本中添加 “graphviz-preview.dotPath”: “D:/program files/Graphviz/bin/dot.exe” 并保存设置:

到这里如果你是想在VSCode 里面想自己写PlantUML, 预览, 导出都是可以的.

之后的是c# 自动导出的.

4.netCore 3.0

下面的工具需要用到这个,

https://dotnet.microsoft.com/download/dotnet-core/3.0

  1. c#代码生成UML

https://github.com/pierre3/PlantUmlClassDiagramGenerator

windows 命令行中安装

dotnet tool install --global PlantUmlClassDiagramGenerator --version 1.2.0

之后就可以通过命令来吧C#代码生成plantUML

puml-gen InputPath [OutputPath] [-dir] [-public | -ignore IgnoreAccessibilities] [-excludePaths ExcludePathList] [-createAssociation]
InputPath: (Required) Sets a input source file or directory name.
OutputPath: (Optional) Sets a output file or directory name.
If you omit this option, plantuml files are outputted to same directory as the input files.
-dir: (Optional) Specify when InputPath and OutputPath are directory names.
-public: (Optional) If specified, only public accessibility members are output.
-ignore: (Optional) Specify the accessibility of members to ignore, with a comma separated list.
-excludePaths: (Optional) Specify the exclude file and directory.
Specifies a relative path from the “InputPath”, with a comma separated list.
-createAssociation: (Optional) Create object associations from references of fields and properites.
-allInOne: (Optional) Only if -dir is set: copy the output of all diagrams to file include.puml (this allows a PlanUMLServer to render it).
examples

puml-gen C:\Source\App1\ClassA.cs -public
puml-gen C:\Source\App1 C:\PlantUml\App1 -dir -ignore Private,Protected -createAssociation -allInOne
puml-gen C:\Source\App1 C:\PlantUml\App1 -dir -excludePaths bin,obj,Properties

### 如何在 VSCode生成类图 #### 使用 PlantUML 扩展绘制类图 为了能够在 VSCode 中使用 PlantUML 绘制类图,需先完成环境配置。这涉及到安装 Java 环境,因为 PlantUML 的运行依赖于 Java[^4]。 一旦 Java 安装完毕并通过 `java -version` 命令验证无误之后,可以在 VSCode 内部通过 Extensions 视图(快捷键 Ctrl+Shift+X)搜索并安装名为 "PlantUML" 的官方插件来支持 UML 图表的编辑与预览功能[^1]。 接着,在项目文件夹下创建 `.puml` 文件用于编写 PlantUML 语法描述的图表定义语句。下面是一个简单的例子展示如何用 PlantUML 创建两个相互关联的类: ```plantuml @startuml class Customer { + String name + int age } class Order { + double totalAmount } Customer "0..*" -- "1" Order : places @enduml ``` 此代码片段展示了客户 (Customer) 和订单 (Order) 类之间的一对多关系,其中每个顾客可以有多个订单,而每一个订单只属于一位特定的顾客。 对于 Python 用户来说,除了手动绘制外还可以借助 Graphviz 结合 pyreverse 自动化生成基于现有源码结构的 UML 类图。具体操作是在终端执行 pip install graphviz pycodestyle 来获取必要的库;随后利用命令行工具 pyreverse 对目标模块进行分析处理从而导出对应的 .dot 文件最后再转换成图像形式查看[^2]。 至于 Java 开发者,则可以直接依靠集成到 IDE 当中的 Javadoc 注解配合某些特殊插件实现自动化文档及图形化的类层次展现方式[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值