如何用PlantUML中的成员编写注释?

问题描述

我想用PlantUML中的成员写一个注释。具体来说,我想在PlantUML中描述这段Java代码

public @interface Foo {
    String bar();
    String baz();
}

我尝试用 PlantUML 编写它,但它导致语法错误

@startuml
annotation Foo {
    String bar()
    String baz()
}
@enduml

plantuml-syntax-error

但是,当我省略成员时它可以工作:

@startuml
annotation Foo
@enduml

enter image description here

我该怎么办?谢谢。

解决方法

在 PlantUML 中,注解不能有成员(因此会出现语法错误)。

要为您的代码显示 UML 图,您需要使用另一种解决方案,例如将注释添加为单独的实体:

@startuml
annotation interface

class Foo {
    String bar();
    String baz();
}


interface -- Foo
@enduml

PlantUML Diagram of above code

或者在类名定义中包含注解:

@startuml
class "@interface Foo" as Foo {
    String bar();
    String baz();
}
@enduml

PlantUML Diagram of above code

,

现在可以使用成员编写注释:http://www.plantuml.com/plantuml/uml/SoWkIImgAStDuKhCoyilIIp9pCzJSClFLwZcKW22u9AYpBnqXQJ48WrDL84ge40jbqDgNWfGCm00

根据comment,它从版本 V1.2020.2 开始可用。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...