Skip to content

feature: add more advanced setSimpleName that also changes the references #2095

Open
@surli

Description

@surli

Hi everyone,

I find that really counter intuitive that the reference are not considered as CtNamedElement: for example, recently I wrote a processor to rename element in Spoon, in order to do it properly I also had to rename references, then it led me to the creation of a processor of CtElement with ugly casts to finally call the same methods getSimpleName/setSimpleName.

I know there is an historical reason for that and it would break a lot of things to change the metamodel to make CtReference inherits from CtNamedElement. I also know that @monperrus point of view on that is - if I remember well - that the reference should be computed from the structural elements and not directly modified by the end users.

However I really have the feeling that the current API does not allow to easily change only structural elements: for refactorings, we need to fix the references too.

So, I see at least two solutions here:

  1. to make another interface maybe called CtAbstractNamedElement for CtReference and CtNamedElement: we keep the fact that CtNamedElement are structural elements, but we also allow to do lots of renaming/filtering by name, in using the same type
  2. a completely different solution: we use internally in Spoon the model change listener to fix the reference when we change a name of a structural element. It won't help for querying the model, but it can surely help when refactoring.

Actually we might even apply both solution.
Is it a problem you also encountered using Spoon or is it just me? And WDYT about those solutions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions