Skip to content

Support refactoring based on an annotation that provides the replacement template (e.g. @InlineMe) #5400

@traceyyoshima

Description

@traceyyoshima

What problem are you trying to solve?

Automated transformations via type attribution and annotations.
Tim asked about automating refactoring during the KotlinParser development using deprecated annotations.

I thought it might be possible to create an OR annotation like DeprecatedX(...), where the annotation arguments provide information about how to handle a migration.

Describe the solution you'd like

  • The annotations could be target-site specific, like METHOD, CLASS, etc.
  • OR would own the annotation, and its existence could trigger a recipe.
  • The type-attribution on a class, method, etc., may have arguments that provide contextual instructions on the migration.
class Example {

    // I don't recall what is available in the annotation arguments, but I imagine something could be sorted out.
    @org.openrewrite.DeprecatedMethod("methodMatcherSig", "someTransformationToMethodB")
    void methodA(...) {...}

    // Method calls of `methodA` would be migrated to `methodB`.
    void methodB(...) {...}
}

Have you considered any alternatives or workarounds?

No, this was just a thought. This may already exist, but I haven't tracked all the changes across OR for awhile.

Are you interested in contributing this feature to OpenRewrite?

I'm pretty busy at the moment, but anything is possible!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestrecipeRequested Recipe

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions