1

For context, say I have these classes:

public class Foo {
     public void doStuff() {}
}

public class Bar extends Foo {
     @Override
     public void doStuff() {}
}

public class Zig extends Foo {
     @Override
     public void doStuff() {}
}

I'm trying to find only calls to Bar#doStuff().

I've tried:

  • Java Search for Bar.doStuff
  • "Open Call Hierarchy" on Bar#doStuff()

but they appear to return calls to both Bar.doStuff() and Foo.doStuff() and Zig.doStuff(). Is there something else I need to do, or am I misunderstanding the results I'm getting?

Brad Mace
  • 27,194
  • 17
  • 102
  • 148

2 Answers2

2

To find the calls which are definitely from Bar, you can mark Bar#doStuff as @Deprecated, and then create a new "Problems" view with a filter to find just these messages.

to create the new Problems view:

  1. open default Problems view
  2. click triangle and choose New Problems View
  3. in new view, click triangle and choose Configure Contents
  4. On the left, check only Errors/Warnings in Project
  5. set the Text contains filter (under Description heading) as appropriate

Note: this will not find cases where Bars are stored as Foos, e.g.:

Foo f = new Bar();
f.doStuff();
Brad Mace
  • 27,194
  • 17
  • 102
  • 148
1

Well, due to polymorphism, there's not a good way for the IDE to know that a given Foo isn't potentially a Bar -- so it will show you all calls to doStuff. I suppose it could do more analysis to determine that the concrete type of a Foo really is a Foo -- for example, in the case:

final Foo foo = new Foo();

it is definitely not a Bar -- but that's a lot of work for little benefit.

You will notice the same holds true for interfaces and their implementations, at least in Eclipse.

Thorn G
  • 12,620
  • 2
  • 44
  • 56
  • ok, that much makes sense. I've updated question though, as I'm also getting matches for `Zig`s, which are definitely not `Bar`s. – Brad Mace Nov 21 '14 at 21:55