Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine generic nature of targeted methods in J.MethodInvocation #4721

Open
MBoegers opened this issue Nov 27, 2024 · 0 comments
Open

Determine generic nature of targeted methods in J.MethodInvocation #4721

MBoegers opened this issue Nov 27, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@MBoegers
Copy link
Contributor

What problem are you trying to solve?

For any method targeted by a J.MethodInvocation it should be easy to determine if the method's return type is generic.
This is needed in some cases to implement migrations for language features.
As generics introduce a whole new level of complexity, it should be easy to leave such invocations untouched.

class Test {
    void tst() {
        Object o;
        String some = new GenericClazz<String>().cast(o);  // <1>
        String someStr = new GenericClazz<String>().hashIt("Just a Tests"); // <2>
        String other = StaticClazz.cast(o); // <3>
    }
}

class GenericClazz<T> {
    T cast(Object O) {}
    String hashIt(T t) {}
}

class StaticClazz {
    static <T> T cast(Object o) {}
}

Bullets 1 and 2 are somehow decidable by analyzing the owning class or the parameters of the method.
For Bullet 3 the information are lost, as @knutwannheden describes here it is somehow decideable.

Describe the solution you'd like

I'd like to be able to get the information from the J.MethodInvocation#getMethodType.
Maybe a new Flag would solve this problem and could also be used as shorthand around J.ClassDeclarations.

Have you considered any alternatives or workarounds?

See https://rewriteoss.slack.com/archives/C01A843MWG5/p1732217494169589

Additional context

Are you interested in contributing this feature to OpenRewrite?

Yes

@MBoegers MBoegers added the enhancement New feature or request label Nov 27, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

1 participant