Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 484367

Summary: call hierarchy does not finds calls via method references on interface implementations
Product: [Eclipse Project] JDT Reporter: Samrat Dhillon <samrat.dhillon>
Component: CoreAssignee: Manoj N Palat <manoj.palat>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: jarthana, knut.wannheden, samrat.dhillon, T3rm1
Version: 4.6   
Target Milestone: 4.6 M7   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/70746
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=d6cbb5f758ded5eeca102e76e753b701b04256d0
https://bugs.eclipse.org/bugs/show_bug.cgi?id=539602
Whiteboard:

Description Samrat Dhillon CLA 2015-12-14 23:56:38 EST
Here is an example to reproduce the problem

interface  Bar {
	
	public void print();

}

@FunctionalInterface
public interface Foo {
	
	void process(Bar bar);

}


public class BarImpl implements Bar{

	@Override
//call hierarchy on print does not finds invocation in the below TestMethod class  
	public void print() {
		
	}

}


public class TestMethod {
	

	public void test(){
		//Foo foo = (bar)->bar.print();
		Foo foo = Bar::print;
	}
	
	

}

Invocation of call hierarchy fails on BarImpl#print however it works on Bar#print. If the method reference expression is replaced with the lambda expression, then it works. 

Marked this as major as I use this functionality everyday on interface implementations and it is very annoying that such a basic thing does not works.
Comment 1 Jay Arthanareeswaran CLA 2015-12-15 01:49:38 EST
Reproduced on master.

Manoj, please take a look. Also note that searching for references of Bar#print() produces inconsistent results. At times, the reference expression is not reported if the lambda is present.
Comment 2 Manoj N Palat CLA 2015-12-16 01:45:51 EST
(In reply to Jay Arthanareeswaran from comment #1)
>note that searching for references of
> Bar#print() produces inconsistent results. At times, the reference
> expression is not reported if the lambda is present.

Jay: yes, this searching for references with lamda does not highlight method reference expression - Looks more likely as a ui bug as jdt core finds the method reference and calls the accept method. Have submitted bug 484454 against ui to track this issue
Comment 3 Samrat Dhillon CLA 2015-12-23 22:22:19 EST
Just wanted to know if this bug is on the radar and will be fixed in the upcoming release?
Comment 4 Eclipse Genie CLA 2016-04-15 07:07:24 EDT
New Gerrit change created: https://git.eclipse.org/r/70746
Comment 6 Sasikanth Bharadwaj CLA 2016-04-27 03:51:37 EDT
Verified for Neon M7 using I20160425-1300 build
Comment 7 T3rm1 CLA 2018-03-08 06:49:29 EST
Still doesn't work in Eclipse Oxygen if there is more than one implementation.
Comment 8 Manoj N Palat CLA 2018-03-13 00:20:27 EDT
(In reply to T3rm1   from comment #7)
> Still doesn't work in Eclipse Oxygen if there is more than one
> implementation.

With an additional implementation, I still see the call hierarchy.
public class BarImpl2 implements Bar{

	@Override
	public void print() {	
	}

}
Or with an extended class as well,
public class BarImpl2 extends BarImpl{

	@Override
	public void print() {
		
	}

}
the call hierarchy is shown.

Can you please give an example?
Comment 9 Knut Wannheden CLA 2018-09-28 03:01:33 EDT
In the following example I would have expected the call hierarchy for the method "bar(Test)" to show me "other()", but instead I get "foo()" which isn't really helpful, as that is only where the method reference is.

Hope this test case helps.

public class Test {

	public interface Listener {
		void process(Test source);
	}

	public void addListener(Listener l) {
		// ...
	}
	
	public void foo() {
		addListener(this::bar);
	}
	
	private void bar(Test test) {
		// ...
	}

	public void other() {
		Listener l = null;
		l.process(this);
	}
}
Comment 10 Manoj N Palat CLA 2018-09-28 03:21:21 EDT
(In reply to Knut Wannheden from comment #9)
> In the following example I would have expected the call hierarchy for the
> method "bar(Test)" to show me "other()", but instead I get "foo()" which
> isn't really helpful, as that is only where the method reference is.

This will be tracked via bug 539602.