How can I using eclipse Java search find all calls of methods that are declared in specific class?
I tried p1.p2.p3.MyClass.* but this search string finds equals, getClass calls which is not necessary. I only need to find methods that are declared explicitly in p1.p2.p3.MyClass.
Select the method name and hit CTRL-SHIFT-G, which searches for all references to this method.
If you want to find all of the usages of all of the methods, you can't do that, but you can find all usages of the class, by selecting the class name and doing CTRL-SHIFT-G.
If you select the method pressing CRTL ALT H you can see the call hierarchy and configure its view.
In the outline view you can select multiple methods, then right button and open in call hierarchy. Again CRTL ALT H .
You can find references to a class by selecting the class name and CRTL SHIFT G (references).
Go to the method that you want to find. Right click and select the option to see all references.
Eclipse is amazing for this. It should show all references in a panel of results
I have found how it can be done using Java search. I have filtered out overrode methods from search result and got only methods defined in type.
Thank you all for your time spent on this question nevertheless :)
Related
When I want to find usages of a normal method in java it is fairly easy and straightforward CTRL-SHIFT-G .
However if this method has a super definition, or implementation, then eclipse will show me usages of all types in the hierarchy types.
For example, if I have a toString() method on my class, I would only be interested in finding exactly where this toString() of this class was being called, instead eclipse gives me every single ancestor toString in the project (ie Object.toString()).
How do I find only specific usages to my class? And not usages of parent classes like Object.toString() ?
Alt + ctrl + h should give you exactly, what you are looking for.
Updated with screenshot from my workspace as some people are facing issue in following it:
Thanks to #manouti answer,
To show when using the overridden method only follow the steps:
Search by Java the method as com.package.MyObject.toString()
And after in search result screen click on the right arrow to the left and check References to Overridden
After having the same problem as many others in the comments (Eclipse shows references to Object.toString()) I have found a way that seems to work correctly:
Go to outline from your custom class, right click on your toString() implementation and References -> Project. This displays only references to said implementation.
I'm trying to find all fields with the Disposable interface, so I can know if whether I forgot to call the dispose() method on any of them in the cleanup phase.
Is there a way to do that in intelliJ?
I've only managed to find those, whose dispose() methods I've already remembered to call. I've done that by ticking the "Usages of methods" checkbox in the find usages options dialog (when doing a search on the Disposable interface)... but this wasn't what I need.
You can try Edit | Find | Search Structurally. You can copy a predefined template named "fields of class" that can be modified to your needs by removing Init part and specifying a hierarchy constraint for $FieldType$ variable.
You can read more about that functionality at https://www.jetbrains.com/idea/help/structural-search-and-replace.html
**Alt+F7**
Instead of the dispose method, find usages of the interface
Usages - if this check box is selected, the search is performed for all references of the class by its name.
This way you will get all the places where Disposable interface is being referenced in your workspace
You can find usage of the your interface.
The keycode for that in my system is alt+f7, but it can be different on your system.
So you can right click and find usage of your interface.
and then filter it down to
Usage in extends/implements clause
Can't find anything on this and sort of would like a report on it and not going through all of this code. Here's the question.
I am analyzing a method that calls about 45 other methods that calls other methods. I need to find out all calls that ends up with a specific package from this specific method. How could I do this?
An option I have is to to use "call hierarchy" and drill down one method at a time (but there is no filter option as I can see to just see methods from one given package).
Actually you can do filtering when using the call hierarchy (CTRL - ALT - H). On the newly opened pane, there is a drop-down list with the name "Scope:". Here you can add a new scope where you can include/exclude filter not only on packages but also on classes or to search given a certain regex.
I checked this on the latest Intellij version (14.1.5).
We have had some bugs caused by a misunderstanding of HashSet functionality. Apparently someone assumed that calling .iterator() would return the elements in the order they were inserted. What should have been used is LinkedHashSet.
Now, I was wondering if there is some way to search for this bug. As in: is there a way to find instances of iterator being called on variables of types implementing the Set interface?
mark the iterator()-call and press Ctrl+Alt+h, the call-hierarchy will be shown;
another way to do so is to right-click on the iterator()-call and choose "open call hierarchy".
BUT:
the method is defined in the Set<E>-interface. so, all locations in workspace, where the method is called, are shown.
I need to find the references to external method say Foo.getInstance() in specific type hierarchy, basically i want to restrict the search results to specific class and all subclasses, i am not interested in all references. Is it possible to do with eclipse or any custom plugin? Thanks
You can do this creating a working set with only the files holding your hierarchy.
Then CTRL+H and Java Search with scope "Working Set".
If the classes are all within a package you can select that in Project Explorer then perform Java Search with scope "Selected".
Working sets are awesome
I have identified a workaround. Requires viewing eclipse search results(in "show as list" mode).
For example ClassA has several subclasses (ClassB,C..Z) which inherits methodA defined on class A and calls them.
Perform method reference in eclipse and change the view to "show as list" using triangle/View menu appearing on top-right corner. This will list method signatures containing super-class/sub-class references so you can easily pick or drop from the search result.
If there are too many results to filter through you can Copy this onto file editor and use search keyword of subclass name (ClassB) and each line containing classB is a potential result which calls methodA on classB object.
Note: If method signature uses classA object reference and within body it type-casts to classB then you need to pick that entry and not drop it. I'd also recommend working set approach mentioned above. This is alternate approach to the question posted.