Skip to main content



      Home
Home » Newcomers » Newcomers » Instantiation hierarchy(Looking for a plugin that shows a class *instantiation* hierarchy (who instantiates who))
Instantiation hierarchy [message #500477] Thu, 26 November 2009 05:05 Go to next message
Eclipse UserFriend
Is there a way in Eclipse - or a plugin - that provides the following feature:

for instance
class A {
    B b;
}

class B {
   C c;
}

class C { ... }


Right-click on "C" / the-wanted-feature would show
A -> B -> C,
showing the instantiation path up to C, based on the source code in the workspace.

Thanks as usual.

[Updated on: Thu, 26 November 2009 10:34] by Moderator

Re: Instantiation hierarchy [message #500499 is a reply to message #500477] Thu, 26 November 2009 07:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

click F4 when you are on your class Wink

Regards,
Aurelien pupier
Re: Instantiation hierarchy [message #500540 is a reply to message #500499] Thu, 26 November 2009 10:03 Go to previous messageGo to next message
Eclipse UserFriend
F4 displays the type hierarchy, related to interfaces, their implementations or class extensions.

I'm looking for a instantiation "hierarchy".
Of course it may not be a "hierarchy", depending on the project structure, and the programming rules followed by the developers.
But for our project is well structured, and for most classes, we have a kind of hierarchy like the one described in my first post.

The project goes deep in classes instantiations and to get the "path" up to a given class would be very helpful.

A plugin would be the ideal solution (or I'll have to do it in Perl).
Re: Instantiation hierarchy [message #500577 is a reply to message #500540] Thu, 26 November 2009 14:45 Go to previous messageGo to next message
Eclipse UserFriend
J.Barnen wrote:
> F4 displays the type hierarchy, related to interfaces, their
> implementations or class extensions.
>
> I'm looking for a instantiation "hierarchy".
> Of course it may not be a "hierarchy", depending on the project
> structure, and the programming rules followed by the developers.
> But for our project is well structured, and for most classes, we have a
> kind of hierarchy like the one described in my first post.
> The project goes deep in classes instantiations and to get the "path" up
> to a given class would be very helpful.
>
> A plugin would be the ideal solution (or I'll have to do it in Perl).
>
Right click on the constructor for class C and select Open Call Hierarchy.
Re: Instantiation hierarchy [message #500600 is a reply to message #500577] Thu, 26 November 2009 19:26 Go to previous messageGo to next message
Eclipse UserFriend
Nope. I'm not looking for the "call hierarchy".
Please read again my 2 posts.
Is my English that bad Smile
Re: Instantiation hierarchy [message #500719 is a reply to message #500477] Fri, 27 November 2009 12:01 Go to previous messageGo to next message
Eclipse UserFriend
This is a feature provided by Java profilers like JProfiler and JProbe, although perhaps not exactly what you're looking for. Given a particular class, you can view all the current instances of the class and see in a tree view the instantiation hierarchy upwards from that instance. I haven't looked at the profiling capabilities in JVisualVM with JDK 1.6, but it's possible you'll get similar features.
Re: Instantiation hierarchy [message #500757 is a reply to message #500600] Sat, 28 November 2009 03:31 Go to previous messageGo to next message
Eclipse UserFriend
"J.Barnen" <333@kochira.com> wrote in message
news:hen6ca$s3t$1@build.eclipse.org...
> Nope. I'm not looking for the "call hierarchy".
> Please read again my 2 posts.
> Is my English that bad :)

In your example there is no instantiation, only type reference. So it is
not surprising that people are having trouble answering.

If I assume you do mean instantiation, then the following example might be
what you meant:

class A {
B b = new B();
}

class B {
C c = new C();
}

class C { ... }

Now, I can sort of imagine writing something that, when clicking on the
declaration of type C, located all the places where C was instantiated; and
then located in turn all the places where the type doing that instantiation
was itself instantiated. This would amount to doing a call hierarchy on all
the constructors of C, collapsing the results for all the constructors
together, and then just listing the classes where the calls took place; then
doing the same, recursively.

Probably a pretty simple plug-in to write, if you wanted to pursue that.
AFAIK the functionality does not exist right now.
Re: Instantiation hierarchy [message #500772 is a reply to message #500757] Sat, 28 November 2009 08:36 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Walter and David.
I will have a look at the profilers.
For the time being, I wrote a Perl module that goes through all files and "draws" the instantiation tree for a given class - it is a simple tool implementing basically the same algorithm as yours (Walter), detects loops (class B { A a = new A() } / class A { B b = new B() }), which is ok for now.
But If anybody knows of a plugin doing this, let me know, thx.

[Updated on: Sat, 28 November 2009 08:38] by Moderator

Re: Instantiation hierarchy [message #501012 is a reply to message #500600] Mon, 30 November 2009 11:36 Go to previous messageGo to next message
Eclipse UserFriend
On 11/26/09 7:26 PM, J.Barnen wrote:
> Nope. I'm not looking for the "call hierarchy".
> Please read again my 2 posts.
> Is my English that bad :)

Try describing how a call hierarchy of constructors different than what
you're looking for.

Eric
Re: Instantiation hierarchy [message #501634 is a reply to message #501012] Thu, 03 December 2009 03:09 Go to previous message
Eclipse UserFriend
"Eric Rizzo" <eclipse-bugs@rizzoweb.com> wrote in message
news:hf0s9j$k8l$4@build.eclipse.org...
> On 11/26/09 7:26 PM, J.Barnen wrote:
>> Nope. I'm not looking for the "call hierarchy".
>> Please read again my 2 posts.
>> Is my English that bad :)
>
> Try describing how a call hierarchy of constructors different than what
> you're looking for.

Eric, consider the following case:

class A {
A(int x) { ... }
A(String s) { ... }
}

class B {
A _a1;
A _a2;
B(int y) {
_a1 = new A(y);
...
}
B(String t) {
_a1 = new A(t);
_a2 = new A(t.size());
...
}
void quux(B b) {
B b2 = new B(b._a1.toString() + b._a2.toString());
...
}
}

class C {
static void zubzub(String args[]) {
B b1 = new B(3);
B b2 = new B("Foo");
}
}

class D {
void foo() {
C.zubzub("hello world");
}
}

Now, I think what the OP wants is just something like:
C -> B -> A

That is, I think he just wants to know what types instantiate what other
types. The information is all there in the call hierarchy of A's
constructors, but it's ugly: he has to get the call hierarchies of each of
the separate constructors of A, and so forth, identify the calls that don't
involve construction (like D.foo; D does not create a C, so the graph is not
D->C->B->A) and manually coalesce the information.
Previous Topic:Out of memory problem
Next Topic:C++ Library
Goto Forum:
  


Current Time: Thu Sep 25 05:15:55 EDT 2025

Powered by FUDForum. Page generated in 0.13234 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top