How to rename a variable in Eclipse JEE Mars 2? - java

I would like to rename a variable and all its references in my code base. I am using Eclipse Java EE IDE for Web Developers (Mars.2 Release (4.5.2)).
When I right-click, I do not see any menu item called Rename in any of the context-menus or sub-menus.
I looked up all the context menu items before posting this question. The first place I looked was the Refactor \ Rename context-menu item because that's where I would have found it in Visual Studio. I am a C# developer.

When I right-click, I do not see any menu item called Rename
The menu item is Refactor, under which you have Rename.

Select the variable pres Alt + Shift + R and type new name.
Or Select the variable -> right click -> Refactor -> Rename and type new name

It is in the context menu Refactor \ Rename....
And the keyboard shortcut is Alt+Shift+R.
You first have to select the variable you want to rename and then use either the context menu (right click) on it, or use the shortcut.

Related

Intellij IDE for Windows 7

I am using Intellij IDE on Windows 7. Here Shift + Up / Shift + Down is not working for Line selection operation. How to get this, as it is default way in other editors.
Thanks in advance.
You can change the key mapping in the settings (File -> Settings). Type in the search box (upper left) keymap. When on the keymap settings page find in the tree Main menu -> Code. There you find the Move Line Up and Move Line Down. Make a right click and select add keyboard shortcut to assign what you want. Most probably SHIFT-UP is already assigned to some action. It's up to you if you want to reassign it.

Replacing a string with classname for multiple files in eclipse [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed last month.
Improve this question
How can I search and replace a String in all files of my current project?
Let's say I have the string "/sites/default/" now I want it to be "/public/sites/default/", but there are almost 1000 files.
Goto "Search"->"File" from menubar at the top left
Enter text, file pattern and projects
Click "Replace..." button at the bottom
Enter new text click ok
Voilà...
Depending on the file type you are focused on, Ctrl+H will open up different types of search screens.
A more consistent hotkey would be using the Alt method: Tap Alt, then A, then F.
Efficient Order of Operations:
Ctrl+C the text you want to do the replacing (if available)
Highlight the text you want to be replaced
Tap ALT, then A, then F. Brings you to File Search. The selection from (2) will auto-fill the search box
In the “File name patterns” input box, type in “.java” for replacing all Java files or type in "" to replace in all files
Click “Replace…”
Ctrl+V (Paste). Or type in the value you want to do the replacing
Enter
You can find more details in my blog post: http://blog.simplyadvanced.net/android-how-to-findreplace-in-multiple-files-using-eclipse/
Use Ctrl+H for opening Eclipse search dialog, select appropriate search tab and select "Replace..." to get you to the "Search and replace" dialog
Strange but it is a two step task:
Search what you want
In the search tab right click and select replace , or replace all:
A demo at:
http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html
Tonny Madsen said it right, but sometimes this is too simplistic.
What if you want to be more selective in your replacements since not all replacements are correct for what you're trying to do?
Here's how to get more granularity to do the replacements only in certain folders, files, or instances:
First, do like he said:
Click Search --> File... OR press Ctrl + H and choose the "File Search" tab.
Enter text, file pattern and choose your Workspace or Working Set.
Then:
Click Search
When your results come up, make some folder, file, or instance selections by Ctrl + clicking on the ones you'd like to select. Ex: here's my selection. I've chosen 3 instances, 1 file, and 1 folder:
Now, right-click on your selection and go to --> Replace Selected.... Here's a screenshot of that:
Enter what you'd like to replace it "With". In my case you can see it says it is "Replacing 190 matches in 4 files". Now click OK.
Voilà!
References:
Here's the tutorial I came across that taught me this: http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html?page=2
ctrl + H will show the option to replace in the bottom .
Once you click on replace it will show as below
There is an option in search => file and shortcut is Ctrl+H. Go for further refer follow link. This is work fine with Eclipse Neon
Is there a way to find/replace across an entire project in Eclipse?
If you want to replace two lines of code with one line, then this does not work. It works in notepad++. I end up open all files in notepad++ and replaced all.
Ctrl+F gives me Find/Replace dialog box.
Or you can,
First Alt+A
Next Alt+F
Then press on Replace button.
If non of them worked:
Goto -> Window -> Preferences -> General -> Keys and search for replace then you will see binding for Find and replace. In the bottom of that window, you can add your key to Binding text box. There you can add or edit any keys as shortcut.
I have tried the following option in Helios Version of Eclipse.
Simply press CTRL+F you will get the "Find/Replace" Window on your screen

Replace text in all java files in Project

I want to replace Logger.getLogger to LogManager.getLogger in my project and project have hundreds of java files .How I do this?
for i in `find -name "*java"`; do sed -i "s/Logger.getLogger/LogManager.getLogger/g" $i; done
:)
That is very easy to be done with sublime text. Just install it and take a look at this question -> Sublime text 2 - find and replace globally ( all files and in all directories )
Search->File menu, enter the text to search for, hit the Replace... button which will give you another dialog where you can replace tex
ctrl + h is the shortcut ;)
Most IDEs have the ability to search and find where a class or method is used. In Eclipse select a class or method, right click, references, project. If you can use both at the same time, the go through and replace. Alternatively replace your current calls with a helper method that calls your current logger and then replace the logger.
If you are using eclipse click on "Search" menu than search for "File", enter the text to search for and select "enclosing project", than hit the bottom right "Replace" button. After the search action is completed eclipse will show up a dialog where you can type the text to replace. Check the preview and than complete the action.
If you're using eclipse:
Select your project with left click.
Press Ctrl-H, select FileSearch. Enter your searchg strin in 'Containing text', *.java 'File name patterns' in narrow the search to 'Selected resources'.Then press replace and you're done.

