10

Environment

I have a simple test-foo.jar library with just two files:

  • interface Foo with a single method void doStuff()
  • class Bar with a single method void executeFoo(Foo foo), which just calls foo.doStuff()

Then I have Eclipse Java project with a single class FooImpl which implements Foo. This project has test-foo.jar as a build path entry. I don't have source codes for this JAR attached.

Eclipse project tree

The Problem

Now lets say I am a bit curious about who actually calls doStuff() method. So I click on the FooImpl#doStuff signature and press Ctrl+Shift+G (find references). I expect to see Bar#executeFoo in the search results, but the results are actually empty.

Empty search results

The Question

I am bit confused as I thought this works in Eclipse (been using Eclipse for more than a few years now). But it seems it only works for libraries with sources attached (which I didn't notice before).

Is there a way how to find references (or usage) of a type (or method) in project libraries without sources attached? Why does not Eclipse index and show references from .class files?


Additional info:

  • Finding references works as soon as I attach source codes to the JAR.
  • I am interested in knowing why Eclipse JDT developers decided to not index or search .class without sources.
  • Note, that knowing who is calling my method is very useful information even if I don't have source codes.
  • Seems to me that Eclipse is indexing method references in .class files.
  • And by the way NetBeans "don't work" as well ;).
oberlies
  • 11,503
  • 4
  • 63
  • 110
Pavel Horal
  • 17,782
  • 3
  • 65
  • 89
  • Possible duplicate? http://stackoverflow.com/questions/5268998/find-methods-calls-in-eclipse-project – Mike Koch Jan 20 '14 at 14:28
  • @MikeKoch nope... OP in that question does not know about *Find References* functionality. Call hierarchy is just a different view on method references. I know (at least I think I know :)) how to search for references. It just don't work if the library does not have sources attached. – Pavel Horal Jan 20 '14 at 14:39
  • If bar does not reference fooImpl.doStuff(), but, instead, references foo.doStuff() then it will not match the search for references to the fooImpl.doStuff() method. – DwB Jan 20 '14 at 14:56
  • Just for curiosity, have you tried installing a Java Decompiler on eclipse to see if it helps? – everton Jan 20 '14 at 19:39
  • @EvertonAgner It helps, but at least one source class needs to be opened before the source files are produced. However I have pretty bad experience with both JAD and JD plugins as they usually cause SEGFAULT (or similar fatal issue) which kills Eclipse. – Pavel Horal Jan 20 '14 at 22:26
  • **UPDATE** Stephan Herrmann (one of JDT committers) answered my question on Eclipse forums. I am waiting for one clarification, then I will post some summary here. http://www.eclipse.org/forums/index.php/mv/msg/639229/1234221/#msg_1234221 – Pavel Horal Jan 21 '14 at 16:31

1 Answers1

0

You need the source attached to your library. There's no point for Eclipse to take you to the .class file since all you would see is a bunch of compiled jamble-wamble (that's just a word I came up with). Eclipse will only navigate to Java source files.

AxiomaticNexus
  • 6,190
  • 3
  • 41
  • 61
  • Do you know why is this the case? Is there any mailing list discussion connected to this or any other official reference? For me, it would still be very useful to know the component, which is calling my interface. – Pavel Horal Jan 20 '14 at 14:56
  • No, I don't have an official reference, it's just what it is. Why do you need to know the component? What is it you plan to do once you find it? – AxiomaticNexus Jan 20 '14 at 15:01
  • 1
    I need to reverse engineer few components. Just knowing the component which is creating a specific object instance would be of a great value. Without this I need to manually decompile all JARs and attach the source files and then search for references. – Pavel Horal Jan 20 '14 at 15:04
  • And that's why the functionality you're asking does not exist. Eclipse is not there to help you reverse engineer or decompile JAR's. What you're trying to do in most cases will even be unethical. – AxiomaticNexus Jan 20 '14 at 15:09
  • 2
    I get that you probably never faced any integration issues when using Java together with some closed source third-party library ;). Or when you need to implement additional functionality where the official documentation is almost non-existent and Google returns exactly 0 results. There is nothing unethical trying to understand how something works. – Pavel Horal Jan 20 '14 at 15:13
  • Well, if the library you're using is not good enough, it's time to move on to a better one I suppose. – AxiomaticNexus Jan 20 '14 at 15:40