Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't refactor rename in Eclipse

Tags:

If I do a refactor rename on something, it tries to do it for a moment but then just reverts it right back to what it was named before. No errors or any indication that something is wrong is shown.


I just restarted Eclipse and now it's even worse. Before, at least selecting Refactor > Rename would "box" the name and pretend it's letting you do a refactor. Now, after restart, selecting Refactor > Rename does nothing.

Win7 64 bit
Eclipse Indigo build 20110615-0604

like image 568
Mike Dannyboy Avatar asked Jul 08 '12 00:07

Mike Dannyboy


People also ask

How do I rename a program in Eclipse?

To rename the project, simply right-click the project and select "Refactor/Rename...". Fill in the new name and click OK.

How do I Refactor a project in Eclipse?

Refactoring using EclipseRight clicking on a Java element in the Package Explorer view and selecting Refactor menu item. Right clicking on a Java element in the Java editor and selecting Refactor menu item. Selecting a Java element in either the Package Explorer view or Java Editor and clicking Shift + Alt + T.

What is rename refactoring?

Use the Rename refactoring to change names of symbols, files, directories, packages, modules and all the references to them throughout code. Renaming local variables or private methods can be done easily inline since only the limited scope is affected.


2 Answers

Try to delete the project from Eclipse (don't delete project contents on disk) and then reload it.

like image 160
Kevin Avatar answered Sep 23 '22 12:09

Kevin


I wanted to add some information to some other answers here.

Archenoth's answer points out you can get more information from running Preview on the rename operation. It took me a while to figure out how to get to preview: type the rename keystroke a second time to get the dialog. Sometimes Preview didn't give the error information (and neither did the quick rename without the ppoup) but clicking OK in the dialog did say more.

MutantXenu found information in the logs by going into files in the workspace, but you can also get to these within Eclipse by going to the Error Log view (from Cmd-3)

When I had this problem, the error log pointed me to this failed assertion: "Search for method declaration did not find original element" which led to some unresolved bugs. (I'm running Kepler, but the problem is apparently hard to replicate and I don't see evidence it's resolved. See here and here.)

You can see if you're experiencing this specific bug by selecting the method and using Cmd-G (or Ctrl-G: Search > Declarations > Workspace). Eclipse is unable to find the method you're trying to rename and the search comes up empty.

My case suggests it's possible the error might have to do with identically-named methods in different classes. When the problem is occuring with one method, it doesn't affect most others.

Refresh, Project->Clean, and restarting Eclipse were not helpful to me. Kevin's answer worked for me: "Try to delete the project from Eclipse (don't delete project contents on disk) and then reload it."

like image 24
Joshua Goldberg Avatar answered Sep 22 '22 12:09

Joshua Goldberg