Eclipse IDE search a function with given name - java

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

Related

Is there an easy way to search for all LOV's in a given Application/Project?

I am working on a fairly large project. I need to find all LOV's in a single application and modify them. The application has about 4 projects. There might be about 300 LOV's. Is there an easy way to search for these? Could I regex this? Is there a way to get a data model diagram of all LOV's.
Any response is appreciated. Thanks in advance.
A LOV is defined by one or more tags depending on the kind of LOV (select one choice, combobox, input select one choice,...).
You can use any tool that can look for text inside files to search for specific tags.
As you did not tell us the framework you use I give you a sample for the tag ADF selectOneChoice uses:
af:selectOneChoice
So you can search the projects folders for all files containing this text. As you tagged the question with JDeveloper, you can use JDevs Find->'Find in Files...' menu option. In the dialog you get, you enter the right data where to look (scope) and what to look for(Search Text). There are more options you can use to get faster and better results. Click on the '?' button to get more help on how to use this feature.

How to search for a method name in Eclipse [duplicate]

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

How to find and replace System.out.println with log.info using reg expression in eclipse

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`

Eclipse shortcut to insert variable in string literal

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.

IDEA: "Assign statement to new local variable"?

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

Categories