@@ -326,7 +326,11 @@ protected InstanceKey computeInstanceKey(Collection<InstanceKey> trackedInstance
326326 }
327327
328328 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 ) {
330334 MethodInvocation creation = this .getCreation ();
331335 ASTRewrite astRewrite = rewrite .getASTRewrite ();
332336
@@ -342,44 +346,38 @@ protected void convertToParallel(CompilationUnitRewrite rewrite) {
342346 MethodInvocation inv = (MethodInvocation ) expression ;
343347 AST ast = creation .getAST ();
344348
345- switch (inv .getName ().getIdentifier ()) {
346- case "sequential" :
349+ String identifier = inv .getName ().getIdentifier ();
350+
351+ if (identifier .equals (source )) {
347352 // remove it.
348353 astRewrite .replace (inv , inv .getExpression (), null );
349- break ;
350- case "parallel" :
354+ } else if (identifier .equals (target )) {
351355 done = true ;
352- break ;
353- case "stream" : {
356+ } else if (identifier .equals (sourceGenerator )) {
354357 // Replace with parallelStream().
355- SimpleName newMethodName = ast .newSimpleName ("parallelStream" );
358+ SimpleName newMethodName = ast .newSimpleName (targetGenerator );
356359 astRewrite .replace (creation .getName (), newMethodName , null );
357- break ;
358- }
359- case "parallelStream" :
360+ } else if (identifier .equals (targetGenerator )) {
360361 done = true ;
361- break ;
362- default : {
362+ } else {
363363 // if we're at the end.
364364 if (inv .getExpression ().getNodeType () != ASTNode .METHOD_INVOCATION
365365 || inv .getExpression ().getNodeType () == ASTNode .METHOD_INVOCATION
366366 && !implementsBaseStream (inv .getExpression ().resolveTypeBinding ())) {
367367 MethodInvocation newMethodInvocation = ast .newMethodInvocation ();
368- newMethodInvocation .setName (ast .newSimpleName ("parallel" ));
368+ newMethodInvocation .setName (ast .newSimpleName (target ));
369369 MethodInvocation invCopy = (MethodInvocation ) ASTNode .copySubtree (ast , inv );
370370 newMethodInvocation .setExpression (invCopy );
371371 astRewrite .replace (inv , newMethodInvocation , null );
372372 }
373373 }
374- }
375374 expression = inv .getExpression ();
376375 } else
377376 done = true ;
378377 }
379378
380379 protected void convertToSequential (CompilationUnitRewrite rewrite ) {
381380 // TODO Auto-generated method stub
382- LOGGER .info ("Converting to sequential." );
383381 }
384382
385383 public Set <TransformationAction > getActions () {
@@ -861,6 +859,5 @@ public void transform(CompilationUnitRewrite rewrite) {
861859
862860 protected void unorder (CompilationUnitRewrite rewrite ) {
863861 // TODO Auto-generated method stub
864- LOGGER .info ("Unordering." );
865862 }
866863}
0 commit comments