@@ -326,7 +326,11 @@ protected InstanceKey computeInstanceKey(Collection<InstanceKey> trackedInstance
326
326
}
327
327
328
328
protected void convertToParallel (CompilationUnitRewrite rewrite ) {
329
- LOGGER .info ("Converting to parallel." );
329
+ convert ("sequential" , "parallel" , "stream" , "parallelStream" , rewrite );
330
+ }
331
+
332
+ private void convert (String source , String target , String sourceGenerator , String targetGenerator ,
333
+ CompilationUnitRewrite rewrite ) {
330
334
MethodInvocation creation = this .getCreation ();
331
335
ASTRewrite astRewrite = rewrite .getASTRewrite ();
332
336
@@ -342,44 +346,38 @@ protected void convertToParallel(CompilationUnitRewrite rewrite) {
342
346
MethodInvocation inv = (MethodInvocation ) expression ;
343
347
AST ast = creation .getAST ();
344
348
345
- switch (inv .getName ().getIdentifier ()) {
346
- case "sequential" :
349
+ String identifier = inv .getName ().getIdentifier ();
350
+
351
+ if (identifier .equals (source )) {
347
352
// remove it.
348
353
astRewrite .replace (inv , inv .getExpression (), null );
349
- break ;
350
- case "parallel" :
354
+ } else if (identifier .equals (target )) {
351
355
done = true ;
352
- break ;
353
- case "stream" : {
356
+ } else if (identifier .equals (sourceGenerator )) {
354
357
// Replace with parallelStream().
355
- SimpleName newMethodName = ast .newSimpleName ("parallelStream" );
358
+ SimpleName newMethodName = ast .newSimpleName (targetGenerator );
356
359
astRewrite .replace (creation .getName (), newMethodName , null );
357
- break ;
358
- }
359
- case "parallelStream" :
360
+ } else if (identifier .equals (targetGenerator )) {
360
361
done = true ;
361
- break ;
362
- default : {
362
+ } else {
363
363
// if we're at the end.
364
364
if (inv .getExpression ().getNodeType () != ASTNode .METHOD_INVOCATION
365
365
|| inv .getExpression ().getNodeType () == ASTNode .METHOD_INVOCATION
366
366
&& !implementsBaseStream (inv .getExpression ().resolveTypeBinding ())) {
367
367
MethodInvocation newMethodInvocation = ast .newMethodInvocation ();
368
- newMethodInvocation .setName (ast .newSimpleName ("parallel" ));
368
+ newMethodInvocation .setName (ast .newSimpleName (target ));
369
369
MethodInvocation invCopy = (MethodInvocation ) ASTNode .copySubtree (ast , inv );
370
370
newMethodInvocation .setExpression (invCopy );
371
371
astRewrite .replace (inv , newMethodInvocation , null );
372
372
}
373
373
}
374
- }
375
374
expression = inv .getExpression ();
376
375
} else
377
376
done = true ;
378
377
}
379
378
380
379
protected void convertToSequential (CompilationUnitRewrite rewrite ) {
381
380
// TODO Auto-generated method stub
382
- LOGGER .info ("Converting to sequential." );
383
381
}
384
382
385
383
public Set <TransformationAction > getActions () {
@@ -861,6 +859,5 @@ public void transform(CompilationUnitRewrite rewrite) {
861
859
862
860
protected void unorder (CompilationUnitRewrite rewrite ) {
863
861
// TODO Auto-generated method stub
864
- LOGGER .info ("Unordering." );
865
862
}
866
863
}
0 commit comments