esteinberg / plantuml4idea

Intellij IDEA plugin for PlantUML
Apache License 2.0
633 stars 113 forks source link

Rename Refactor does not understand namespaces #373

Open BenceSzalai opened 1 year ago

BenceSzalai commented 1 year ago

Rename refactor does not understand Namespaces in Class diagrams.

@startuml

namespace Foo1 {
    class Bar {}
}

namespace Foo2 {
    class Bar {}
}

Foo1.Bar <-> Foo2.Bar

@enduml

Try to rename Bar in the 4th line. It will wrongly rename Bar in the 8th line, but will not rename Foo1.Bar in the 11th one.

I know it would require parsing the namespaces, understand how local names (e.g. Bar inside Foo1) can appear different than fully qualified names (Foo1.Bar everywhere outside Foo1), so it is not a small feat, just wanted to record it.

On the other hand it would not require full grammar parsing, only applying the /^[^"\n\r]*namespace \S+ {/gm RegEx (see in action to detect namespaces and do a running count of { and } curly braces* to understand where the namespace scope ends.

*: Ignoring anything matching:

Indeed such parsing may fail if for example someone adds a comment which includes a block comment opening tag ' something... /' ...something... or adds a comment in front of the opening line /' comment '/ namepsace Foo { or similar, but those are somewhat unlikely or outright deliberate stress-test cases, unlikely to happen during real life usage...