Bug 417801 - [1.8][quick assist] Infer lambda parameters
Summary: [1.8][quick assist] Infer lambda parameters
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.5 M3   Edit
Assignee: Noopur Gupta CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on: 432614 446442
Blocks:
  Show dependency tree
 
Reported: 2013-09-23 06:36 EDT by Noopur Gupta CLA
Modified: 2014-10-15 05:50 EDT (History)
3 users (show)

See Also:
markus.kell.r: review+


Attachments
Patch (16.54 KB, patch)
2014-08-12 07:42 EDT, Noopur Gupta CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Noopur Gupta CLA 2013-09-23 06:36:09 EDT
A quick assist can be added to infer lambda parameters in a lambda expression which has type inferred (type-less) parameters. 

It would be useful to know the types of the lambda parameters explicitly, in cases where the functional interface is not in the same class or project.

Example: Invoking infer lambda parameters quick assist on the lambda expression: 

Button button = new Button();
button.addActionListener(e -> foo());

should result in:

Button button = new Button();
button.addActionListener((ActionEvent e) -> foo());
Comment 1 Noopur Gupta CLA 2014-08-12 07:42:49 EDT
Created attachment 245909 [details]
Patch

Added quick assist: "Add inferred lambda parameter types" and tests.

The inferred type added for a lambda parameter should not have annotations from the SAM - added disabled test AssistQuickFixTest18.testAddInferredLambdaParamTypes4() which should be enabled after bug 432614 is fixed.

Also, the type will have all the dimensions (no separate extra dimensions) from the parameter in SAM (AssistQuickFixTest18.testAddInferredLambdaParamTypes4()) and will represent varargs (...) as [] in the lambda parameters (AssistQuickFixTest18.testAddInferredLambdaParamTypes1()).

Markus, please have a look.
Comment 2 Markus Keller CLA 2014-10-14 06:29:32 EDT
Looks good. I found it inconvenient that the proposal is not available on the parameter name itself. In general, it's good to restrict proposals to a small set of activation positions, but in this case, you can also argue that the quick assist actually targets each parameter, so enabling it on the names is justified.

Please add that (using getLocationInParent() == xxx; you know how it works;-), fix testAddInferredLambdaParamTypes4 by accepting the result
    (@A Integer i, @A String @C [] @B [] s) -> {}
, and then release.

It think this feature is done, so to finish it off, you could also add the N&N entry: ssh://git.eclipse.org/gitroot/www.eclipse.org/eclipse/news.git