Bug 516986 - [templates] Support iteration of arrays using JDK 8 Streams
Summary: [templates] Support iteration of arrays using JDK 8 Streams
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-19 10:31 EDT by George Gastaldi CLA
Modified: 2017-05-23 11:26 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description George Gastaldi CLA 2017-05-19 10:31:19 EDT
Right now eclipse provides some code templates to iterate a variable using for and foreach (for (int i: array)). 

It would be nice to support code templates iterating using the JDK 8 streams API.
Comment 1 George Gastaldi CLA 2017-05-19 10:45:47 EDT
Example using Arrays: 

      int[] array = { 1, 2, 3, 4, 5, 4, 3, 2, 1 };
      Arrays.stream(array).forEach(System.out::println);
Comment 2 Stephan Herrmann CLA 2017-05-19 11:10:44 EDT
In my understanding, most support for stream processing is already covered by code completion, since most stream processing follows a fluent pattern.

So, what should the template produce?

Input: array
Output: Arrays.stream(array)
?

I don't think that forEach is more relevant than any other method on Stream, is it?
Comment 3 George Gastaldi CLA 2017-05-19 11:13:42 EDT
I believe it should produce Arrays.stream(array).forEach(); and place the cursor inside the forEach parameter, just like the for code completion templates do.
Comment 4 Stephan Herrmann CLA 2017-05-19 11:27:28 EDT
(In reply to George Gastaldi from comment #3)
> I believe it should produce Arrays.stream(array).forEach(); and place the
> cursor inside the forEach parameter, just like the for code completion
> templates do.

Why should a template favor forEach over any other method of Stream?
Comment 5 George Gastaldi CLA 2017-05-19 11:29:24 EDT
I see that as an evolution to the for-each statement. Obviously that is not so clear unless there is a code template to help