Skip to content

Commit eee4327

Browse files
LakshyaKwatraLakshya Kwatratimtebeek
authored
Add regression test to verify that no default import order style is applied (#597)
* Add regression test to verify that no default import order style is applied. * Minor polish --------- Co-authored-by: Lakshya Kwatra <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
1 parent 3631783 commit eee4327

File tree

2 files changed

+294
-281
lines changed

2 files changed

+294
-281
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import org.openrewrite.java.tree.JavaSourceFile;
2727
import org.openrewrite.style.Style;
2828

29-
import static java.util.Objects.requireNonNull;
30-
3129
public class CustomImportOrder extends Recipe {
3230

3331
@Override
@@ -42,20 +40,17 @@ public String getDescription() {
4240

4341
@Override
4442
public TreeVisitor<?, ExecutionContext> getVisitor() {
45-
return new CustomImportOrderCompilationUnitStyle();
46-
}
47-
48-
private static class CustomImportOrderCompilationUnitStyle extends JavaIsoVisitor<ExecutionContext> {
49-
@Override
50-
public @Nullable J visit(@Nullable Tree tree, ExecutionContext ctx) {
51-
if (tree instanceof JavaSourceFile) {
52-
JavaSourceFile cu = (JavaSourceFile) requireNonNull(tree);
53-
CustomImportOrderStyle style = Style.from(CustomImportOrderStyle.class, cu);
54-
if (style != null) {
55-
return new CustomImportOrderVisitor<>(style).visitNonNull(cu, ctx);
43+
return new JavaIsoVisitor<ExecutionContext>() {
44+
@Override
45+
public @Nullable J visit(@Nullable Tree tree, ExecutionContext ctx) {
46+
if (tree instanceof JavaSourceFile) {
47+
CustomImportOrderStyle style = Style.from(CustomImportOrderStyle.class, (JavaSourceFile) tree);
48+
if (style != null) {
49+
return new CustomImportOrderVisitor<>(style).visitNonNull(tree, ctx);
50+
}
5651
}
52+
return (J) tree;
5753
}
58-
return (J) tree;
59-
}
54+
};
6055
}
6156
}

0 commit comments

Comments
 (0)