Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 274087 - [call hierarchy] Remember for which nodes to expand constructors
Summary: [call hierarchy] Remember for which nodes to expand constructors
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.5 RC1   Edit
Assignee: Raksha Vasisht CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 275128 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-04-28 11:27 EDT by Dani Megert CLA
Modified: 2009-05-15 12:03 EDT (History)
3 users (show)

See Also:
daniel_megert: review+


Attachments
Patch with the fix. (5.64 KB, patch)
2009-05-05 07:11 EDT, Raksha Vasisht CLA
markus.kell.r: review-
Details | Diff
Improved patch (6.12 KB, patch)
2009-05-12 08:03 EDT, Raksha Vasisht CLA
no flags Details | Diff
Added check in EWC. (6.20 KB, patch)
2009-05-13 04:20 EDT, Raksha Vasisht CLA
daniel_megert: iplog+
Details | Diff
Fixes NPE (4.54 KB, patch)
2009-05-14 11:53 EDT, Markus Keller CLA
no flags Details | Diff
Configure automatic Expand with Constructors (18.86 KB, patch)
2009-05-14 16:00 EDT, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2009-04-28 11:27:17 EDT
I20090428-0100.

The Call Hierarchy should remember for which nodes to expand constructors.

Another option would be to allow to configure this.
Comment 1 Markus Keller CLA 2009-04-28 13:51:43 EDT
The difficult question is what element exactly to remember. 'Expand With Constructors' is mainly useful on methods that serve as function pointers, e.g. run() in an anonymous subtype of Runnable.

I think it would be annoying if I had to toggle this for every single implementation of the run() method. After a while, it would also become hard to predict whether a given run() method will be expanded with constructors or not.

It would be much more convenient if there was a list of methods whose *implementations* (or extensions) should be expanded with constructors. The prime defaults for this list are Runnable#run() and Callable#call().

However, this is not easy to implement efficiently, because we can neither create a supertype hierarchy for every method that shows up in a call hierarchy, nor can we create (and maintain) a subtype hierarchy of all types in the list.

I guess the hierarchy would have to be created on demand (using the supertype hierarchy cache from the override indicators), whenever the user expands a node or opens the context menu.
Comment 2 Dani Megert CLA 2009-04-29 02:26:35 EDT
Maybe we could trick a but and use the method name plus some code parsing i.e. check whether it's inside an anonymous class.
Comment 3 Markus Keller CLA 2009-04-29 04:23:38 EDT
> Maybe we could trick a but and use the method name

I was also thinking about that, and I'm starting to like this as a quick fix for 3.5.

> plus some code parsing i.e. check whether it's inside an anonymous class.

I fear that would already introduce too much "black magic", since it would fail as soon as the anonymous class is converted into its own class (which is reasonable for delayed tasks or listener implementations).

But we could generalize it and just check the simple names of the direct super types. That info is relatively cheaply available from the IMethod:
- if the declaring type is anonymous, just check the type name
- otherwise, check the declaring type's #getSuperInterfaceNames() and #getSuperclassName()

This approach has the advantage that the "special" methods can already now be stored fully qualified, and thus the stored data could still be used if we decide later to implement the full-fledged solution outlined in comment 2. It can lead to false positives, but that's acceptable IMO.
Comment 4 Dani Megert CLA 2009-04-29 12:47:11 EDT
re comment 3: good idea.
Comment 5 Raksha Vasisht CLA 2009-05-05 07:11:38 EDT
Created attachment 134405 [details]
Patch with the fix.
Comment 6 Dani Megert CLA 2009-05-06 07:56:39 EDT
*** Bug 275128 has been marked as a duplicate of this bug. ***
Comment 7 Markus Keller CLA 2009-05-10 19:19:26 EDT
Comment on attachment 134405 [details]
Patch with the fix.

* CallHierarchyContentProvider#isInTheDefaultExpandWithConstructorList(IType):

