Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

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.

question from:https://stackoverflow.com/questions/65931119/how-to-write-an-annotation-with-members-in-plantuml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...