Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add recipe to replace Annotation #4217
Add recipe to replace Annotation #4217
Changes from 1 commit
f37beec
5577a22
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense with an example that includes a parameter, to make it clear that this is supported. Additionally, since a parameter could require a reference to a Java class, I think it would make sense for the JavaTemplate here to be required to be fully context-free and thus not rely on any imports being registered with the JavaTemplate. As a result I imagine the
annotationFQN
parameter can be dropped (didn't look at the code). Then we can apply theShortenFullyQualifiedNames
visitor to get imports added.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried executing
ShortenFullyQualifiedNames
withdoAfterVisit(new ShortenFullyQualifiedTypeReferences().getVisitor());
earlier, but this didn't make the expected changes. I'll try again and post a gist if not working.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC the class declares a static utility method. We should find some uses of it in rewrite-static-analysis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
ShortenFullyQualifiedTypeReferences#modifyOnly
the recipe looks better now, thanks. But now the tests are failing becauseShortenFullyQualifiedTypeReferences
handles annotations unexpected.It seems to only shorten Annotations of the pattern ´packagename.@annotation´ (see
ShortenFullyQualifiedTypeReferencesTest#typeFullyQualifiedAnnotatedField
andShortenFullyQualifiedTypeReferencesTest#annotatedFieldAccess
).In the
ShortenFullyQualifiedTypeReferences
fails if the annotation has the pattern@packagename.TypeName
According to the Java Language Spec 9.7.1 Annotations in FQN format have the pattern
@packagename.TypeName
.I think there might be a bug in
ShortenFullyQualifiedTypeReferences
or am I missing something?See https://gist.github.com/MBoegers/9c805b9caa35144466d9f380ddbb40bd for a reproducing test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite possible that we have a bug there. I will try to investigate next week.