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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.openrewrite.kotlin.KotlinTemplate;
import org.openrewrite.kotlin.tree.K;
import org.openrewrite.staticanalysis.LambdaBlockToExpression;
import org.openrewrite.staticanalysis.java.JavaFileChecker;
import org.openrewrite.staticanalysis.kotlin.KotlinFileChecker;

import java.util.*;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -55,14 +57,10 @@ public class AssertThrowsOnLastStatement extends Recipe {
public TreeVisitor<?, ExecutionContext> getVisitor() {
MethodMatcher assertThrowsMatcher = new MethodMatcher(
"org.junit.jupiter.api.Assertions assertThrows(java.lang.Class, org.junit.jupiter.api.function.Executable, ..)");
return Preconditions.check(new UsesMethod<>(assertThrowsMatcher), new JavaIsoVisitor<ExecutionContext>() {
@Override
public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) {
return Preconditions.check(Preconditions.and(
// Only Java and Kotlin are supported, as the extracted variable declaration is rendered per language
return (sourceFile instanceof J.CompilationUnit || sourceFile instanceof K.CompilationUnit) &&
super.isAcceptable(sourceFile, ctx);
}

Preconditions.or(new JavaFileChecker<>(), new KotlinFileChecker<>()),
new UsesMethod<>(assertThrowsMatcher)), new JavaIsoVisitor<ExecutionContext>() {
@Override
public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl, ExecutionContext ctx) {
J.MethodDeclaration m = super.visitMethodDeclaration(methodDecl, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openrewrite.java.search.UsesType;
import org.openrewrite.java.tree.*;
import org.openrewrite.marker.Markers;
import org.openrewrite.staticanalysis.java.JavaFileChecker;

import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -52,16 +53,11 @@ public class ExpectedSystemExitToCatchSystemExit extends Recipe {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesType<>(EXPECTED_SYSTEM_EXIT, false), new JavaVisitor<ExecutionContext>() {
return Preconditions.check(Preconditions.and(new JavaFileChecker<>(), new UsesType<>(EXPECTED_SYSTEM_EXIT, false)), new JavaVisitor<ExecutionContext>() {
private final Set<JavaType.Variable> migrated = new HashSet<>();
private final Map<JavaType.Variable, String> todos = new HashMap<>();
private final Map<UUID, ExitPlan> plans = new HashMap<>();

@Override
public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) {
return sourceFile instanceof J.CompilationUnit;
}

@Override
public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
migrated.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.SourceFile;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.java.AnnotationMatcher;
Expand All @@ -34,6 +33,7 @@
import org.openrewrite.java.trait.Annotated;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.staticanalysis.java.JavaFileChecker;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -79,19 +79,15 @@ public class JUnitSoftAssertionsToSoftAssertionsExtension extends Recipe {
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(
Preconditions.and(
// Kotlin properties would need `lateinit var` rather than a dropped `final` and initializer, and
// the `ChangeType` below is driven from a `J.CompilationUnit` that a Kotlin source does not have.
new JavaFileChecker<>(),
new UsesType<>(RULE, false),
Preconditions.or(
new UsesType<>(JUNIT_SOFT_ASSERTIONS, false),
new UsesType<>(JUNIT_BDD_SOFT_ASSERTIONS, false))),
new JavaIsoVisitor<ExecutionContext>() {

// Kotlin properties would need `lateinit var` rather than a dropped `final` and initializer, and
// the `ChangeType` below is driven from a `J.CompilationUnit` that a Kotlin source does not have.
@Override
public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) {
return sourceFile instanceof J.CompilationUnit;
}

@Override
public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
getCursor().putMessage(UNCONVERTIBLE_TYPES, unconvertibleRuleTypes(cu));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.SourceFile;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.java.JavaIsoVisitor;
Expand All @@ -37,6 +36,7 @@
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.Statement;
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.staticanalysis.java.JavaFileChecker;

import java.util.*;

Expand All @@ -63,12 +63,7 @@ public class SystemPropertyRulesToPioneer extends Recipe {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesType<>(PACKAGE + ".*", false), new JavaIsoVisitor<ExecutionContext>() {
@Override
public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) {
return sourceFile instanceof J.CompilationUnit;
}

return Preconditions.check(Preconditions.and(new JavaFileChecker<>(), new UsesType<>(PACKAGE + ".*", false)), new JavaIsoVisitor<ExecutionContext>() {
@Override
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) {
J.ClassDeclaration cd = super.visitClassDeclaration(classDecl, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.java.service.AnnotationService;
import org.openrewrite.java.tree.*;
import org.openrewrite.marker.Markers;
import org.openrewrite.staticanalysis.java.JavaFileChecker;

import java.util.*;

Expand Down Expand Up @@ -119,15 +120,10 @@ private static class Migration {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesType<>(PACKAGE + ".*", false), new JavaVisitor<ExecutionContext>() {
return Preconditions.check(Preconditions.and(new JavaFileChecker<>(), new UsesType<>(PACKAGE + ".*", false)), new JavaVisitor<ExecutionContext>() {
private final Map<JavaType.Variable, Migration> migrations = new HashMap<>();
private final Map<JavaType.Variable, String> todos = new HashMap<>();

@Override
public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) {
return sourceFile instanceof J.CompilationUnit;
}

@Override
public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
migrations.clear();
Expand Down
Loading