Bug 431967 - [1.8][quick assist] Provide quick assist to migrate code to use the new Stream APIs
Summary: [1.8][quick assist] Provide quick assist to migrate code to use the new Strea...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 433028 461455 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-04-04 02:15 EDT by Martin Mathew CLA
Modified: 2015-03-20 19:40 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 Martin Mathew CLA 2014-04-04 02:15:02 EDT
There are a number of new Stream APIs like the #filter, #collect, #forEach, #count, #mapToInt, #mapToDouble etc. We need to analyze the existing code and propose appropriate quick assist.

Like for e.g:
private static void streamA(Collection<String> words) {
		int sum = 0;
		for (String word : words) {
			if (word.startsWith("A")) {
				sum++;
			}
		}
		System.out.println(sum);		
	}
Can be converted as:
private static void streamA(Collection<String> words) {
		int sum = (int) words.stream().filter(w -> w.startsWith("A")).count();
		System.out.println(sum);
		
	}

Since there are many use cases we can create individual bugs to track each case. Also it would be nice to have a clean up option available to migrate existing code to use the new Stream APIs.
Comment 1 Noopur Gupta CLA 2014-04-18 02:30:23 EDT
*** Bug 433028 has been marked as a duplicate of this bug. ***
Comment 2 Noopur Gupta CLA 2015-03-05 03:46:53 EST
*** Bug 461455 has been marked as a duplicate of this bug. ***
Comment 3 Raffi Khatchadourian CLA 2015-03-20 19:40:28 EDT
(In reply to Manju Mathew from comment #0)
> There are a number of new Stream APIs like the #filter, #collect, #forEach,
> #count, #mapToInt, #mapToDouble etc. We need to analyze the existing code
> and propose appropriate quick assist.
> 
> Like for e.g:
> private static void streamA(Collection<String> words) {
> 		int sum = 0;
> 		for (String word : words) {
> 			if (word.startsWith("A")) {
> 				sum++;
> 			}
> 		}
> 		System.out.println(sum);		
> 	}
> Can be converted as:
> private static void streamA(Collection<String> words) {
> 		int sum = (int) words.stream().filter(w -> w.startsWith("A")).count();
> 		System.out.println(sum);
> 		
> 	}

Interesting. When I did this conversion automatically in NetBeans 8.0.2, I got this:

int sum = words.stream().filter((word) -> (word.startsWith("A"))).map((_item) -> 1).reduce(sum, Integer::sum);