2424import org .openrewrite .java .JavaIsoVisitor ;
2525import org .openrewrite .java .format .TabsAndIndentsVisitor ;
2626import org .openrewrite .java .style .IntelliJ ;
27+ import org .openrewrite .java .style .SpacesStyle ;
2728import org .openrewrite .java .style .TabsAndIndentsStyle ;
2829import org .openrewrite .java .tree .J ;
2930import org .openrewrite .java .tree .JavaSourceFile ;
3031import org .openrewrite .java .tree .Loop ;
3132import org .openrewrite .java .tree .Statement ;
33+ import org .openrewrite .style .Style ;
3234
3335import java .time .Duration ;
3436import java .util .Set ;
@@ -63,17 +65,17 @@ public Duration getEstimatedEffortPerOccurrence() {
6365 @ Override
6466 public TreeVisitor <?, ExecutionContext > getVisitor () {
6567 return new JavaIsoVisitor <ExecutionContext >() {
68+ @ Nullable
6669 TabsAndIndentsStyle tabsAndIndentsStyle ;
70+ @ Nullable
71+ SpacesStyle spacesStyle ;
6772
6873 @ Override
69- public J visit (@ Nullable Tree tree , ExecutionContext ctx ) {
74+ public @ Nullable J visit (@ Nullable Tree tree , ExecutionContext ctx ) {
7075 if (tree instanceof JavaSourceFile ) {
7176 JavaSourceFile cu = (JavaSourceFile ) requireNonNull (tree );
72- TabsAndIndentsStyle style = cu .getStyle (TabsAndIndentsStyle .class );
73- if (style == null ) {
74- style = IntelliJ .tabsAndIndents ();
75- }
76- tabsAndIndentsStyle = style ;
77+ tabsAndIndentsStyle = Style .from (TabsAndIndentsStyle .class , cu , IntelliJ ::tabsAndIndents );
78+ spacesStyle = Style .from (SpacesStyle .class , cu , IntelliJ ::spaces );
7779 }
7880 return super .visit (tree , ctx );
7981 }
@@ -85,7 +87,10 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) {
8587 return b .withStatements (ListUtils .map (b .getStatements (), (i , statement ) -> {
8688 if (foundControlFlowRequiringReformatting .get () || shouldReformat (statement )) {
8789 foundControlFlowRequiringReformatting .set (true );
88- return (Statement ) new TabsAndIndentsVisitor <>(tabsAndIndentsStyle ).visit (statement , ctx , getCursor ());
90+ return (Statement ) new TabsAndIndentsVisitor <>(
91+ requireNonNull (tabsAndIndentsStyle ),
92+ requireNonNull (spacesStyle ))
93+ .visit (statement , ctx , getCursor ());
8994 }
9095 return statement ;
9196 }));
0 commit comments