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:
/^\s*note ".*/gm - remove single line notes so we can reliably detect multiline notes
/\s*note[\s\S]*end note/gm - remove multiline line notes
/[^\/]'[^\/].*/gm - remove single line comments
/\s*\/'[\s\S]*'\//gm - remove multiline line comments
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...
Rename refactor does not understand Namespaces in Class diagrams.
Try to rename
Bar
in the 4th line. It will wrongly renameBar
in the 8th line, but will not renameFoo1.Bar
in the 11th one.I know it would require parsing the namespaces, understand how local names (e.g.
Bar
insideFoo1
) can appear different than fully qualified names (Foo1.Bar
everywhere outsideFoo1
), 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:
/^\s*note ".*/gm
- remove single line notes so we can reliably detect multiline notes/\s*note[\s\S]*end note/gm
- remove multiline line notes/[^\/]'[^\/].*/gm
- remove single line comments/\s*\/'[\s\S]*'\//gm
- remove multiline line commentsIndeed 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...