Community
Participate
Working Groups
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.
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
(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.
(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.
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).
Clean-up / Save action or Quickfix for this conversion would be great and seems available in Netbeans as well as in IntelliJ.