From 9deb5720b4db50de1a8439ac3508a503ce0d9bf8 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Tue, 20 Feb 2024 09:57:07 +0100 Subject: [PATCH] Pass correct cursor in `visitNonNull()` calls (#495) * Pass correct cursor in `visitNonNull()` calls * Fix compile error in `DowngradeServletApiWhenUsingJetty` * Fix two compiler warnings * Revert "Fix compile error in `DowngradeServletApiWhenUsingJetty`" This reverts commit 5548109d78b13ccdeb08e3d99d9c694d89c821d4. --- .../spring/batch/ReplaceSupportClassWithItsInterface.java | 2 +- .../boot2/ReplaceExtendWithAndContextConfiguration.java | 2 +- .../openrewrite/java/spring/boot3/AddRouteTrailingSlash.java | 4 ++-- .../java/spring/framework/MigrateWebMvcConfigurerAdapter.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openrewrite/java/spring/batch/ReplaceSupportClassWithItsInterface.java b/src/main/java/org/openrewrite/java/spring/batch/ReplaceSupportClassWithItsInterface.java index 72a209acc..325ab2456 100644 --- a/src/main/java/org/openrewrite/java/spring/batch/ReplaceSupportClassWithItsInterface.java +++ b/src/main/java/org/openrewrite/java/spring/batch/ReplaceSupportClassWithItsInterface.java @@ -84,7 +84,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, getCursor(), cd.getCoordinates().addImplementsClause() ); - cd = (J.ClassDeclaration) new RemoveSuperStatementVisitor().visitNonNull(cd, ctx, getCursor()); + cd = (J.ClassDeclaration) new RemoveSuperStatementVisitor().visitNonNull(cd, ctx, getCursor().getParentOrThrow()); maybeRemoveImport(fullyQualifiedClassName); maybeAddImport(fullyQualifiedInterfaceName); } diff --git a/src/main/java/org/openrewrite/java/spring/boot2/ReplaceExtendWithAndContextConfiguration.java b/src/main/java/org/openrewrite/java/spring/boot2/ReplaceExtendWithAndContextConfiguration.java index f6c8959d5..142e8d300 100644 --- a/src/main/java/org/openrewrite/java/spring/boot2/ReplaceExtendWithAndContextConfiguration.java +++ b/src/main/java/org/openrewrite/java/spring/boot2/ReplaceExtendWithAndContextConfiguration.java @@ -90,7 +90,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct maybeRemoveImport(FQN_CONTEXT_CONFIGURATION); maybeAddImport(FQN_SPRING_JUNIT_CONFIG); a = (J.Annotation) new ChangeType(FQN_CONTEXT_CONFIGURATION, FQN_SPRING_JUNIT_CONFIG, false) - .getVisitor().visitNonNull(a, ctx, getCursor()); + .getVisitor().visitNonNull(a, ctx, getCursor().getParentOrThrow()); a = autoFormat(a, ctx); } diff --git a/src/main/java/org/openrewrite/java/spring/boot3/AddRouteTrailingSlash.java b/src/main/java/org/openrewrite/java/spring/boot3/AddRouteTrailingSlash.java index eabe9c6a3..e7388f8f9 100644 --- a/src/main/java/org/openrewrite/java/spring/boot3/AddRouteTrailingSlash.java +++ b/src/main/java/org/openrewrite/java/spring/boot3/AddRouteTrailingSlash.java @@ -71,7 +71,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct .build() .apply(getCursor(), anno.getCoordinates().replaceArguments(), - buildTwoStringsArray(str)); + (Object[]) buildTwoStringsArray(str)); return autoFormat(replacement, ctx); } } else { @@ -90,7 +90,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct .build() .apply(getCursor(), anno.getCoordinates().replaceArguments(), - buildTwoStringsArray(str)).getArguments().get(0); + (Object[]) buildTwoStringsArray(str)).getArguments().get(0); } } } diff --git a/src/main/java/org/openrewrite/java/spring/framework/MigrateWebMvcConfigurerAdapter.java b/src/main/java/org/openrewrite/java/spring/framework/MigrateWebMvcConfigurerAdapter.java index 107d68549..d3d0a0412 100644 --- a/src/main/java/org/openrewrite/java/spring/framework/MigrateWebMvcConfigurerAdapter.java +++ b/src/main/java/org/openrewrite/java/spring/framework/MigrateWebMvcConfigurerAdapter.java @@ -63,7 +63,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex .classpathFromResources(ctx, "spring-webmvc-5.*")) .build().apply(getCursor(), cd.getCoordinates().addImplementsClause()); updateCursor(cd); - cd = (J.ClassDeclaration) new RemoveSuperStatementVisitor().visitNonNull(cd, ctx, getCursor()); + cd = (J.ClassDeclaration) new RemoveSuperStatementVisitor().visitNonNull(cd, ctx, getCursor().getParentOrThrow()); maybeRemoveImport("org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter"); maybeAddImport("org.springframework.web.servlet.config.annotation.WebMvcConfigurer"); }