5757import com .diffplug .spotless .extra .EclipseBasedStepBuilder ;
5858import com .diffplug .spotless .extra .wtp .EclipseWtpFormatterStep ;
5959import com .diffplug .spotless .generic .EndWithNewlineStep ;
60+ import com .diffplug .spotless .generic .FenceStep ;
6061import com .diffplug .spotless .generic .IndentStep ;
6162import com .diffplug .spotless .generic .LicenseHeaderStep ;
6263import com .diffplug .spotless .generic .LicenseHeaderStep .YearMode ;
6364import com .diffplug .spotless .generic .NativeCmdStep ;
64- import com .diffplug .spotless .generic .PipeStepPair ;
6565import com .diffplug .spotless .generic .ReplaceRegexStep ;
6666import com .diffplug .spotless .generic .ReplaceStep ;
6767import com .diffplug .spotless .generic .TrimTrailingWhitespaceStep ;
@@ -989,7 +989,7 @@ public void withinBlocks(String name, String open, String close, Action<FormatEx
989989 */
990990 public <T extends FormatExtension > void withinBlocks (String name , String open , String close , Class <T > clazz ,
991991 Action <T > configure ) {
992- withinBlocksHelper (PipeStepPair .named (name ).openClose (open , close ), clazz , configure );
992+ withinBlocksHelper (FenceStep .named (name ).openClose (open , close ), clazz , configure );
993993 }
994994
995995 /**
@@ -1007,18 +1007,17 @@ public void withinBlocksRegex(String name, String regex, Action<FormatExtension>
10071007 */
10081008 public <T extends FormatExtension > void withinBlocksRegex (String name , String regex , Class <T > clazz ,
10091009 Action <T > configure ) {
1010- withinBlocksHelper (PipeStepPair .named (name ).regex (regex ), clazz , configure );
1010+ withinBlocksHelper (FenceStep .named (name ).regex (regex ), clazz , configure );
10111011 }
10121012
1013- private <T extends FormatExtension > void withinBlocksHelper (PipeStepPair . Builder builder , Class <T > clazz ,
1013+ private <T extends FormatExtension > void withinBlocksHelper (FenceStep fence , Class <T > clazz ,
10141014 Action <T > configure ) {
10151015 // create the sub-extension
10161016 T formatExtension = spotless .instantiateFormatExtension (clazz );
10171017 // configure it
10181018 configure .execute (formatExtension );
10191019 // create a step which applies all of those steps as sub-steps
1020- FormatterStep step = builder .buildStepWhichAppliesSubSteps (spotless .project .getRootDir ().toPath (),
1021- formatExtension .steps );
1020+ FormatterStep step = fence .applyWithin (formatExtension .steps );
10221021 addStep (step );
10231022 }
10241023
@@ -1027,28 +1026,28 @@ private <T extends FormatExtension> void withinBlocksHelper(PipeStepPair.Builder
10271026 * that captured group.
10281027 */
10291028 public void toggleOffOnRegex (String regex ) {
1030- this .togglePair = PipeStepPair .named (PipeStepPair .defaultToggleName ()).regex (regex ). buildPair ( );
1029+ this .toggleFence = FenceStep .named (FenceStep .defaultToggleName ()).regex (regex );
10311030 }
10321031
10331032 /** Disables formatting between the given tags. */
10341033 public void toggleOffOn (String off , String on ) {
1035- this .togglePair = PipeStepPair .named (PipeStepPair .defaultToggleName ()).openClose (off , on ). buildPair ( );
1034+ this .toggleFence = FenceStep .named (FenceStep .defaultToggleName ()).openClose (off , on );
10361035 }
10371036
10381037 /** Disables formatting between {@code spotless:off} and {@code spotless:on}. */
10391038 public void toggleOffOn () {
1040- toggleOffOn (PipeStepPair .defaultToggleOff (), PipeStepPair .defaultToggleOn ());
1039+ toggleOffOn (FenceStep .defaultToggleOff (), FenceStep .defaultToggleOn ());
10411040 }
10421041
10431042 /**
10441043 * Undoes all previous calls to {@link #toggleOffOn()} and
10451044 * {@link #toggleOffOn(String, String)}.
10461045 */
10471046 public void toggleOffOnDisable () {
1048- this .togglePair = null ;
1047+ this .toggleFence = null ;
10491048 }
10501049
1051- private @ Nullable PipeStepPair togglePair ;
1050+ private @ Nullable FenceStep toggleFence ;
10521051
10531052 /** Sets up a format task according to the values in this extension. */
10541053 protected void setupTask (SpotlessTask task ) {
@@ -1057,11 +1056,8 @@ protected void setupTask(SpotlessTask task) {
10571056 FileCollection totalTarget = targetExclude == null ? target : target .minus (targetExclude );
10581057 task .setTarget (totalTarget );
10591058 List <FormatterStep > steps ;
1060- if (togglePair != null ) {
1061- steps = new ArrayList <>(this .steps .size () + 2 );
1062- steps .add (togglePair .in ());
1063- steps .addAll (this .steps );
1064- steps .add (togglePair .out ());
1059+ if (toggleFence != null ) {
1060+ steps = List .of (toggleFence .preserveWithin (this .steps ));
10651061 } else {
10661062 steps = this .steps ;
10671063 }
0 commit comments