IntelliJ- how to find method calls? - java

I have just started using IntelliJ for the first time on a project that I've just started working on, and am still getting familiar witht the setup and how it works. Previously when working on Java projects, I have predominantly used Eclipse as my IDE.
In Eclipse, when working on a particular method, there was the functionality to right-click the method, and select the option 'Find All References', to list everywhere in the project that the method was called.
I have made a few changes to the definitions of a couple of methods (the changes have mainly been in their parameters) in the project in IntelliJ, and now want to 'Find All References' on the methods, so that I can ensure that they are called with the correct parameters. However, when I right-click on the method definitions, and select 'Find Usages' from the menu, I get a popup message displaying the following warning:
Method 'abc() of class def' implements method of interface ghi. Do you want to find the usages of the base method?
Regardless of whether I select 'Yes' or 'No', the search results only return one result- the source file & line that I clicked on in order to do the search.
My guess is that there's something I need to change in the settings somewhere to ensure that doing this returns all of the places where that particular method is used in the code? I checked with a colleague, and when they do exactly the same thing, they get a list of all of the places within the project where that method is called...
How can I resolve this, so that I can find all of the method calls for the one I have highlighted?

Have you tried CTRL+click on method declaration?

I usually use Ctrl-Alt-H for Hierarchy and get a list of all callers even in tests.

By selecting the method name (double click on it) and pressing alt+ctrl+shift+f7 keys, a window named Fined Usages will popup. There is a checkbox in this window, you can check: Usages, Overriding methods, Search for text occurrences or Skip result tab with one usage. Then you can set the scope on All Places and click on Find. So, a search window appears and all classes and methods that called this method are listed there.

Alternatively, you can use "Find in path" option which lets you search for a raw string in any files in the project (although it's of course configurable). It is under Ctrl-Shift-F.

Related

Intellij (or other) - Possible to see a graph/tree of all calls made in Java?

I'm working on a project in Intellij Ultimate 14. I'm not looking to do a live debugging of the application to trace calls. The time it would take to follow all code paths would be insane. I'm hoping that Intellij has some kind of analysis tool that can provide me with all calls made within the project given a particular starting point or points. So if I start with method A(), and A calls B() and C(), and B calls D(), then I'd like to be able to have that information collected and exported/displayed somehow. I'd also like annotations on any method to be included and it would need to be able to resolve interfaces to implementations where possible (many interfaces have only one), or perhaps allow me to select an implementation if needed. I don't think Intellij has this sort of functionality built in beyond being able to find all callers/callees of a single specified method. Does such a tool exist?
In IntelliJ, when your cursor on a callable method name, pressing ctrl-alt-H will bring you to "call Hierarchy" window.
Same if you prefer menu: "Navigate->call Hierarchy"
Atlas (http://www.ensoftcorp.com/atlas) is an Eclipse plugin that can do this. There is a feature called a "smart view" that does what you described. Select the "call" relation and then click on a method name and the view will display the parent and child methods in the call graph. The graph is intereactive, so if you double click on a node or edge in the graph it jumps to the corresponding source code. There are other relationships as well such as control flow and data flow, but the call graph is what you described in your question.
This doesn't graph who calls whom in general, but for a given value you can see a tree of callers that produce or consume that value
To see the tree of calls that produce a value, right-click on the value and select Analyze | Analyze Data Flow to Here.
To see a tree of all of the calls that read a value, right-click on the value and select Analyze | Analyze Data Flow from Here.
There is also Navigate | Call Hierarchy that can switch between caller and callee trees using the buttons at the top.

IntelliJ IDEA code completion show all constructor signatures?

I'm considering switching from Eclipse to IntelliJ IDEA, but there's one thing holding me back: the autocomplete. Eclipse shows me all the information I want from the start whereas IntelliJ holds back some information. The only thing I'm still missing is separate entries in code completion for each constructor signature. And I believe it's pretty weird that's missing since method signatures are done separately.
My question being, is it possible (am I overlooking something) to get IntelliJ to show separate entries for each signature for constructors WITH documentation, instead of just showing the class name and making you figure out afterwards if you're even in the right place or not.
Eclipse way of showing (preferred)
IntelliJ IDEA way of showing (not preferred)
This answer is base on IDEA version 2021.2.2
In the Settings -> Editor -> General -> Code Completion, check Show parameter name hints on completion under Parameter Info session.
Combine with Ctrl + Q, you can view the javadoc for each constructor.
Type the class name and the parenthesis. Inside parenthesis, type Ctrl+P. Eg: new BufferedWriter( <ctrl+P> )
In fact you can type, ctrl+P to get details of any function, not just constructor.
It is also possible to show overloaded constructors by enabling a hidden option. Invoke the Help | Find Action menu item and type Registry to go to the Registry. Here enable the java.completion.show.constructors option.
Copied From: https://stackoverflow.com/a/43639241/2920861

How to display java classes in eclipse calling a method from other class

I was wondering if there is a quick way of identifying or displaying which classes are trying to call a method.
Its easy to do this if there are only few classes present. But what if there are hundreds of classes trying to call a method in other classes. It would be extremly tedious if I do this manually. Is there a plugin or some built-in functions that would do this in eclipse?
The reason am asking is I wanted to map out different classes that are calling methods from other classes for easy debugging.
Right click your function, select references, and then choose what you want (generally project). That will show all the references to this function in the project. This also works for classes, variables, and probably other stuff too.
You can try an eclipse's Call Hierarchy feature. It shows you all the methods which directly call the method you are interested in. You can expand each caller and see what methods call it and so on.
You can do it buy right clicking on the method and selecting an "Open Call Hierarchy" menu item or pressing Ctrl+Alt+H Hotkey.

Is there any way to filter the workspace references (Ctrl+Shift+G) in eclipse so as NOT to also see the "potential matches"?

In eclipse, i want to see where in my workspace is a field actually being used. If I select it and press Ctrl+Shift+G i get all the references to it, but there's a drawback that if in the JavaDoc section someone mentioned that name, i get search results for those too.
So if i have a field called "user" and i want to see where it's being used, i get a ton of search results for every method that mentions "user" as a parameter in the javadoc...
Try using Ctrl+Shift+U that will show every line your variable/method occures in current class. Or Ctrl+Alt+H for every method using your variable.

How to see from where a public method is called in Eclipse using Java?

I am working on a Java project in Eclipse. Sometimes when I do refactoring I would like to see from what other classes a public method is called.
There is a primitive way to do this, that I am using now. I can comment out the method and see in what classes there is an error in Eclipse. Is there any better way to do this in Eclipse? E.g. by selecting the method signature and run a command by a key-shortcut?
Click on the method name, then press Ctrl+Alt+H to bring up the Call Hierarchy view.
You can also use Ctrl+Shift+G for "Find References in Workspace"
Search > References > Workspace
This will build a tree of results in the search view of every reference to the method. The hotkey is Shift+Ctrl+G
Another thing you could do is make it throw an exception (public void test() throws Exception{}) that way eclipse would put errors at every place that calls the method (as long as its not in a try/catch block or it throws an Exception too), this way will only work if you want to search classes in your project.
Cntrl + Shift + G
This shows where the call is made along with the hierarchy.
Eclipse 4.23 (Feb. 2022, 12 years later) does add to this view with:
Show implementations of callee
The call hierarchy view can now show implementing methods as potential callee methods when viewing callees.
This behavior can be controlled from following preference

Categories