Skip to content

InlineMethodCalls: preserve method select when replacement is bare#7551

Merged
timtebeek merged 1 commit intomainfrom
tim/inline-keep-select
May 3, 2026
Merged

InlineMethodCalls: preserve method select when replacement is bare#7551
timtebeek merged 1 commit intomainfrom
tim/inline-keep-select

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 3, 2026

Summary

When the original invocation has a select (e.g. red.getTotalHits()) and the replacement template is a bare method call (e.g. getTotalHitsCount()), the select was being dropped, producing getTotalHitsCount() instead of red.getTotalHitsCount(). This change detects that case and prepends #{this:any()}. to the template so the original receiver is preserved.

Test plan

  • New test preserveSelectWhenReplacementIsBareMethodCall covers the bug case
  • All 12 existing InlineMethodCallsTest tests still pass

When the original invocation has a select (`red.getTotalHits()`) and
the replacement template is a bare method call (`getTotalHitsCount()`),
prepend the select so the result is `red.getTotalHitsCount()` instead
of dropping the receiver.

Fixes #7549
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 3, 2026
@timtebeek timtebeek merged commit bd95250 into main May 3, 2026
1 check failed
@timtebeek timtebeek deleted the tim/inline-keep-select branch May 3, 2026 14:06
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 3, 2026
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.

Inline method calls should keep method select if required

1 participant