1

I have inherited a project that uses calls to an existing jar. The former programmer have had the fortune of obtaining a/the source code of the jar. However the construction is rather complex. I use an abstract class, say Size. In the source code I find an implementation of that class, say SizeProxy. It has an object of class SizeImplementation and any calls on Size.getInfo() will be implemented as a call to this.theSize.getInfo().

In short I have managed to find the actual implementation of getInfo that actually does anything interesting. I would love to make it possible to go from "my" code o_size.getInfo() and go directly to the "implementation" in SizeImplementation.getInfo. Right now I can't make Eclipse do that, possibly because the class names don't match. Please help!

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
StrefanA
  • 11
  • 2
  • 1
    Would I be correct in saying you want to look at the source code for a compiled library? Is so what you want is a decompiler. It won't give you back the true original source code but will give you a close approximation (java is quite good for this) unless the original developer has taken steps to prevent this (obfuscation) – Richard Tingle May 15 '14 at 07:57
  • No, I have the source code. The setup is somewhat convoluted with interfaces and abstract classes AND a class Size that holds an object o_size of class SizeImplementation and the method in Size getInfo() is simply a call to this.o_size.getInfo() but I "know" where the interesting code that actually does any work is and I want to link my call to getInfo() to that implementation code. – StrefanA May 15 '14 at 08:11
  • O I see, I don't think that's possible because an interface can have more than 1 implementation and an abstact class can be extended by more than 1 child class; which you are using is generally not known at compile time except in very simple cases. Of course you can usually go indirectly. I use netbeans and that lets you go from an interface to implemeting classes . I imagine eclipse is similar – Richard Tingle May 15 '14 at 08:15
  • http://stackoverflow.com/questions/122160/is-there-an-easy-way-to-attach-source-in-eclipse – Vivart May 15 '14 at 08:24
  • Are you able to get to the source via many steps within eclipse? (navigate to interface --> navigate to abstract class --> navigate to implementation); in which case see my answer. Or do you have to look at external files in a text editor. In which case see Vivart's comment – Richard Tingle May 15 '14 at 08:26

1 Answers1

0

This is in general not possible because an interface can have several implementations, and an abstract class (or any class) can be extended by many classes. Take this example

public void doSomething(boolean option){
    List<String> someList;
    if (option){
         list=new ArrayList<>();
    }else{
         list=new LinkedList<>();
    }

    list.add("Where do I go"); 

}

Were you to attempt to go to the implementing source directly from list.add("Where do I go"); to the implementation of .add() where would you end up? ArrayList's or LinkedList's.

This is why you have to go via the interface or abstract class then choose your implemetation from there

Richard Tingle
  • 16,906
  • 5
  • 52
  • 77