rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Rewrite calls from deprecated API to target API

Open mipo256 opened this issue 7 months ago • 1 comments

What problem are you trying to solve?

Certain API got deprecated in favor of something new. There is a replacement, and we need to define the rules on how old, deprecated API calls are transitioned into a new call, that is open to discussion

What precondition(s) should be checked before applying this recipe?

We have calls to an old API. The old API produces the type A. The old API produces also either the type A, or any of its children. So it is backward compatible on the source code level. But the input parameters are either changed, or more qualified, or re-arranged or etc.

Describe the situation before applying the recipe

class A {

    void foo(String a, String b) {
        bar(a, b);
    }
    
    /**
     * @deprecated in favor of #bar(Integer, Boolean)
     */
    @Deprecated
    void bar(Integer int, String value) {
    }

    void bar(Integer int, Boolean value) {
    }
}

Describe the situation after applying the recipe

class A {

    void foo(String a, String b) {
        bar(a, Boolean.valueOf(b));
    }
    
    /**
     * @deprecated in favor of #bar(Integer, Boolean)
     */
    @Deprecated
    void bar(Integer int, String value) {
    }

    void bar(Integer int, Boolean value) {
    }
}

Have you considered any alternatives or workarounds?

Based on documentation, there are no workarounds to this in openrewrite, yet.

Any additional context

Are you interested in contributing this recipe to OpenRewrite?

Yes, I would like to

mipo256 avatar Jun 01 '25 20:06 mipo256

hi! It's not immediately clear what you're proposing to contribute. Would this be a new recipe that reads the JavaDoc?

We've had a recent proposal that perhaps comes close to what you're suggesting, somewhat similar to ErrorProne's @InlineMe:

  • https://github.com/openrewrite/rewrite/issues/5400

Any additional details you can provide would help us better understand and guide your efforts.

timtebeek avatar Jun 01 '25 20:06 timtebeek

You might be interested in this new recipe:

  • https://github.com/openrewrite/rewrite-migrate-java/pull/788#issuecomment-3200452153

timtebeek avatar Aug 19 '25 11:08 timtebeek