Sub package / namespace conflicts

0 votes
asked Dec 3, 2014 in bug by anonymous

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"
 
 
 

1 Answer

+1 vote
answered Dec 4, 2014 by rmric (2,490 points)
 
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
   }
}
 
commented Dec 5, 2014 by anonymous
Thx, it really helped.

I was writting the aliases in the wrong order... (id as displayName, not displayName as id).
commented Dec 5, 2014 by plantuml (131,770 points)
> 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.
commented Feb 23 by anonymous
Same problem.
Will this issue be fixed?
commented Feb 23 by plantuml (131,770 points)
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
...