Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review: fix: Dynamic lookup issues by removing dynamic lookup #1215

Merged
merged 9 commits into from
Mar 15, 2017

Conversation

surli
Copy link
Collaborator

@surli surli commented Mar 10, 2017

The issue #1213 shows that in some cases dynamic lookup just fail to find the right class. Then we propose to remove the dynamic lookup, and to improve the setName instead.
According to @tdurieux dynamic lookup was introduced to support the clone operations: we propose instead to always use renaming operation after using clone, and then to improve renaming to also rename children of a type.

A mandatory change is then needed: to use the setName operation after putting a type in the package.

@surli surli changed the title fix: Dynamic lookup issues by removing dynamic lookup review: fix: Dynamic lookup issues by removing dynamic lookup Mar 11, 2017
@monperrus
Copy link
Collaborator

dynamic lookup was introduced to support the clone operations

no, dynamic lookup is a core design decision that was already there at the birth of Spoon more than ten years ago

@tdurieux
Copy link
Collaborator

Nope this lookup based on parents has been introduced 8 months ago to solve this issue #756

@pvojtechovsky
Copy link
Collaborator

The dynamic lookup algorithm introduced in #756, is step in wrong direction.
The dynamic lookup - old core feature of spoon - is OK and should stay there.

The problem of #756 is that client wants to rename class A to B, and it is kind of java model refactoring, which cannot be easily done by CtType#setName(), but which must be done by an appropriate refactoring algorithm, which includes check for validity of new name, conflict with other classes, etc.
So the original solution of #756, was simply wrong.

And I think that solution of this PR is not good idea too, because it tries to pretend that renaming of class is a primitive operation. What if somebody wants to rename field, variable, method, parameter, ...? Are we able to implement everything into CtNamedElementImpl ?

Suggestion: May be the CtNamedElementImpl#setSimpleName should only check what kind of element we are renaming and by default throw an exception which says "Modification of model is not primitive operation. Please use refactoring methods from package ...spoon.refactor...". That exception would be thrown optionally depending on settings of spoon launcher/factory, so after clients are warned and they change that setting with idea "I know what I am doing", they can continue renaming without further warning exceptions ...

@@ -43,6 +49,22 @@ public String getSimpleName() {
if (factory instanceof FactoryImpl) {
simpleName = ((FactoryImpl) factory).dedup(simpleName);
}

if (this instanceof CtType && !simpleName.equals("")) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not change setSimpleName here. Instead we should change the CloneVisitorGenerator to call Refactor.rename().

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor.rename()

I agree.

@@ -28,18 +28,22 @@
*/
public final class Refactoring {
/**
* Changes name of a type element.
* Changes names of the inherited reference of type qualified by oldName
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated doc

@monperrus monperrus merged commit f818e07 into INRIA:master Mar 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants