53
53
import com .diffplug .spotless .LineEnding ;
54
54
import com .diffplug .spotless .OnMatch ;
55
55
import com .diffplug .spotless .Provisioner ;
56
+ import com .diffplug .spotless .SerializedFunction ;
56
57
import com .diffplug .spotless .biome .BiomeFlavor ;
57
58
import com .diffplug .spotless .cpp .ClangFormatStep ;
58
59
import com .diffplug .spotless .extra .EclipseBasedStepBuilder ;
@@ -427,7 +428,21 @@ protected Integer calculateState() throws Exception {
427
428
*/
428
429
public void custom (String name , Closure <String > formatter ) {
429
430
requireNonNull (formatter , "formatter" );
430
- custom (name , formatter ::call );
431
+ Closure <String > dehydrated = formatter .dehydrate ();
432
+ custom (name , new ClosureFormatterFunc (dehydrated ));
433
+ }
434
+
435
+ static class ClosureFormatterFunc implements FormatterFunc , Serializable {
436
+ private final Closure <String > closure ;
437
+
438
+ ClosureFormatterFunc (Closure <String > closure ) {
439
+ this .closure = closure ;
440
+ }
441
+
442
+ @ Override
443
+ public String apply (String unixNewlines ) {
444
+ return closure .call (unixNewlines );
445
+ }
431
446
}
432
447
433
448
/**
@@ -436,7 +451,7 @@ public void custom(String name, Closure<String> formatter) {
436
451
*/
437
452
public void custom (String name , FormatterFunc formatter ) {
438
453
requireNonNull (formatter , "formatter" );
439
- addStep (FormatterStep .createLazy (name , () -> globalState , unusedState -> formatter ));
454
+ addStep (FormatterStep .createLazy (name , () -> globalState , SerializedFunction . alwaysReturns ( formatter ) ));
440
455
}
441
456
442
457
/** Highly efficient find-replace char sequence. */
0 commit comments