Skip to content

Uniform behaviour for the methodInvocations that are needed for template unsubstitution #5658

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jenson3210
Copy link
Contributor

What's changed?

Added an overload to Substitutions maybeParameter that accepts the prefixed element.
When using a template that passes in a placeholder that must be replaced by an Object / parameter, the resulting template is shows as __P__.<java.lang.Object>/*__p0__*/p()

The existing code will pass methodName's Identifier (/*__p0__*/p()) to the maybeParameter call which will cause it to use the prefix of this Identifier to parse the template resulting in trimmed template prefix.

By overloading and passing the entire methodInvocation for prefix calculations we no longer need to overcome this in every recipe that is using templates but we can just rest assured that the prefix of the template will be also present in the result lst objects.

What's your motivation?

Stumbled into this investigation with @Laurens-W after having some other template issues.

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

@Jenson3210 Jenson3210 self-assigned this Jun 23, 2025
@Jenson3210 Jenson3210 added the bug Something isn't working label Jun 23, 2025
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jun 23, 2025
@Jenson3210 Jenson3210 moved this from In Progress to Ready to Review in OpenRewrite Jun 23, 2025
@Jenson3210
Copy link
Contributor Author

Do not merge this one without approval from @jkschneider

@Jenson3210 Jenson3210 requested a review from jkschneider June 23, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Ready to Review
Development

Successfully merging this pull request may close these issues.

1 participant