Can't refactor rename in Eclipse

25,030

Solution 1

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

Solution 2

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."

Solution 3

While renaming methods directly in the editor does not work in very rare cases and then the IDE restores the orignal method name after pressing return key - kind of "agnostic mode" :-), when I do the same via Refactoring -> Change Methode Signature, in the upper right corner I change the method name, then I receive a fully detailed error message: "An unexpected exception occured while performing the refactoring... Reason: anonymous #1 in .... in lambda #1 ... in ... Working Copy ... does not exist."

This indicates, that renaming methods triggers this failure, when the method to be renamed is used in the context of an lambda or anonymous class.

To check, comment out the occurence in the lambda or anonymous class, the refactoring/renaming could then work as expected as it did in my case.

Solution 4

I've been struggling this issue too. When I looked on Error Log View of Eclipse, I noticed that each time I tried to rename a variable or method, I was getting this kind of exception:

java.lang.reflect.InvocationTargetException at 
org.eclipse.jface.operation.ModalContext.run(ModalContext.java:421) at 
org.eclipse.jface.window.ApplicationWindow$1.run(ApplicationWindow.java:759) at
org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at 
org.eclipse.jface.window.ApplicationWindow.run(ApplicationWindow.java:756) at
org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2606) at 
org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:191) at
org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:151) at
org.eclipse.jdt.ui.refactoring.RenameSupport.perform(RenameSupport.java:197) at
org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode.doRename(RenameLinkedMode.java:361) at
org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode$EditorSynchronizer.left(RenameLinkedMode.java:119) at 
org.eclipse.jface.text.link.LinkedModeModel.exit(LinkedModeModel.java:341) at 
org.eclipse.jface.text.link.LinkedModeUI$4.run(LinkedModeUI.java:1194) at
org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134) at 
org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4041) at 
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660)

I noticed it all starts from SWT libraries. Tried to update SWT, but for some reasons I wasn't able even to find SWT installed. So I simply installed SWT Tools 3.106.0.v20170503-0851 via Help -> Install new Software, what happily solved the issue.

Solution 5

Try the following (just worked for me):

  1. Delete the project
  2. Create a new java project with the same name
Share:
25,030
Mike Dannyboy
Author by

Mike Dannyboy

Updated on November 15, 2020

Comments

  • Mike Dannyboy
    Mike Dannyboy over 3 years

    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

  • Ellen Spertus
    Ellen Spertus about 6 years
    Welcome to StackOverflow! It's not clear to me that your answer matches the question that was asked. If it does, could you please make the connection more explicit? Thank you.
  • Curtis Yallop
    Curtis Yallop about 5 years
    You can get the site-url to use in Help > Install_New_Software from here: eclipse.org/swt/updatesite.php - I used the milestone-update-site: download.eclipse.org/eclipse/updates/milestones
  • Curtis Yallop
    Curtis Yallop about 5 years
    @EllenSpertus It does match the question and solved the problem for me. This stack trace comes from the error-log window in eclipse. When using change-signature or the Refactor>Rename,click-Options, it reports the error and tells you to look at the Error-Log (plain rename without a dialog just executes for a bit then reverts my change and reports nothing). This stack trace shows a particular rename-operation exception. You can tell the stack trace matches because it has RefactoringExecutionHelper and RenameLinkedMode.doRename in it.
  • Curtis Yallop
    Curtis Yallop about 5 years
    Ok, after this fixed my problem, I renamed a couple more methods and got the same error again. Restarting Eclipse fixed it. Note that I also had to restart Eclipse the first time after installing SWT.
  • Koenigsberg
    Koenigsberg over 3 years
    8 years later, still the same nonsense.