17

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() ?

1
  • could you please release this bounty. Commented Jul 3, 2018 at 9:29

3 Answers 3

21
+100

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:

enter image description here

Sign up to request clarification or add additional context in comments.

14 Comments

It still find occurrences of Object's toString() in Eclipse Neon
it shouldn't, I am using eclipse mars currently and it works/worked (with older versions) perfectly.
it's a correct answer: in eclipse right click and then choose Open Call Hierarchy... upvoted :)
@HalayemAnis But if use it on a specific method as new MyClass("aa","").toString(); it will return all Object.toString() method usages
@ user7294900 I just tried to replicate same as you suggested but it worked fine for me. I am using jdk8, eclipse mars2, java perspective. I selected 'toString()' on line new MyClass().toString() and it gave me single result. Make sure you haven't overridden any default key bindings.
|
4

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

2 Comments

does not work for me. I have e xactly one call to a toString() in my Test.class, if I do a search on toString() and then 'references to overriden' I still get dozens of hits on other toString() methods from other unrelated classes.
@OliverWatkins in Java Search you Limit To: References?
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.