Bug 462725 - [1.8] Support more general to lambda expression conversions (e.g., for loops)
Summary: [1.8] Support more general to lambda expression conversions (e.g., for loops)
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL: http://github.com/mdarefin/Convert-Fo...
Whiteboard:
Keywords:
Depends on: 380188
Blocks:
  Show dependency tree
 
Reported: 2015-03-20 16:47 EDT by Raffi Khatchadourian CLA
Modified: 2019-12-10 02:45 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raffi Khatchadourian CLA 2015-03-20 16:47:36 EDT
This bug is to suggest adding additional, more general conversions "to lambda expression" conversions, e.g., for loops. Currently, Eclipse can convert (via quick fix) an annonymous inner class to a lambda expression, however, it cannot convert a for loop on a collection to an equivalent forEach() call using a lambda expression. 

Here's an example:

List<String> list = Arrays.asList({"Moe", "Larry", "Curly"});

for (String s : list)
    System.out.println(s);

//should be converted to:

list.forEach(s -> System.out.println(s));

//or better yet:

list.forEach(System.out::println);

//and it also should work with streams:

list.stream.forEach(System.out::println);



Note that NetBeans has some functionality for this, although not perfect. It is based on the following paper:

A. Gyori, L. Franklin, D. Dig, and J. Lahoda. Crossing the gap from imperative to functional pro- gramming through refactoring. In Proceedings of the 2013 9th Joint Meeting on Foundations of Software Engineering, pages 543–553. ACM, 2013. http://dl.acm.org/citation.cfm?id=2491461.
Comment 1 Stephan Herrmann CLA 2015-03-20 19:19:07 EDT
This is the bug for the GSoC proposal [1], right?

Have you seen bug 431967? 

I'm moving this bug to JDT/UI (which is where refactorings and quick assists are implemented) to facilitate discussion / coordination.


[1] https://wiki.eclipse.org/Google_Summer_of_Code_2015_Ideas#JDT_Core:_More_general_convert_to_lambda_expression_Java_8_refactoring.2Fquick_fixes
Comment 2 Raffi Khatchadourian CLA 2015-03-20 19:24:53 EDT
(In reply to Stephan Herrmann from comment #1)
> This is the bug for the GSoC proposal [1], right?
> 
> Have you seen bug 431967? 
> 
> I'm moving this bug to JDT/UI (which is where refactorings and quick assists
> are implemented) to facilitate discussion / coordination.
> 
> 
> [1]
> https://wiki.eclipse.org/Google_Summer_of_Code_2015_Ideas#JDT_Core:
> _More_general_convert_to_lambda_expression_Java_8_refactoring.2Fquick_fixes

Yes, I currently have a student interested in submitting it for his proposal.
Comment 3 Raffi Khatchadourian CLA 2015-03-20 19:27:43 EDT
(In reply to Stephan Herrmann from comment #1)
> This is the bug for the GSoC proposal [1], right?
> 
> Have you seen bug 431967? 

Ah, no I have not seen that bug! However, I would be hesitant to mark it as a duplicate as the example I give is actually independent of streams. It is certainly related, however.
Comment 4 Raffi Khatchadourian CLA 2015-11-11 12:00:13 EST
I just wanted to comment on the status of this bug in respect to the GSoC 2015 project progress. My student's code is in a GitHub repo at http://github.com/mdarefin/Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin. He developed it as a separate plugin with the intention of integrating it into Eclipse later. 

The project was not completed during the summer. We broke the tasks down into preconditions and transformation. I would say that the preconditions are almost complete but he did not begin the transformation phase. He does, however, have a full refactoring test suite, which he used for TDD. More information can be found in the issue tracker (completed: https://github.com/mdarefin/Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin/issues?q=is%3Aissue+is%3Aclosed; pending: https://github.com/mdarefin/Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin/issues).
Comment 5 Lars Vogel CLA 2019-12-10 02:45:01 EST
Clean-up / Save action or Quickfix for this conversion would be great and seems available in Netbeans as well as in IntelliJ.