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.

Sub package / namespace conflicts

0 votes

Hi, when I declare two subpackages (or subnamespaces) with the same names, it seems that the last one is ignored and considered a belonging of the first.

e.g. with the following code, I get Foo and ImplFoo in Root1.Element1
 
namespace Root1 {
   namespace Element1 {
      interface Foo
   }
}
 
namespace Root2 {
   namespace Element1 {
      class ImplFoo
   }
}
 
I could use the full names, but for the readability sake, I'd wish that there were a way to have aliases or automatic "full names"
 
 
 
asked Dec 3, 2014 in bug by anonymous

1 Answer

+1 vote
 
Best answer

Correct me if I'm wrong, but there's no local scope in PlantUML syntax.

Intent to declare a seoncd element with identical name is like redefining/extending the previous one.

The workaround is to play with aliases like explained here http://plantuml.sourceforge.net/qa/?qa=1742/how-can-get-components-to-have-local-scope-inside-of-packages

namespace Root1 {
   namespace "Element1" as R1_Element1 {
      interface Foo
   }
}
 
namespace Root2 {
   namespace "Element1" as R2_Element1 {
      class ImplFoo
   }
}
 
answered Dec 4, 2014 by rmric (2,520 points)
Thx, it really helped.

I was writting the aliases in the wrong order... (id as displayName, not displayName as id).
> Correct me if I'm wrong, but there's no local scope in PlantUML syntax.
> Intent to declare a second element with identical name is like redefining/extending the previous one.

Well, this is almost 100% true, except when you use "namespaces".
The concept of "namespace" has been introduced latter in PlantUML to allows local scopes.
So the example is indeed a bug: defining a namespace "Element1" within namespace "Root2" should create a new namespace different from "Element1" within namespace "Root1".
(And as you said, this would be a different story with package).

Using aliases is indeed a way to turn around this issues.

We will (hopefully) solve this in next release.
Same problem.
Will this issue be fixed?
This should be fixed now.
For example:

@startuml
namespace Root1 {
   namespace Element1 {
      interface Foo
   }
}
 
namespace Root2 {
   namespace Element1 {
      class Foo
   }
}
@enduml

http://www.plantuml.com/plantuml/uml/SoWkIImgAStDuSfBp4qjBaXCJbK8oiylCLIevb9GK408kkQavgRcmSI183El9BKe3IJbbfyF4glbgkLIG3F6YA0noJc9nSN8HZYavgK0tGC0
Support This Project Offer 250 Mo! Follow PlantUML on Twitter
...