Conversation
… one When an element carries two nullability annotations that both migrate to the same JSpecify annotation -- such as `javax.annotation.Nullable` together with `javax.annotation.CheckForNull`, or annotations from two different frameworks -- the `ChangeType` steps each rewrite their own annotation, leaving the element annotated twice. Add a `RemoveDuplicateAnnotations` recipe that drops repeated annotations of the same type, and run it at the end of each `MigrateFrom*` recipe. Fixes #1199
The recipe is not specific to JSpecify: any many-to-one `ChangeType` mapping can leave an element annotated twice. It now lives in rewrite-static-analysis, next to `RemoveDuplicateConditions`, with an optional `annotationType` defaulting to any annotation and a guard for `@Repeatable` annotations. See openrewrite/rewrite-static-analysis#1000
Member
Author
|
Moved the recipe out to rewrite-static-analysis: openrewrite/rewrite-static-analysis#1000. It is not JSpecify-specific — any many-to-one Marked as draft: this PR is now just the six |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When an element carries two nullability annotations that both migrate to the same JSpecify annotation, each
ChangeTypestep rewrites its own annotation and the element ends up annotated twice:migrated to
@Nullable @Nullable String baz(fully qualified on the second one whenever the simple name could not be shortened, matching the output in the issue).This adds a
RemoveDuplicateAnnotationsrecipe that drops annotations repeated on the same element -- leading annotations on classes, methods and variables, annotations attached to modifiers, and type-use annotations on array types, nested types and type arguments -- keeping the first occurrence. It is run at the end of eachMigrateFrom*recipe, so it also covers duplicates that only appear once two differentMigrateFrom*recipes have both run.Only annotations that are semantically equal to an earlier one are removed, so distinct annotations such as
@Nullable @NonNullare left alone.