Splicing Up Notes

0 votes
asked Aug 1, 2019 in Question / help by kjw

Extending the example I found on the Q&A I am try to apply a Diagram in a Note via a function which requires function passing.

uncomment addNote() to make it break

Can the preprocessor handle this ?

or is there a work around ?

@startuml

!function msg($source, $destination)

$source --> $destination

!endfunction

!function init_class($name)

class $name {

$addCommonMethod()

}

!endfunction

!function $addCommonMethod()

  toString()

  hashCode()

!endfunction

!function $OBJ()

  class Object {

name : token

name : flag

}

!endfunction

!unquoted function addNote($note, $as) 

    note "$note" as $as

!endfunction

component "C1" as C1 {

        note "{{\nparticipant MyA as A\nA->>B: prepare\n}}\n" as detailsNote1  

}

   

note "{{\nclass Object {\n name : token\n name : flag\n}\n}}\n" as detailsNote2

'$OBJ() 

'addNote($OBJ(), note1)

init_class("foo1")

init_class("foo2")

msg("foo1", "foo2")

@enduml

1 Answer

0 votes
answered Aug 1, 2019 by plantuml (295,000 points)

Following your idea, we added a new function %retrieve_void_func() in last beta http://beta.plantuml.net/plantuml.jar

This function is a return function, which means that it returns a String. %retrieve_void_func() takes as first argument the name of a void function to be called. Strings generated by this called void function are not output to the diagram but are returned in the returned string. Ok, this sounds difficult to understand.

Here is a first simple example :

@startuml
!function $OBJ()
class Object {
name : token
name : flag
}
!endfunction

$OBJ()
note left : foo %retrieve_void_func("$OBJ") dummy
@enduml

Knowing that, you can now have :

@startuml
!function msg($source, $destination)
$source --> $destination
!endfunction

!function init_class($name)
class $name {
$addCommonMethod()
}
!endfunction

!function $addCommonMethod()
  toString()
  hashCode()
!endfunction

!function $OBJ()
class Object {
  name : token
  name : flag
}
!endfunction

!unquoted function addNote($note, $as)
    note "$note" as $as
!endfunction

component "C1" as C1 {
        note "{{\nparticipant MyA as A\nA->>B: prepare\n}}\n" as detailsNote1 
}

note "{{\nclass Object {\n name : token\n name : flag\n}\n}}\n" as detailsNote2
$OBJ()
addNote(%retrieve_void_func("$OBJ"), note1)
init_class("foo1")
init_class("foo2")
msg("foo1", "foo2")
@enduml

Is this what you were looking for ?

commented Aug 2, 2019 by kjw

Running this up in planttext.com

addNote(%retrieve_void_func("$OBJ"), note1) generates a Function not found AddNote error.

Removing unquoted from  the function definition generates Unknown built-in function %retrieve_void_func.

Assume planttext.com is update with latest build so something seems to be adrift. 

commented Aug 3, 2019 by plantuml (295,000 points)
We did not put this beta on the online server http://plantuml.com/plantuml and I think planttext.com is using that one.

We have some tests to do before pushing this. Please wait a couple of weeks...

Sorry about that.
...