This question already has answers here:
Quick find a field or method in Eclipse's workspace
(7 answers)
Closed 8 years ago.
The Cmd + O only allow you to search for method in the current opened file, are there any easy method to search for method in your project?
CTRL+H, You can see Search For box, select Method. In Scope, select Enclosing projects.
Use "Java Search" in the search menu or move the caret on the function name in the source and press Ctrl+Shift+G (-> search for reference in Workspace).
[EDIT] If you don't know in which class the function is, then use the text search (which is called "File search"). Enter the name in the search field and then limit the search to "*.java" files.
Use Ctrl+Gto search for declarations of the method your cursor is currently sitting on, as opposed to the Shift+Ctrl+G mentioned by user1071979 which shows all references to method. kshen mentioned Ctrl+H which will give you greatest flexibility - though giving you a dialog box to fill out to go further.
F3 - open declaration
Ctrl+H - open additional search dialog
Ctrl+Shift+G -search references in workspace
1. I always prefer Ctrl + F to find methods, variable etc...........
2. This also gives the functionality to replace one or all the names with the one you want to...
3. Ctrl+H is also very helpful for finding method, variables, package,etc....
Related
I have a Java project organized using Eclipse in linux. I want to migrate this project to Windows. But there are so many java files with only case differences in names, like AM.java, am.java, Am.java, aM.java. These four files cannot exist together in one directory under Windows. So I need to rename these files in linux before migration. like:
AM.java -> AM1.java
am.java -> am2.java
Am.java -> Am3.java
aM.java -> aM4.java
Because the java classes invoke each others, so we cannot simply rename the java file names. All references inside the files should be replaced at the same time. I know there's a rename function in Eclipse. But there are so many java classes that I cannot rename them mannually, is there a script way or program way to achieve this? based on Eclipse or other Java IDEs?
EDIT
There're some classes named a.java and A.java. Also there're many variables and methods named a,A. So there will be like this:
File 1:
class A
{
...
}
File 2:
int A = 1;
File 3:
int A(int a, int b)
{
return a + b;
}
All I wanna to change is the class A, not the variable or method A. So we cannot simply replace the whole word, a java grammer parser seems to be necessary?
Use Krusader file explorer. Use Multi Rename feature. It is based on krename.
Installing on Windows
Installing on Linux
After renaming files as said above import the projects in eclipse. This shows many compiler errors as references are not updated. Use Search dialog(opens on pressing Ctrl + H) to update the references. Repeat this for all 4 cases mentioned in your post one by one.
Refer this and this.
Edit
After looking at your comment:
Hope you completed part 1 and its working(?). If so then,
Just find all search term/key(Ex: AM) in entire workspace using search dialog
Press Ctrl + A to select all search results.
Right click on the selection then select Replace All then enter replace word ex:AM1
Press OK
Note: Don't forget to select Case Sensitive and Whole World option while searching and file extension .java.
You have to do it JUST 4 times for 4 cases.
I have an old java project which contains more than 100 source files for which I need to add log4j, need to append all the data inside System.Out.println to log.info. Find and replace with reg expression might help me out with this. I am using eclipse 6.
You can use the eclipse feature Search feature it is very good for searching within the files as well. It is on eclipse toolbar Search>Java Search
In the search string type in the method name and then select "method" radio box. and hit search.
It is self explanatory you can search method, constructors extra
It is also very good if you want to search a string within the filename as well.
In eclipse I would use Ctrl+H to bring up the search menu. Go across the tabs at the top until you get to "File Search" type in your search string, "System.out.println(", tell it to search in your project for *.java files and then hit the replace button.
sed -i "s/System.out.println/log.info/g" `grep System.out.println -rl /path`
When I need to interpolate a String variable into a quoted string literal in the Eclipse java editor, I generally type "++" and eclipse usually inserts another " after the latter one, so I then have to go past it with arrow keys and then backspace to remove the duplicate, then go insert some spaces in between the "++" and type my variable name.
This seems like a lot of work. I have found Practically Macro, but I thought there might be something built in for this situation which is very common for me.
I'm not sure if this shortcut exists, try doing CTRL+SHIFT+L when the string is selected.
Also there is this link which has a whole bunch of nice keyboard shortcuts, I know it may not answer the question completely but maybe it'll get you one step closer. :)
**** Edit: In that link the "Ctrl-2 something" post looks promising.****
The most relevant built-in feature is maybe the "Pick out part of a string" quick assist:
insert a space (or anything else) where you want to add a variable,
select it,
press Ctrl+1,
select the "Pick out part of a string" quick assist,
insert your variable name.
Reference: "Pick out part of a string" section in this post.
As a long time Eclipse user, I'm playing around a little bit with IntelliJ IDEA 10. I can't seem to find out how to perform an "Assign statement to new local variable" code completion.
Feature explanation:
I type something like
new BufferedOutputStream(out)
and then hit Cmd (or Ctrl)+1 and enter, and Eclipse changes the line into:
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(out);
At the same time, I can type over "bufferedOutputStream" immediately to rename it (or select from the options "bufferedOutputStream", "outputStream" and "stream" from a dropdown).
I use this feature for absolutely every assignment, and it's an enormous time saver - this must be available in IDEA, too - but where is it hidden?
Refactor | Introduce Variable (Ctrl+Alt+V on Windows). Note that you don't need to select the text if it's the only text in the current line. Then you can change the variable name in-line just like you've described and press Enter to complete editing.
Another way is to use the Postfix Completion:
Type .var (or just .v to select it from the list) and confirm it with Enter.
As CrazyCoder mentions you can use Ctrl+Alt+V. Also instead of selecting the expression, clicking into somewhere in your expression and using Ctrl+W to expand scope is very useful while using introduce refactorings. Extract refactorings are:
Extract variable: Ctrl+Alt+V
Extract field: Ctrl+Alt+F
Extract method: Ctrl+Alt+M
Extract parameter: Ctrl+Alt+P
Extract constant: Ctrl+Alt+C
Also, Idea is a polygot editor so you can use these extract refactorings for other file types like js or html also (not all refactorings work in all file types but Ctrl+W works mostly).
There are more extract refactorings which do not have shortcuts which you can access from Refactor|Extract menu (both menu bar and context menu). To quick access all refactorings you can use Ctrl+Alt+Shift+T for a popup menu.
As a last word, I highly encourage you using "Tip of the Day" (Help|Tip of the Day). It is a fast way to learn many helpful features of Idea.
It's not as nice as Eclipse, but you can try the following:
new BufferedOutputStream(out)
Select the expression above, either with your mouse (or by using Ctrl+W).
Then hit Ctrl+Alt+V to Introduce a Variable or (Ctrl+Alt+F to Introduce a Field)
Easiest is, hit Alt+Enter, you will be offered with a list of options, and just select "Introduce local Variable".
How to search a partifular function in a particular project in Eclipse
e.g. if I want to search a function with name xyz how do I do it?
Use "Java Search" in the search menu or move the caret on the function name in the source and press Ctrl+Shift+G (-> search for reference in Workspace).
[EDIT] If you don't know in which class the function is, then use the text search (which is called "File search"). Enter the name in the search field and then limit the search to "*.java" files.
If you don't know where the method is located, use text search with a root of your whole project, working set or even the whole workspace if you've really got no idea where it might be; Search → File… brings up a dialog which lets you enter exactly what you are looking for. You'll have to sort through all the things it finds (using the Search window) to identify the real match from among the false positives, but that's better than nothing.
You can write some code that uses that function and then use the [Ctrl] + [Click] trick to go to its implementations.
Check out nWire for Java. It has a quick search feature: start typing and it will instantly show results which include types, interfaces, methods, fields and other artifacts. It has a lot more features.
In Eclipse Neon 4.6 there's CTRL+H (from the menu Search -> Search) then we can use either the "File search" or "Java Search" tabs. both are very useful