Is there a way to quickly capitalize the variable name in Eclipse

Eclipse

Eclipse Problem Overview


Any refactoring tool like this?

Eclipse Solutions


Solution 1 - Eclipse

Windows

After you press Alt+Shift+R as mentioned by kostja, you can select the text you want to change, then

  • Ctrl+Shift+Y for lowercase, or
  • Ctrl+Shift+X for uppercase.

Mac OS

  • Cmd+Shift+Y lowercase
  • Cmd+Shift+X uppercase

There is no intelligence in this. It just blindly changes the case on the selected characters.

note: This tip comes from eclipse help. If you need to find it, click Help, Search, then type "uppercase". You'll find a page with lots of shortcuts.

Solution 2 - Eclipse

What I find useful is column select using Alt+Shift+A and select a column of letters. Then use Ctrl+Shift+Y or Ctrl+Shift+X to lower case or uppercase letters.

This works for eclipse on windows.

Solution 3 - Eclipse

There are a number of problems:

  • fooBar -> FooBar and vice-versa are unlikely to occur unless someone has been ignoring the Java style guidelines. (I rarely encounter such code, and when I do my initial reaction is to write off the code as beyond salvage.)

  • fooBar -> FOO_BAR and vice-versa are plausible, but pretty unusual.

  • foobar -> fooBar is also plausible, but it is problematic. It would entail Eclipse figuring out where the intended word boundaries are in a sequence of characters, and that is hard to get right.

If you look at these, they are all either unlikely to be needed much, or too hard to do properly. Hence, it doesn't surprise me that they are not supported by the standard Eclipse codebase.

Solution 4 - Eclipse

Pressing Alt+Shift+R gives you all the power to refactor your variable name to your liking. AFAIK, there is no tool or shortcut that does just the capitalizing.

Solution 5 - Eclipse

No. You'll have to use the standard rename refactoring and retype the variable name in capital letters.

Capitalizing variable names should be limited to those cases, where we change a class attribute to a "constant", and this doesn't happen that often...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser496949View Question on Stackoverflow
Solution 1 - Eclipsemartin jakubikView Answer on Stackoverflow
Solution 2 - Eclipseuser2672474View Answer on Stackoverflow
Solution 3 - EclipseStephen CView Answer on Stackoverflow
Solution 4 - EclipsekostjaView Answer on Stackoverflow
Solution 5 - EclipseAndreas DolkView Answer on Stackoverflow