What are the different eclipse shortcuts available?

I wanted to know the different eclipse shortcuts available like when we wanted to write this
System.out.println(); then we simply write syso and hit ctrl+space
then we get System.out.println();.I do not want shortcuts like for copy ctrl+c or to cut ctrl +X
screenshot of templates
These are called "editor templates", and you can see the full list in
Window --> Preferences --> Java --> Editor --> Templates
You can also create your own there, with various placeholders, e.g. I have one isequalto defined like this:
${:importStatic(org.fest.assertions.api.Assertions.assertThat)}assertThat(${actual}).isEqualTo(${expected});
This will automatically add a static import and add cursor positions that can be navigated to with TAB. This can be invoked by typing isequalto (or just ise) and ctrl+SPACE.
For a try/catch bock, just type try and ctrl+SPACE.
What you're looking for are not shortcuts, but Templates.
Open Window -> Preferences -> Java -> Editor -> Templates and you'll see the full list.
You can even add your own templates.
GO to Help Menu in Eclipse
And Click Key Assist
The shortcuts your referring to are called templates.
You can view them all in the IDE or make your own:
Window > Preferences > Java > Editor > Templates
Basically to use any of these templates, type their name followed by CTRL + SPACE. Once you have enough of the name typed that the name is distinct, for instance syso you can use CTRL + SPACE. So you may not need to type the whole name.
see Eclipse Short Cuts
It may be for Eclipse 3 but those shortcuts have been standardised for a while.

(Eclipse RCP) How can I add shortcut text after a menu entry in toolbar?

I want to add shortcut text after the menu entry in toolbar.
For example, for "copy" menu entry in toolbar, default only a image in toolbar, and the tooltips will be "Copy (Ctrl+C)", what I need is adding "Ctrl + C" after the image of Copy menu entry, I did a lots of search, but can't find more useful material.
Also the action ( such as Copy ) has a shortcut, for example, "Ctrl + C", when our mouse hovers on the menu entry, will show "Copy (Ctrl+C)", but when I use Action.getText(), I only can get "Copy", not "Copy (Ctrl + C)"
Thanks for your help, this issue troubled me couple days.
You can show shortcut easily by using command, action and binding.
First. Create command in org.eclipse.ui.commands extension.
second, Bind shortcut and command in org.eclipse.ui.bindings extension.
If you do that, shortcut(ctrl+c) will be appeared after the command name.
There are helpful article to see tutorial:
How to make command: http://www.vogella.com/articles/EclipseCommands/article.html
Key binding: http://www.vogella.com/articles/EclipseCommandsKeybindings/article.html
It looks strange and difficult but if you master eclipse command, it will be one of the most powerful extension in RCP development.

Categories