Community
Participate
Working Groups
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());
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.
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
Thanks Markus. Released patch with: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=80bb6a1527f4959d9bb1c22e4244fc1f672231fb and news with: http://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=9b304bee5e60016c3d53a2e2b5b0622991b02411