6
6
import java .io .IOException ;
7
7
import java .util .ArrayList ;
8
8
import java .util .Arrays ;
9
+ import java .util .Collection ;
9
10
import java .util .Collections ;
10
11
import java .util .HashSet ;
11
12
import java .util .List ;
48
49
import org .eclipse .ltk .core .refactoring .participants .ProcessorBasedRefactoring ;
49
50
import org .osgi .framework .FrameworkUtil ;
50
51
52
+ import com .google .common .collect .Sets ;
53
+ import com .google .common .collect .Sets .SetView ;
54
+
55
+ import edu .cuny .hunter .streamrefactoring .core .analysis .PreconditionFailure ;
51
56
import edu .cuny .hunter .streamrefactoring .core .analysis .PreconditionSuccess ;
52
57
import edu .cuny .hunter .streamrefactoring .core .analysis .Refactoring ;
53
58
import edu .cuny .hunter .streamrefactoring .core .analysis .Stream ;
@@ -236,18 +241,34 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
236
241
// #streams.
237
242
resultsPrinter .print (processor .getStreamSet ().size ());
238
243
239
- // #optimization available streams. These are the "filtered" streams. No
240
- // filtering currently.
241
- resultsPrinter . print ( processor . getStreamSet (). size () );
244
+ // #optimization available streams. These are the "filtered" streams.
245
+ Set < Stream > candidates = processor . getStreamSet (). parallelStream (). filter ( s -> {
246
+ String pluginId = FrameworkUtil . getBundle ( Stream . class ). getSymbolicName ( );
242
247
243
- // candidate streams and their attributes.
244
- for (Stream stream : processor .getStreamSet ()) {
248
+ // error related to reachability.
249
+ RefactoringStatusEntry reachabilityError = s .getStatus ().getEntryMatchingCode (pluginId ,
250
+ PreconditionFailure .STREAM_CODE_NOT_REACHABLE .getCode ());
251
+
252
+ // error related to missing entry points.
253
+ RefactoringStatusEntry entryPointError = s .getStatus ().getEntryMatchingCode (pluginId ,
254
+ PreconditionFailure .NO_ENTRY_POINT .getCode ());
255
+
256
+ // filter streams without such errors.
257
+ return reachabilityError == null && entryPointError == null ;
258
+ }).collect (Collectors .toSet ());
259
+
260
+ resultsPrinter .print (candidates .size ()); // number.
261
+
262
+ // candidate streams.
263
+ for (Stream stream : candidates )
245
264
candidateStreamPrinter .printRecord (javaProject .getElementName (), stream .getCreation (),
246
265
stream .getCreation ().getStartPosition (), stream .getCreation ().getLength (),
247
266
Util .getMethodIdentifier (stream .getEnclosingEclipseMethod ()),
248
267
stream .getEnclosingType () == null ? null
249
268
: stream .getEnclosingType ().getFullyQualifiedName ());
250
269
270
+ // stream attributes.
271
+ for (Stream stream : processor .getStreamSet ()) {
251
272
streamAttributesPrinter .printRecord (javaProject .getElementName (), stream .getCreation (),
252
273
stream .getCreation ().getStartPosition (), stream .getCreation ().getLength (),
253
274
Util .getMethodIdentifier (stream .getEnclosingEclipseMethod ()),
@@ -259,10 +280,13 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
259
280
: stream .getStatus ().getEntryWithHighestSeverity ().getSeverity ());
260
281
261
282
String method = Util .getMethodIdentifier (stream .getEnclosingEclipseMethod ());
283
+
262
284
printStreamAttributesWithMultipleValues (stream .getActions (), streamActionsPrinter , stream ,
263
285
method , javaProject );
286
+
264
287
printStreamAttributesWithMultipleValues (stream .getPossibleExecutionModes (),
265
288
streamExecutionModePrinter , stream , method , javaProject );
289
+
266
290
printStreamAttributesWithMultipleValues (stream .getPossibleOrderings (), streamOrderingPrinter ,
267
291
stream , method , javaProject );
268
292
@@ -279,16 +303,20 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
279
303
stream .getEnclosingType ().getFullyQualifiedName ());
280
304
281
305
// failed streams.
282
- for (Stream stream : processor .getUnoptimizableStreams ())
306
+ SetView <Stream > failures = Sets .difference (candidates , processor .getOptimizableStreams ());
307
+
308
+ for (Stream stream : failures )
283
309
nonOptimizedStreamPrinter .printRecord (javaProject .getElementName (), stream .getCreation (),
284
310
stream .getCreation ().getStartPosition (), stream .getCreation ().getLength (),
285
311
Util .getMethodIdentifier (stream .getEnclosingEclipseMethod ()),
286
312
stream .getEnclosingType () == null ? null
287
313
: stream .getEnclosingType ().getFullyQualifiedName ());
288
314
289
315
// failed preconditions.
290
- List <RefactoringStatusEntry > errorEntries = Arrays .stream (status .getEntries ())
291
- .filter (RefactoringStatusEntry ::isError ).collect (Collectors .toList ());
316
+ Collection <RefactoringStatusEntry > errorEntries = failures .parallelStream ().map (Stream ::getStatus )
317
+ .flatMap (s -> Arrays .stream (s .getEntries ())).filter (RefactoringStatusEntry ::isError )
318
+ .collect (Collectors .toSet ());
319
+
292
320
resultsPrinter .print (errorEntries .size ()); // number.
293
321
294
322
for (RefactoringStatusEntry entry : errorEntries )
@@ -301,6 +329,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
301
329
+ correspondingElement .getClass ());
302
330
303
331
Stream failedStream = (Stream ) correspondingElement ;
332
+
304
333
errorPrinter .printRecord (javaProject .getElementName (), failedStream .getCreation (),
305
334
failedStream .getCreation ().getStartPosition (),
306
335
failedStream .getCreation ().getLength (),
0 commit comments