Move type-use annotations to array brackets during JSpecify migration#1038
Open
Move type-use annotations to array brackets during JSpecify migration#1038
Conversation
Move the recipe before ChangeType in each migration pipeline so it matches on the old annotation type (e.g. javax.annotation.*). This avoids incorrectly moving pre-existing JSpecify annotations where @nullable String[] intentionally means "array of nullable Strings."
…ected Verifies that a project with both javax annotations (to migrate) and pre-existing JSpecify @nullable String[] (meaning array of nullable elements) only migrates the javax annotations without touching the already-correct JSpecify annotations.
|
|
||
| String description = "When an annotation like `@Nullable` is applied to an array type in declaration position, " + | ||
| "this recipe moves it to the array brackets. " + | ||
| "For example, `@Nullable byte[]` becomes `byte @Nullable[]`. " + |
Contributor
There was a problem hiding this comment.
Is there the scenario to handle when the type of the elements in the array is a nested class? Pulled from the implementation below J.@Nullable Annotation[] is the ideal form, but do we need to consider if someone wrote @Nullable J.Annotation[], or would that just not compile to begin with?
Comment on lines
+98
to
+108
| List<J.Annotation> leading = ListUtils.map(mv.getLeadingAnnotations(), a -> { | ||
| if (match[0] == null && matchesType(a)) { | ||
| match[0] = a; | ||
| return null; | ||
| } | ||
| return a; | ||
| }); | ||
| if (leading == mv.getLeadingAnnotations()) { | ||
| return mv; | ||
| } | ||
| mv = mv.withLeadingAnnotations(leading); |
Contributor
There was a problem hiding this comment.
I suppose I'm trying to figure out if we have recipes that are going to be fragile in light of leading annotations being dropped and whether any of our recipes need to be adapted to handle the change in position for the annotations (have not had a chance to dig into this further yet)
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.
Summary
Fixes MigrateFromJavaxAnnotationApi does not modify annotations to the type level #934
Adds a new
MoveAnnotationToArrayTyperecipe that moves type-use annotations (e.g.@Nullable) from declaration position to the array brackets (e.g.@Nullable byte[]→byte @Nullable[]), as required by the JSpecify spec.Wires the recipe into all 6 JSpecify migration recipes in
jspecify.yml, running afterMoveFieldAnnotationToType.Handles method return types, method parameters, and field declarations.
Test plan
MoveAnnotationToArrayType: return types, parameters, fields, non-array no-ops, multi-dimensional arraysJSpecifyBestPracticesTestfor end-to-end javax → JSpecify migration with array types