Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/main/java/org/openrewrite/java/migrate/UseTabsOrSpaces.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.openrewrite.java.style.TabsAndIndentsStyle;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaSourceFile;
import org.openrewrite.style.Style;

import static java.util.Objects.requireNonNull;

Expand All @@ -43,7 +44,7 @@ public String getDisplayName() {
@Override
public String getDescription() {
return "This is useful for one-off migrations of a codebase that has mixed indentation styles, while " +
"preserving all other auto-detected formatting rules.";
"preserving all other auto-detected formatting rules.";
}

@Override
Expand All @@ -53,11 +54,8 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
public J visit(@Nullable Tree tree, ExecutionContext ctx) {
if (tree instanceof JavaSourceFile) {
JavaSourceFile cu = (JavaSourceFile) requireNonNull(tree);
TabsAndIndentsStyle style = ((SourceFile) cu).getStyle(TabsAndIndentsStyle.class);
if (style == null) {
style = IntelliJ.tabsAndIndents();
}
style = style.withUseTabCharacter(useTabs);
TabsAndIndentsStyle style = Style.from(TabsAndIndentsStyle.class, cu, IntelliJ::tabsAndIndents)
.withUseTabCharacter(useTabs);
return new NormalizeTabsOrSpacesVisitor<>(style).visit(tree, ctx);
}
return (J) tree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.marker.Markers;
import org.openrewrite.staticanalysis.kotlin.KotlinFileChecker;
import org.openrewrite.style.Style;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Optional;

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -145,8 +145,7 @@ private J.Literal toTextBlock(J.Binary binary, String content, List<J.Literal> s
}
}

TabsAndIndentsStyle tabsAndIndentsStyle = Optional.ofNullable(getCursor().firstEnclosingOrThrow(SourceFile.class)
.getStyle(TabsAndIndentsStyle.class)).orElse(IntelliJ.tabsAndIndents());
TabsAndIndentsStyle tabsAndIndentsStyle = Style.from(TabsAndIndentsStyle.class, getCursor().firstEnclosingOrThrow(SourceFile.class), IntelliJ::tabsAndIndents);
boolean useTab = tabsAndIndentsStyle.getUseTabCharacter();
int tabSize = tabsAndIndentsStyle.getTabSize();

Expand Down