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

Prevent SuggestedFixes#renameMethod from modifying return type declaration #4043

Closed

Conversation

oxkitsune
Copy link
Contributor

By ensuring the return type IDENTIFIER token is not matched.

.addOutputLines(
"Test.java",
"class Test {",
" private Object object() {",
Copy link
Contributor

Choose a reason for hiding this comment

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

For other reviewers: before this fix Error Prone would suggest:

Suggested change
" private Object object() {",
" private object Object() {",

for (ErrorProneToken token : methodTokens) {
if (token.kind() == TokenKind.IDENTIFIER && token.name().equals(tree.getName())) {
if (token.kind() == TokenKind.IDENTIFIER
&& token.pos() > returnTypeEndPos
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of checking the token positions here, I think we might be able to adjust basePos earlier and only tokenize from after the return type. Do you see any issues with that approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good catch thanks! Will push a commit.

copybara-service bot pushed a commit that referenced this pull request Aug 10, 2023
…aration

By ensuring the return type `IDENTIFIER` token is not matched.

Fixes #4043

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4043 from PicnicSupermarket:gdejong/bug-method-name cbfbc54
PiperOrigin-RevId: 555232503
@Stephan202 Stephan202 deleted the gdejong/bug-method-name branch August 10, 2023 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants