Skip to content

RenameVariable: skip type-reference identifiers in method signatures and casts#7780

Merged
timtebeek merged 1 commit into
mainfrom
tim/fix-rename-variable-return-type
May 26, 2026
Merged

RenameVariable: skip type-reference identifiers in method signatures and casts#7780
timtebeek merged 1 commit into
mainfrom
tim/fix-rename-variable-return-type

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 26, 2026

Summary

Audited the other branches for similar gaps and added exclusions for the type-reference positions that demonstrably regressed: J.InstanceOf.getClazz(), J.ArrayType.getElementType(), J.Annotation.getAnnotationType(), and the J.ControlParentheses inside J.TypeCast. Each new exclusion is covered by a test that fails without the corresponding fix; positions where I couldn't reproduce a failure (e.g. J.AnnotatedType for simple identifiers, since type-use annotations get folded into J.Identifier.annotations) were left alone.

Test plan

  • ./gradlew :rewrite-java:test
  • ./gradlew :rewrite-java-test:test
  • New RenameVariableTest cases each fail before their fix and pass after

…and casts

`isVariableName` only excluded the method-name identifier on `J.MethodDeclaration`,
so a return-type identifier matching the variable name was renamed too — turning
`Foo create()` into `foo create()` when renaming a field `Foo`. Also extend the
audit to `J.InstanceOf`, `J.ArrayType`, `J.Annotation`, and the `J.ControlParentheses`
inside `J.TypeCast`, each demonstrated by a failing test.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 26, 2026
@timtebeek timtebeek merged commit 82a80d6 into main May 26, 2026
1 check passed
@timtebeek timtebeek deleted the tim/fix-rename-variable-return-type branch May 26, 2026 10:20
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 26, 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.

1 participant