Eclipse - Find Java references of a library without attached sources
Asked Answered
G

1

11

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 ;).
Gonidium answered 20/1, 2014 at 13:51 Comment(6)
Possible duplicate? #5269498Goshorn
@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.Gonidium
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.Chauffeur
Just for curiosity, have you tried installing a Java Decompiler on eclipse to see if it helps?Bifurcate
@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.Gonidium
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. eclipse.org/forums/index.php/mv/msg/639229/1234221/#msg_1234221Gonidium
K
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.

Kenning answered 20/1, 2014 at 14:54 Comment(6)
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.Gonidium
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?Kenning
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.Gonidium
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.Kenning
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.Gonidium
Well, if the library you're using is not good enough, it's time to move on to a better one I suppose.Kenning

© 2022 - 2024 — McMap. All rights reserved.