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

Update method-patterns.md #357

Merged
merged 1 commit into from
Feb 28, 2025
Merged

Conversation

CodexRaunak
Copy link
Contributor

@CodexRaunak CodexRaunak commented Feb 28, 2025

Update the ChangeMethodNameVisitor class.

What's changed?

  • The getType() returns a JavaType, changed it to getMethodType().
  • With withType() we have to mention the withMethodType() as well or it will give the error of missing type or invalid type error.

What's your motivation?

I was making a recipe to change the method name, when I refered docs I used the code provided in the ChangeMethodNameVisitor but it errored to missing type or invalid type in LST. Then I made the required changes, maybe this was the correct one used before. But now the current change works.

I reffered this https://github.com/openrewrite/rewrite/blob/main/rewrite-java/src/main/java/org/openrewrite/java/ChangeMethodName.java#L103-L110

Before:

JavaType.Method type = m.getType();
            if (type != null) {
                type = type.withName(newMethodName);
            }

            m = m.withName(m.getName().withName(newMethodName))
                    .withType(type);
        }

image
Or also change made in 2 cycles error.

After:
No error, recipe works fine.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

Update the ChangeMethodNameVisitor class.
Copy link
Contributor

@mike-solomon mike-solomon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for catching and fixing this!

@mike-solomon mike-solomon merged commit 7b0a1ad into openrewrite:master Feb 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants