Bug 369379 - [call hierarchy] Call Hierarchy reports callers of overridden method -- add a filter
Summary: [call hierarchy] Call Hierarchy reports callers of overridden method -- add a...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-23 06:48 EST by Dani Megert CLA
Modified: 2016-12-12 12:27 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2012-01-23 06:48:21 EST
I20120122-2000.

The call hierarchy reports overridden caller.

Test Case:

1. paste this:

public class Super {
	void callIt() {
		called();
	}
	void called() {
		System.out.println("called");
	}

	public static void main(String[] args) {
		new Sub().callIt();
	}
}

class Sub extends Super {
	void callIt() {
		System.out.println("BUG");	
	}

	void called() {
		System.out.println("called");	
	}
}


2. Open the Call Hierarchy on Sub.called()
==> it lists Super.callIt() but that's wrong since Sub.callIt() does not call super.callIt().
Comment 1 Markus Keller CLA 2012-01-23 09:48:38 EST
> 2. Open the Call Hierarchy on Sub.called()
> ==> it lists Super.callIt() but that's wrong since Sub.callIt() does not call
> super.callIt().

Sub.callIt() indeed doesn't call Sub.called(), but Super.callIt() still does. To know that this call path is never executed in practice, we would need a full system analysis.

The result is OK in general, see example below where this call actually happens in practice via Sub.callItDetour().

The best we can do is to offer a filter for calls to overridden methods, like bug 73401 did for reference search.


package p;
public class Super {
    void callIt() {
        called();
    }
    void called() {
        System.out.println("called Super");
    }

    public static void main(String[] args) {
        new Sub().callIt();
        new Sub().callItDetour();
    }
}

class Sub extends Super {
    void callItDetour() {
        super.callIt();
    }
    
    void callIt() {
        System.out.println("BUG");    
    }

    void called() {
        System.out.println("called Sub");    
    }
}
Comment 2 Stephan Herrmann CLA 2016-12-12 12:27:05 EST
(In reply to Markus Keller from comment #1)
> The best we can do is to offer a filter for calls to overridden methods,
> like bug 73401 did for reference search.

In case of a single search, a user has good chances to "just know" that receivers will have a particular type and not another. In the Call Hierarchy this is more problematic because each call in a chain can be polymorphic and it's unlikely that a user has precise type information for all these calls.

Ideally, I would imagine a context menu action "Restrict callee type" or "Filter polymorhpic calls", which could be invoked on each node in the hierarchy to filter just the incoming edges to this particular node. Not sure, though, if this is overkill. But disabling polymorphic search for the entire Call Hierarchy feels wrong to me.