How to find which method calls currently selected method in Eclipse? - java

In Eclipse, when you click on a method name and press the F3 button, it takes you to that method.
How can I do the reverse of this? I have a method that's overloaded (probably about 12 different instances of it), and I would like to quickly find if this particular one is being called from anywhere else.
I know you can click on the method, press Ctrl+ H, and Search for this Method in the Workspace. Is there a simpler keyboard shortcut for this?

Click on the method and press Ctrl+Shift+G to perform a Search for References in Workspace.

Ctrl+Alt+H opens the Call Hierarchy, which sounds like what you're looking for.

Related

Extract method dialog not opening in Intellij Idea

Whenever I try to refactor any code by extracting a method whether from the 'Refactor Menu' or use the shortcut - 'ctrl + alt + M', the method directly gets crated with name as 'extracted' and the dialog box doesn't open wherein I could do changes to name and privacy of method. Also, it doesn't replace any duplicate code block with the method newly created. Is there any reason why the dialog box isn't opening?
Thanks
This is a new feature in the most recent version of IntelliJ Idea (2021.3). When you extract a method there is now a small settings icon next to the replaced code to click (or you can use CTRL+SHIFT+O) and see some of the old menu-style method extraction tools.

In Eclipse, is it possible to find, where, a certain function, class or variable is called?

When you want to open the declaration of a class/function/variable in java you can press Ctrl and click on it, but is there are way to go the other way round? If you had to find all instances where a function or variable is called how would you quickly get that?
Ctrl + Alt + H shows you all the places where a variable or method is used or called.
On both Windows and Mac, right-click the method, and choose "Open Call Hierarchy."
You can use this for identifiers other than methods. For example, if a class does not have an explicit constructor, you can use this to find all the callers of its default constructor.

Why open Call Hierarchy on a method is not working

I am using Eclipse IDE 3.6 version .
Inside my code i have a method as
public APIRes execute(APIReq request) throws Exception {
// Some code
}
Could you please tell me , when i did open Call Hierarchy , nothing is shown .
Why is it so ??
The obvious solution is that there may be nothing calling that method - at least within the code that Eclipse knows about. Beyond that, we really can't say...
Maybe the problem is that Open Call Hierarchy was not searching the entire Workspace.
Click on the small down arrow (in the Call Hierarchy view window on the right; it is the "View Menu" arrow -- a triangle pointing down) in Call Hierarchy view, set the Search Scope > Workspace.
Do you mean Call Hierarchy or Class Referencing.
If your create a method and nobody calls it, what do you expect to see in the call hierarchy.
Your method is referencing the class in which the method is placed. This would be shown in the reference view.
first clear the project and refresh it and select the method press right click open call hierarchy you will get the class where method declaration is defined.

How to get eclipse to go to the ONLY implementation of an interface's method?

If I'm in an interface and pointing to a method name, what can I do to quickly go to the ONLY implementation of that method?
Using Eclipse 3.6.
F3 is the typical "go to implementation". For interfaces that go to the interface definition.
Instead use Ctrl + T to see all implementations of the interface definition. You can then easily go to the one you want with the arrow keys and Enter. I believe that the first one is automatically selected so that Ctrl-T + Enter will do what you need.
I just checked this on my Eclipse 3.6 install: Hold control (command on Mac), hover over the method name and select "Open Implementation".
You may assign a keyboard shortcut to this action by using Window > Preferences > General > Keys and searching for "Open Implementation".
In the keymap (General > Keys) search for "open implementation" and map it to whatever you want. I chose Ctrl + Shift + I. Make sure you select "Editing Java Source" in the When box. I tested it, and having the cursor over the method name and pressing Ctrl + Shift + I took me directly to the implementation instead of showing the hierarchy that you get with Ctrl + T.
Also you can see an answer to a nearly identical question for other options:
In eclipse, ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly to that implementation?
If someone still need this information nowadays (Eclipse version 2022), to jump into interface method definition starting from an #Override method, now in Eclipse you can see on the left, next to the method signature, a little white triangle. By clicking on that you will jump to the implemented interface method. here an image of the little triangle
Oterwise, if you are on a interface method definition and you need to jump to one of the implementations, you must use CTRL+T shortcut to see the list of available implementations and than click on one of them.

How to get back auto-completion after misspelling a method name in Eclipse?

When I am coding Java in Eclipse I like the auto-completion feature. With that I mean the popup with method-names that comes when you start typing in a method name for an object. Or maybe it's called something different, i.e. method-suggestions?
But the popup is hidden if I misspells a method name, and it doesn't come back if I delete the misspelled part of the method name. Is there any way to get back the popup after a misspelling without starting to type in the hole method name again?
Press Ctrl+ (Blank). For a complete list of keyboard shortcuts have a look in the eclipse "Preferences" and there "General/Keys".
You should also check out Preferences->Java->Editor->Content Assist. You'll be able to select how it acts; things like if you use it in the middle of a word should it insert or overwrite, should it show deprecated methods, the delay before it automatically appears, and it can even (try to) guess your method parameters based on the variables in the current scope.
I think you're after the Ctrl-Space keyboard shortcut.
(In Eclipse this is called Content Assist. In Visual Studio it's called IntelliSense.)

Categories