5

In Eclipse (I am running 3.8.0 @ Linux (Mint 14 (Ubuntu (Debian))) at the moment), renaming variables using Refactor is an option that seems randomly available. For some code it's there, and for other code it's not.

I tried to see a pattern why some var declarations are up for renaming and others are not, but I haven't found it yet.

Why does refactor->rename not work for some code? How can I make this work?

You can see by the highlighted references that Eclipse is very aware of what should be refactored, so I don't understand what the problem is.

No problem: enter image description here

Problem: enter image description here

Redsandro
  • 11,060
  • 13
  • 76
  • 106

3 Answers3

3

You can always use Ctrl + 2 + R (Press R after appearing a small dropdown) to refactor the variable... [ Got it by chance ].

Update

working on Eclipse Neon... can't say about other older version. because it is the latest stable version at the time I am writing the answer.

Update 3-May-2017

one drawback is that it replaces all occurrences of that variable in the file. special care is required.

sanjeevprasad
  • 804
  • 1
  • 6
  • 21
1

I noticed that renaming is not available, when the project is not a JS project or if I open it with the non-default JS editor. (Spket JS Editor in my case.)

So try this:

  • Make sure in your .project file jsNature is set.

E.g. (In my case I have JS code inside a Java project):

<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
    <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
  • Right click file -> Open with -> JavaScript Editor

Works for my using Eclipse Kepler.

Jack Miller
  • 6,843
  • 3
  • 48
  • 66
  • Sometimes Eclipse tells me "refactoring cannot be performed, since its input variable does not exist". --> Just click OK, then CTRL+Z (undo) until all instances of the variable are renamed. – Jack Miller Aug 19 '14 at 07:31
0

I can rename the local variable under Aptana Studio 3.0 (Eclipse based) with the JSDT "JavaScript Editor" and in the screenshot shown JS function: https://i.stack.imgur.com/qnkJj.jpg

Nikolay Georgiev
  • 1,047
  • 1
  • 12
  • 22
  • This doesn't really address the OP's problem. You may be able to do this, but he's asking why he can't. Do you know of a difference between your system and his? –  Jun 22 '13 at 19:22
  • Thanks for the efford, but like _Mike W_ said, this doesn't really give me a clue. I am wondering if it makes a difference whether you're running Aptana as stand-alone software or as an Eclipse plugin? – Redsandro Jun 22 '13 at 20:50