Open
Description
After the discussion in #3827, I was intrigued by how we deal with name collisions on manipulating the AST. I've done some cursory investigations into this, and there's some truly odd behavior.
- Creating a type or type member (e.g. with
Factory.createClass()
orFactory.createMethod()
) that has a qualified name collision with some other element causes a silent overwrite of the original. - Creating a new package with
Factory.createPackage()
such that the qualified name collides with some other package, actually just returns the other package, without creating a new one. It's more or less a wrapper aroundPackage.getOrCreate()
. - Creating a new module with
Factory.createModule()
works the same way as packages. - Changing the simple name of a type, type member, package or module so as to make its qualified name collide with some other element causes two elements with the same qualified names to coexist.
This behavior is inconsistent and confusing.
The behavior of 1-3 should be consistent. An exception makes most sense to me, but returning the existing element is also an option (as is the case for 2 and 3) and less breaking as we only have to change 1.
For 4, I think we should raise an exception when applicable (not applicable if the element in question has no parent).