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

Bug 429738

Summary: [1.8][search] Find Declarations (Ctrl + G) shows no result for type-less lambda parameter
Product: [Eclipse Project] JDT Reporter: Noopur Gupta <noopur_gupta>
Component: CoreAssignee: Manoj N Palat <manoj.palat>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: manoj.palat, srikanth_sankaran
Version: 4.4   
Target Milestone: BETA J8   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed Patch
none
Proposed Patch none

Description Noopur Gupta CLA 2014-03-06 03:20:10 EST
package one.test;

@FunctionalInterface
interface Foo {
	int foo(int x);
}

public class T {
	// Select 'x' in lambda body and press Ctrl+G.
	Foo f1= x -> x; //[1]
	Foo f2= (int x) -> x; //[2]
}
-----------------------------------------------------

- Select 'x' in lambda body.
- Go to the menu: Search > Declarations > Workspace. Or, press Ctrl+G.
- Works at [2] but shows no result at [1].
Comment 1 Srikanth Sankaran CLA 2014-03-06 03:37:05 EST
I doubt that this is a JDT/Core problem. Let me check.
Comment 2 Srikanth Sankaran CLA 2014-03-06 03:40:26 EST
See that control clicking on the type elided x's usage takes you to the
declaration. That shows that selection engine computes the java element
correctly.

Also the hover links look good. 

Noopur, please check what API if any is used subsequently after determining
the Java element.
Comment 3 Srikanth Sankaran CLA 2014-03-06 03:43:17 EST
I suspect a problem in ILocalVariable#getTypeSignature
Comment 4 Srikanth Sankaran CLA 2014-03-06 03:54:15 EST
(In reply to Srikanth Sankaran from comment #3)
> I suspect a problem in ILocalVariable#getTypeSignature

No, this works fine too,

Noopur, please triage and send it back to JDT/Core if necessary with
clear instructions on which API if something is misbehaving. Without
knowing what the client does to hit the dead end, it is difficult to
make progress or even conclude JDT/Core is at fault here.
Comment 5 Noopur Gupta CLA 2014-03-06 04:24:56 EST
Add a breakpoint at org.eclipse.jdt.internal.ui.search.JavaSearchQuery, line: 144 which invokes SearchEngine.search(SearchPattern pattern, SearchParticipant[] participants, IJavaSearchScope scope, SearchRequestor requestor, IProgressMonitor monitor) as:

engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, fPatternData.getScope(), collector, mainSearchPM);

After the call to search engine, the SearchRequestor (collector) does not contain any match for case [1]. 
The pattern passed to search has resolved type for lambda parameter in both [1] and [2].
Also, note that org.eclipse.jdt.internal.ui.search.NewSearchResultCollector.acceptSearchMatch(SearchMatch match) is not hit during debugging for case [1], whereas it is hit with a SearchMatch for case [2].
Hence, it looks like an issue in SearchEngine#search.
Comment 6 Srikanth Sankaran CLA 2014-03-06 04:32:47 EST
Thanks Noopur, Manoj, please work on this, Thanks.
Comment 7 Srikanth Sankaran CLA 2014-03-06 05:22:58 EST
I think I know the problem. For type elided parameter declarations index
entries should be created after resolve and not before resolve. Manoj,
see if this is the problem.
Comment 8 Manoj N Palat CLA 2014-03-06 08:00:13 EST
Created attachment 240592 [details]
Proposed Patch

Issue was that MatchLocatorParser() did not override consumeTypeElidedLambdaParameter() and hence the match did not happen. Fixed with the patch attached above.
Comment 9 Srikanth Sankaran CLA 2014-03-06 08:32:50 EST
This patch does not apply :(
Comment 10 Srikanth Sankaran CLA 2014-03-06 08:33:56 EST
Manoj, it looks like you posted the wrong patch - this is already released
Comment 11 Srikanth Sankaran CLA 2014-03-06 09:07:44 EST
I went and created a fix and test (Manoj already had discussed the outline
of the fix) Something has horribly gone wrong during the commit - I don't see
the main fix but see fragments - studying what went wrong ...
Comment 12 Manoj N Palat CLA 2014-03-06 09:08:15 EST
Created attachment 240596 [details]
Proposed Patch

correct patch attached. Thanks Srikanth.
Comment 14 Srikanth Sankaran CLA 2014-03-06 22:37:57 EST
Verified as working for Eclipse + Java 8 RC2 using Kepler SR1 +   
Eclipse Java Development Tools Patch for Java 8 Support (BETA)
1.0.0.v20140306-1935