Skip to content

Commit 3631783

Browse files
committed
Add SpacesStyle to TabsAndIndentsVisitor following openrewrite/rewrite#5649
1 parent c309a51 commit 3631783

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/main/java/org/openrewrite/staticanalysis/ControlFlowIndentation.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
import org.openrewrite.java.JavaIsoVisitor;
2525
import org.openrewrite.java.format.TabsAndIndentsVisitor;
2626
import org.openrewrite.java.style.IntelliJ;
27+
import org.openrewrite.java.style.SpacesStyle;
2728
import org.openrewrite.java.style.TabsAndIndentsStyle;
2829
import org.openrewrite.java.tree.J;
2930
import org.openrewrite.java.tree.JavaSourceFile;
3031
import org.openrewrite.java.tree.Loop;
3132
import org.openrewrite.java.tree.Statement;
33+
import org.openrewrite.style.Style;
3234

3335
import java.time.Duration;
3436
import 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

Comments
 (0)