Welcome to PlantUML Q&A, where you can ask questions and receive answers from other members of the community.

You can also submit new features request and vote for them.

how to refer to methods with parameters / return values

0 votes

How can I attach a note to the following field/method?

@startuml

class A {

{static} int counter

+void {abstract} start(int timeout)

}

@enduml

asked Mar 30 in Wanted features by pihentagy (130 points)
It would be nice to be able to use the "as" syntax for methods and fields:

class "AAAAAAAAAA"  as A {

"{static} int counter" as StaticCounter

"+void {abstract} start(int timeout)" as start
}

after this we can do
note left of A::start
  Yet **another**
  note on several lines.
end note

1 Answer

0 votes

We fix this in last beta (beta17):
https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0

You can now have:

@startuml
class A {
{static} int counter
+void {abstract} start(int timeout)
}
note right of A::counter
  This member is annotated
end note
note right of A::start
  This method is now explained in a UML note
end note

@enduml


 

answered Mar 31 by plantuml (126,850 points)
Hello,
It is working with your example, but it is not working to explain the difference of 2 functions with the same name:

@startuml
class A {
{static} int counter
+void {abstract} start(int timeoutms)
+void {abstract} start(Duration timeout)
}
note right of A::counter
  This member is annotated
end note
note right of A::start
  This method with int
end note
note right of A::start
  This method with Duration
end note
@enduml
By chance, there is a way with your example:

@startuml
class A {
{static} int counter
+void {abstract} start(int timeoutms)
+void {abstract} start(Duration timeout)
}
note right of A::counter
  This member is annotated
end note
note right of A::start(int
  This method with int
end note
note right of A::start(Duration
  This method with Duration
end note
@enduml

There cannot be space after :: so this won't work in many case.
We don't like "as" keyword proposal (sorry about that) because today PlantUML does not really try to parse the class body itself (that is member/fields/methods...)
We can implement some wildcard option, so that people would be able to use:
note right of A::start*timeoutms
Or we could allows space after :: (with quotes).
Not sure which is best.
Thanks. I understand your point of view. It is OK for method, but not field.
For me A::"string with spaces " is better than  A::start*timeoutms, because in c * is used for pointer.
One other possibility is to encode the text without space like html.

@startuml
class A {
{static} int counter
double counter
+void {abstract} start(int timeoutms)
+void {abstract} start(Duration timeout)
}
note right of A::counter
  This member is annotated
end note
note right of A::start(int
  This method with int
end note
'Proposal
note right of A::"double counter"
  second counter
end note
'or
note right of A::double counter
  second counter
end note

@enduml
Ok, with last beta (beta18)
https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0
You can now have
@startuml
class A {
{static} int counter
+void {abstract} start(int timeoutms)
+void {abstract} start(Duration timeout)
}
note left of A::counter
  This member is annotated
end note
note right of A::"start(int timeoutms)"
  This method with int
end note
note right of A::"start(Duration timeout)"
  This method with Duration
end note
@enduml
Thanks, it is perfect for me
Support This Project Offer 250 Mo! Follow PlantUML on Twitter
...