johnlinp
johnlinp

Reputation: 933

How to write an annotation with members in PlantUML?

I want to write an annotation with members in PlantUML. Specifically, I want to describe this Java code in PlantUML:

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

I tried to write it in PlantUML, but it causes syntax error:

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

plantuml-syntax-error

However, it's working when I omit the members:

@startuml
annotation Foo
@enduml

enter image description here

What should I do? Thanks.

Upvotes: 2

Views: 1870

Answers (2)

johnlinp
johnlinp

Reputation: 933

It's possible to write annotations with members now: http://www.plantuml.com/plantuml/uml/SoWkIImgAStDuKhCoyilIIp9pCzJSClFLwZcKW22u9AYpBnqXQJ48WrDL84ge40jbqDgNWfGCm00

According to the comment, it's available starting at version V1.2020.2.

Upvotes: 1

Potherca
Potherca

Reputation: 14630

In PlantUML, annotations can not have members (hence the syntax error).

To display a UML diagram for your code, you will need to use another solution, like adding the annotation as a separate entity:

@startuml
annotation interface

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


interface -- Foo
@enduml

PlantUML Diagram of above code

Or include the annotation in the class name definition:

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

PlantUML Diagram of above code

Upvotes: 0

Related Questions