1

If you pass an inner class to maybeRemoveImport then imports of the outer class are not removed. Is this intended or could this be a helpful extension of the method?

An example: I have this code

import javax.ws.rs.core.Response;

public class TestController {

    public void respond() {
       System.out.println(Response.Status.NOT_FOUND);
    }
}

If I apply the recipe ReplaceConstantWithAnotherConstant to replace javax.ws.rs.core.Response$Status.NOT_FOUND with org.springframework.http.HttpStatus.NOT_FOUND then the import import javax.ws.rs.core.Response; is not removed as maybeRemoveImport is called with argument javax.ws.rs.core.Response$Status.

  • 1
    That indeed sounds like a bug and your suggestion makes sense. I suggest you report a GitHub issue for this problem. – knutwannheden Apr 10 '23 at 11:33
  • Thanks for another good suggestion; I've converted your question here into a feature request: https://github.com/openrewrite/rewrite/issues/3101 – Tim Apr 10 '23 at 15:08

1 Answers1

1

As mentioned in the comments to your question this was a bug in OpenRewrite which meanwhile has been fixed and is available as part of the latest 7.40.0-SNAPSHOT builds (see documentation for instructions).

With this fix the ReplaceConstantWithAnotherConstant recipe will remove the javax.ws.rs.core.Response import in the example you gave.

knutwannheden
  • 680
  • 4
  • 7