Bug 259044 - [plan] [refactoring] Various kinds of rename refactorings do not work
Summary: [plan] [refactoring] Various kinds of rename refactorings do not work
Status: RESOLVED FIXED
Alias: None
Product: AJDT
Classification: Tools
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 2.1.1   Edit
Assignee: Andrew Eisenberg CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 259328
Blocks:
  Show dependency tree
 
Reported: 2008-12-16 18:40 EST by Andrew Eisenberg CLA
Modified: 2010-08-27 16:26 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Eisenberg CLA 2008-12-16 18:40:01 EST
Although JDT Weaving has solved many kinds of refactoring problems with Aspect elements, there are still quite a few things that do not work, or produce incorrect behavior.  This bug is here to track all the refactoring problems.
Comment 1 Andrew Eisenberg CLA 2008-12-16 18:42:51 EST
1. When moving to a new package, imports are not updated for other aspects and for target types of ITDs.
2. When doing drag and drop to a new package, the original is not removed
3. When doing copy and paste into the same package, the top level type in the new AJCU still has the old name.
Comment 2 Andrew Eisenberg CLA 2008-12-18 19:22:53 EST
Seems that #2 is a JDT problem.  See Bug 259328.
Comment 3 Andrew Eisenberg CLA 2008-12-18 22:50:36 EST
OK.  Fixed #1.  Seems that there was an escape hatch put in AJCompilationUnit.java inn the getAllTypes() method.  This method signals that the AJCU has no types if the method is being called from within a refactoring context.

Now with JDT Weaving enabled, this escape hatch can be closed.
Comment 4 Andrew Eisenberg CLA 2008-12-19 13:05:09 EST
Fixed #3.  Seems that the getPrimaryType() Method for AJCompilationUnits was always returning null.  This is because the assumption is that the primary type is a SourceType (aka Java type).  Now, I check to see if the aspect type exists first, and if so return that, otherwise, try to return a source type.

See AJCompilationUnit.getType().
Comment 5 Andrew Eisenberg CLA 2008-12-19 13:21:44 EST
I shouldn't get too happy here about fixing refactoring because there still seems to be lots of problems when the AJCU is more complicated.

Seems that the drag and drop of a more complicated aspect can cause a class cast exception.  Here is what I think is going on:

1. The aspect has a declare declaration as well as a reference to a type that will need to be added to the import statements.
2. When determining what needs to change for the refactor, a sort of compilation occurs.  During this compilation, declare declarations are converted into field declarations.
3. Because "declare" is not a real type, the compilation fails with a missing type binding for the declare.  

What we need to do is ensure that in this instance, declare declarations are ignored.
Comment 6 Andrew Eisenberg CLA 2008-12-19 14:13:49 EST
OK.  Able to fix that by making a small change to AspectsConvertingParser such that "declare" keywords are converted to "int" for use in situations where the IDE is looking for references.
Comment 7 Andrew Clement CLA 2010-02-09 11:44:31 EST
Looks like this might be the place to report this.  Are we expecting simple refactor-rename of the member name for an ITD method to work?

Running refactor-rename against 'id' here:

 void Target.id(int i) {}

causes: ('Type name cannot contain a '.') because it considers Target.id to be the name when I am just renaming the member name.

This impacts Roo usage.  I would also hope callers of the ITD get updated, but of course I can't test that out as I can't rename.
Comment 8 Andrew Eisenberg CLA 2010-02-09 13:34:47 EST
This is not working because rename refactor for Java elements sends a java parser down the target file to look for the element to be renamed.  This obviously fails because the ITD is not using Java syntax.

What is the behavior when you try to rename the ITD from a different file (ie- where it is referenced instead of being declared)?

We may need to create a new refactoring participant to get the latter to work, and we may need to create a special ITD Rename Refactoring to get the former to work.
Comment 9 Andrew Clement CLA 2010-02-09 13:48:42 EST
When attempting to rename where it is used it lets me type something in but when I press return to execute the rename it reverts to the original name immediately
Comment 10 Andrew Eisenberg CLA 2010-04-26 19:39:05 EDT
OK.  Looking into this more now.  Probably won't implement this immediately, but here is what I think needs to happen to get rename refactoring of ITDs working:

1. before advice on RenameSupport.create(RenameJavaElementDescriptor)
2. in this advice, set the descriptor's fRefactoringId to be something like 'org.eclipse.ajdt.ui.rename.itd'
3. create a new refactoring contribution by extending the associated extension point

The above ensures that our rename refactoring is instantiated instead of erroneously instantiating a JDT refactoring. (Maybe we want separate refactoring contributions for each of ITD fields, methods, and constructors.)

After that, we need to figure out how to implement the refactoring itself, and we will likely have to copy significant code from the jdt side.  

I think that would be sufficient.  In the short term, we should probably create a nice warning message saying that this is not implemented yet, rather than have Eclipse throw a class case exception.
Comment 11 Andrew Eisenberg CLA 2010-04-28 19:25:35 EDT
Try to solve for 2.1.0.
Comment 12 Andrew Eisenberg CLA 2010-06-16 18:12:04 EDT
Determining what will be tackled for 2.1.1 release.
Comment 13 Andrew Eisenberg CLA 2010-08-27 16:26:30 EDT
Rename refactoring is now known to work in all the situations described in this bug.  All tests are passing locally.