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

Make SuggestedFixes.updateAnnotationArgumentValues JDK 17-compatible #2820

Conversation

Stephan202
Copy link
Contributor

When running Java 17, AnnotationTree#toString() omits parentheses if
the annotation tree does not contain any arguments. With this change
#updateAnnotationArgumentValues no longer relies on the unconditional
presence of such parentheses.

When running Java 17, `AnnotationTree#toString()` omits parentheses if
the annotation tree does not contain any arguments. With this change
`#updateAnnotationArgumentValues` no longer relies on the unconditional
presence of such parentheses.
Comment on lines 1146 to 1147
'@'
+ annotation.getAnnotationType().toString()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

More correct would be to do state.getSourceForNode(annotation.getAnnotationType()), but this method currently does not accept a VisitorState. Let me know if you'd like me to make this change; it appears that all callers do have a VisitorState in scope. (Well, in the open source repository, at least.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix!

Adding passing in the VisitorState as a parameter and using state.getSourceForNode(annotation.getAnnotationType()) SGTM if you want to make that change, but this is a clear improvement as-is, so either way is OK with me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I added one more commit, though arguably the improvement is minimal. (But I can imagine that at some point TreeToString is extended to cover non-BugChecker classes, in which case this change would have to be made anyway.)

@Stephan202
Copy link
Contributor Author

Tests indicate that this issue applies to JDK 12+.

Comment on lines 1146 to 1147
'@'
+ annotation.getAnnotationType().toString()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix!

Adding passing in the VisitorState as a parameter and using state.getSourceForNode(annotation.getAnnotationType()) SGTM if you want to make that change, but this is a clear improvement as-is, so either way is OK with me.

@Stephan202 Stephan202 deleted the improvement/SuggestedFixes-updateAnnotationArgumentValues-jdk-17-compat branch January 10, 2022 19:35
@cushon
Copy link
Collaborator

cushon commented Jan 11, 2022

Sorry, I started merging the PR before your last commit, I'll import that separately

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.

None yet

2 participants