diff --git a/src/main/java/org/openrewrite/java/spring/NoRepoAnnotationOnRepoInterface.java b/src/main/java/org/openrewrite/java/spring/NoRepoAnnotationOnRepoInterface.java index 008dd199e..7a3534a86 100644 --- a/src/main/java/org/openrewrite/java/spring/NoRepoAnnotationOnRepoInterface.java +++ b/src/main/java/org/openrewrite/java/spring/NoRepoAnnotationOnRepoInterface.java @@ -59,7 +59,8 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex }); if (hasRepoAnnotation && TypeUtils.isAssignableTo(INTERFACE_REPOSITORY, c.getType())) { maybeRemoveImport(ANNOTATION_REPOSITORY); - return (J.ClassDeclaration) new RemoveAnnotationVisitor(new AnnotationMatcher("@" + ANNOTATION_REPOSITORY)).visit(c, ctx, getCursor()); + return (J.ClassDeclaration) new RemoveAnnotationVisitor(new AnnotationMatcher("@" + ANNOTATION_REPOSITORY)) + .visit(c, ctx, getCursor().getParentOrThrow()); } } return c; diff --git a/src/main/java/org/openrewrite/java/spring/NoRequestMappingAnnotation.java b/src/main/java/org/openrewrite/java/spring/NoRequestMappingAnnotation.java index 1b1f4b034..fba586c0a 100644 --- a/src/main/java/org/openrewrite/java/spring/NoRequestMappingAnnotation.java +++ b/src/main/java/org/openrewrite/java/spring/NoRequestMappingAnnotation.java @@ -104,7 +104,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct maybeAddImport("org.springframework.web.bind.annotation." + resolvedRequestMappingAnnotationClassName); a = (J.Annotation) new ChangeType("org.springframework.web.bind.annotation.RequestMapping", "org.springframework.web.bind.annotation." + resolvedRequestMappingAnnotationClassName, false) - .getVisitor().visit(a, ctx, getCursor()); + .getVisitor().visit(a, ctx, getCursor().getParentOrThrow()); // if there is only one remaining argument now, and it is "path" or "value", then we can drop the key name if (a != null && a.getArguments() != null && a.getArguments().size() == 1) {