@@ -380,7 +380,14 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
380380 .map (J .MethodInvocation .class ::cast )
381381 .findFirst ()
382382 .orElseThrow (() -> new IllegalStateException ("Unable to create a new configurations.all block" ));
383- return cu .withStatements (ListUtils .insert (cu .getStatements (), m , insertionIndex ));
383+ List <Statement > newStatements = ListUtils .insert (cu .getStatements (), m , insertionIndex );
384+ if (insertionIndex == 0 ) {
385+ newStatements = ListUtils .map (newStatements , (i , stat ) ->
386+ i == 1 && stat .getPrefix ().getWhitespace ().isEmpty ()
387+ ? stat .withPrefix (stat .getPrefix ().withWhitespace ("\n \n " ))
388+ : stat );
389+ }
390+ return cu .withStatements (newStatements );
384391 } else {
385392 K .CompilationUnit cu = (K .CompilationUnit ) sourceFile ;
386393 assert cu != null ;
@@ -425,7 +432,14 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
425432 final int finalInsertionIndex = insertionIndex ;
426433 return cu .withStatements (ListUtils .mapFirst (cu .getStatements (), arg -> {
427434 if (arg == block ) {
428- return block .withStatements (ListUtils .insert (block .getStatements (), m , finalInsertionIndex ));
435+ List <Statement > newStatements = ListUtils .insert (block .getStatements (), m , finalInsertionIndex );
436+ if (finalInsertionIndex == 0 ) {
437+ newStatements = ListUtils .map (newStatements , (i , stat ) ->
438+ i == 1 && stat .getPrefix ().getWhitespace ().isEmpty ()
439+ ? stat .withPrefix (stat .getPrefix ().withWhitespace ("\n \n " ))
440+ : stat );
441+ }
442+ return block .withStatements (newStatements );
429443 }
430444 return arg ;
431445 }));
0 commit comments