INRIA / INRIA/spoon

feature: add more advanced setSimpleName that also changes the references

Open
#2,095 2 comments 0 reactions 0 assignees View on GitHub
discussion feature
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.