Define for part of identifiers - for use with !includesub - not working for relations

0 votes
asked Feb 25, 2022 in Bug by Jesper Balle

Hi

Thank you for a very useful piece of software!!

I would really like to repeat a piece of components so I am trying to use !define for the identifiers. It is working fine for the actual components, but not for the relations

Eg. a main file like this

@startuml

!define NAME Class1
!include sub.puml

!define NAME Class2
!includesub sub.puml!SUB

@enduml

and then a sub.puml with

@startuml

!ifndef PREFIX
!define PREFIX Class1
!endif

!startsub SUB

package PREFIX {
    'This will not replace the variable PREFIX
    'class "Class1" as PREFIX_1 {
    ' This works
    class "Class2" as PREFIX-1 {
        property1
    }

    class PREFIX-2 {
        property2
    }
}

' This will not replace the variable PREFIX
'PREFIX_1 --> PREFIX_2 : Relation for PREFIX
' This gives syntax error
'PREFIX-1 --> PREFIX-2 : Relation for PREFIX

!endsub
@enduml

1 Answer

0 votes
answered Feb 25, 2022 by Martin (8,360 points)

1) I agree it looks to be a bug that you can name a class with a hyphen but not then refer to it in a relation. 

@startuml
class "Class1" as PREFIX-1
class "Class2" as PREFIX-2
PREFIX-1 -> PREFIX-2
@enduml

2) To work with underscore instead, try using the "##" operator to separate the variable name from the suffix:

@startuml
!define PREFIX Class
class PREFIX##_1
class PREFIX##_2
PREFIX##_1 -> PREFIX##_2
@enduml

PS Technically !define has been replaced by the more powerful procedures/functions/variables, see Migration notes at https://plantuml.com/preprocessing#0625790a47906fd3

commented Feb 25, 2022 by Jesper Balle
Thank you for your fast reply.

It is working exactly as described.
Thank you!
commented Mar 4, 2022 by kirchsth (4,880 points)

you could use apostrophe too like

@startuml
class "Class2" as PREFIX-1

class PREFIX-2 {
   property2
}

"PREFIX-1" --> "PREFIX-2" : Relation for PREFIX
@enduml

...