- Always watch out for NPEs.
'superClass= type.getSuperclassName()' -> superClass can be null

- Extract local variable for repeated expressions.
defaultTypes[i]

- IType#getFullyQualifiedName() is most of the time not what we need. Should be getFullyQualifiedName('.').

- 'String[] superInterface' should be 'superInterfaces' (plural)


* CallerMethodWrapper#fIsDefaultExpandWithConstructors:

I don't see how this property should work. I would expect that the state of the "Expand with Constructors" menu item always correctly reflects the state of the selected node, but currently, it is also unchecked for methods that are automatically expanded with constructors.

I think the easiest solution for this would be to change CallerMethodWrapper#fExpandWithConstructors to be type Boolean and then interpret 'null' from getExpandWithConstructors() as "has not been explicitly set, so take the default". And if it is null, then ExpandWithConstructorsAction#canActionBeAdded() can set the default state.
Comment 8 Raksha Vasisht CLA 2009-05-12 08:03:05 EDT
Created attachment 135332 [details]
Improved patch
Comment 9 Markus Keller CLA 2009-05-12 13:14:35 EDT
> interpret 'null' from getExpandWithConstructors() as "has not been explicitly
> set, so take the default". And if it is null, then
> ExpandWithConstructorsAction#canActionBeAdded() can set the default state.

The last patch is still missing this, so e.g. the context menu on a run() method still does not have "Expand with Constructors" checked. You really need to do the check before adding the action and set the flag there as well (and you need to keep it in the content provider as well, in case the user expands the node before opening the menu).
Comment 10 Raksha Vasisht CLA 2009-05-13 04:20:21 EDT
Created attachment 135525 [details]
Added check in EWC.
Comment 11 Markus Keller CLA 2009-05-13 05:53:23 EDT
Dani, can you please review patch 3?

Cosmetics I'd apply to CallHierarchyContentProvider#setDefaultExpandWithConstructors(..):

- move 'IType type= ..' to inside the if block

- change Javadoc to
 * Sets the default "expand with constructors" mode for the method wrapper.
 * Does nothing if the mode has already been set.

- rename method to "ensureExpandWithConstructorsSet"
Comment 12 Dani Megert CLA 2009-05-13 09:29:22 EDT
Works as expected. Besides the changes suggested by Markus I suggest to encapsulate the knowledge whether the expand mode has been set or not inside the wrapper so that we don't need to change the data type of fExpandWithConstructors and set/getExpandWithConstructors().

Committed to HEAD with above changes plus commenting the empty catch block.
Comment 13 Markus Keller CLA 2009-05-14 11:53:28 EDT
Created attachment 135802 [details]
Fixes NPE

The last patch caused NPEs when a member was not a method (but e.g. a type that doesn't have a constructor).

The fix ensures that CallHierarchyContentProvider#ensureDefaultExpandWithConstructors(CallerMethodWrapper) only sets the expandWithConstructors flag if the given member can be expanded with constructors at all.

Released to HEAD.
Comment 14 Markus Keller CLA 2009-05-14 16:00:52 EDT
Created attachment 135852 [details]
Configure automatic Expand with Constructors

Adds a view menu action that opens a dialog to configure for which types 'Expand with Constructors' should be the default.
Comment 15 Markus Keller CLA 2009-05-14 16:03:47 EDT
Released for I20090514-2000. Dani, could you please sanity check HEAD?
Comment 16 Dani Megert CLA 2009-05-15 03:34:57 EDT
Fix is good. Found one minor issue (see bug 276429).
Comment 17 Raksha Vasisht CLA 2009-05-15 06:31:09 EDT
Filed bug <a href="show_bug.cgi?id=276466" title="[call hierarchy] Improve UI for View Menu Preferences">bug 276466</a>) for UI (Call Hierarchy View Menu -> Preferences)  improvement.
Comment 18 Markus Keller CLA 2009-05-15 12:03:53 EDT
Verified in I20090514-2000.