Unable to link between fields in different namespaces

0 votes
asked Mar 1, 2021 in Bug by Steinybot (120 points)

Hi,

I'm having trouble creating a relation between two fields on classes from different namespaces. I expect the following to create a relation from c -> d and d -> c but it does not.

@startuml
namespace a.b {
  class C {
    c
  }
  C::c o-- e.f.D::d
}
class e.f.D {
  d
}
e.f.D::d o-- a.b.C::c
@enduml

Instead it looks like:

 ,-.   ,-.
 |C|   |D|
 |-|   |-|
 |c|   |d|
 `-'   `-'
   |
   |
,----.
|D::d|
|----|
`----'
   |
,----.
|C::c|
|----|
`----'

(namespaces missing from ASCII output)

Cheers

commented Mar 1, 2021 by Martin (8,360 points)
edited Mar 1, 2021 by Martin

Aside from you trying to forward link to a class that hasn't been defined yet - which I'm not sure is intended to be supported - there does seem to be a confliction between namespaces and qualified fields.

By changing the namespace to a package, moving your forward link to the end, and changing the namespace separator to avoid both "." and "::", I was able to achieve this:

@startuml
set namespaceSeparator $$
package a.b {
  class C {
    c
  }

}
class e.f.D {
  d
}
a.b$$C::c o-- e.f.D::d
e.f.D::d o-- a.b$$C::c
@enduml

(could use "skinparam Linetype ortho" or "left to right direction" to improve the look).

Is that what you think your diagram should look like?  Or should D be in a group "e.f" ?

But I agree that I shouldn't have had to do some of that; and there does appear to be a bug.

commented Mar 1, 2021 by Steinybot (120 points)

Thanks for the answer. 

trying to forward link to a class that hasn't been defined yet - which I'm not sure is intended to be supported

 A similar effect occurs if you have an extends clause before defining the parent type (or don't define it at all). You can also define a class multiple times and they get combined. I really like this feature / unintended side effect, it has greatly simplified things for me (I'm writing a diagram generator).

The problem with using packages is that my class names are not globally unique.

Is that what you think your diagram should look like?  Or should D be in a group "e.f" ?

Yeah, D should be in a namespace "e.f".

commented Mar 5, 2021 by poi (1,200 points)

See "Issue about Namespace and Package" at http://alphadoc.plantuml.com/doc/dokuwiki/en/poll-about-package-and-namespace#2ou4k28pt3ukk5v9fq2d

The code below produces a diagram identical to that of Martin

@startuml
!pragma useNewPackage
set separator .
class e.f.D {
  d
}
namespace a.b {
  class C {
    c
  }
  C::c o-- e.f.D::d
}
e.f.D::d o-- a.b.C::c
@enduml

commented Mar 5, 2021 by Martin (8,360 points)
edited Mar 5, 2021 by Martin
Brilliant!  (I had always assumed that webpage was historical.)

1 Answer

0 votes
answered Mar 5, 2021 by Martin (8,360 points)
edited Mar 5, 2021 by Martin

Thanks to Poi for pointing out the "useNewPackage" beta feature!

I've made it work with the OP's example (enhanced with the name clash that the OP needed to be handled).

I even managed to enable the forward use of a field name - I had to first autovivicate the e.f.C class using a hidden link.

@startuml

!pragma useNewPackage
set separator .

namespace a.b {
  class C {
    c
  }
  C::c o-[hidden]- e.f.C
  C::c o-- e.f.C::c
}

class e.f.C {
  c
}

e.f.C::c o-- a.b.C::c

@enduml

...