-
Notifications
You must be signed in to change notification settings - Fork 329
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
#2838 standardize nullability annotations #3084
#2838 standardize nullability annotations #3084
Conversation
AlexanderSkrock
commented
Apr 3, 2023
•
edited by timtebeek
Loading
edited by timtebeek
- Fixes Standardize nullability annotations #2838
… nullability annotations
Includes first example for javax annotations
As long we are not able to use Java 9's Set#of, I'll use stream api's set collector.
To prevent cyclic dependencies we have to split them. This way, we do not need dependencies on gradle and maven within rewrite-java.
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 will also ask @sambsnyd to weigh in with his view on this.
rewrite-gradle/src/main/resources/META-INF/rewrite/nullability.yml
Outdated
Show resolved
Hide resolved
...ite-gradle/src/test/java/org/openrewrite/gradle/java/UseJavaxNullabilityAnnotationsTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/StandardizeNullabilityAnnotations.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/StandardizeNullabilityAnnotations.java
Outdated
Show resolved
Hide resolved
rewrite-maven/src/main/resources/META-INF/rewrite/nullability.yml
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/StandardizeNullabilityAnnotations.java
Outdated
Show resolved
Hide resolved
rewrite-maven/src/test/java/org/openrewrite/maven/java/UseJavaxNullabilityAnnotationsTest.java
Outdated
Show resolved
Hide resolved
rewrite-java-test/src/test/java/org/openrewrite/java/StandardizeNullabilityAnnotationsTest.java
Outdated
Show resolved
Hide resolved
We can bring those back, when there is a global AddDependency recipe which is independent of the used dependency management system. Then, we can define those recipes within rewrite-java without additional effort for maintaining Maven, Gradle etc.
This annotation is already defined at package level.
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.
Looks useful to me. Thanks!
…ility annotations
Between holidays, I had time to think about this recipe and committed a work in progress version. In my opinion, we can solve the standardization issue even better this way. Would be more flexible and robust. What do you think about this approach, @knutwannheden and @sambsnyd ? Anyways, I you prefer the original approach, I will roll back to the last commit before the overhaul and simply add your proposed testcase and nullability annotation. Otherwise I would continue implementing the |
…endency on test scope only
This simplifies testing whether an annotation covers identical scopes. Also, not all element types would make sense as scopes.
rewrite-java/src/main/resources/META-INF/rewrite/nullability.yml
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/resources/META-INF/rewrite/nullability.yml
Outdated
Show resolved
Hide resolved
Co-authored-by: Tim te Beek <timtebeek@gmail.com>
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.
Apart from the last remark by Tim I think this PR is good to go.
There is actually one case which isn't addressed yet. The Java language for some reason allows annotations to appear in-between modifiers. So it is actually allowed to have a class like this: class Test {
private
@Nonnull
final
String variable = "";
} In OpenRewrite the LST is also a bit unusual in this case. There is a |
Oh, I overlooked that one! Yeah, I could implement it within Edit: I added a few test cases about afore discussed problems with this commit.
Last, but not least, for the first and second bullet, I would propose we define inserting annotations in front (e. g. for |
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum KnownNullabilityAnnotations implements NullabilityAnnotation { |
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.
FWIW, I found another source with common nullness annotations: The annotations supported by the Kotlin compiler.
For
In the JLS there is this remark:
So, either we could try to replace the annotations exactly in the same place as they were declared (but as previously discussed, this is currently not as easy as one would like it to be) or we could instead just always add the new annotations as leading annotations (all of the previously mentioned types also declare a |
If the recipe moves the strangely-placed annotations in-place that is fine, this recipe's purpose will have been accomplished. |
Just for your information. Currently I got some private issues and I try spend as much as time as possible with my family to make it through this period. Also, I am not sure, when I will be able to continue my work on this pull request. I am sorry! As mentioned earlier, I collected the remaning issues and wrote, currently disabled, testcases for those. If any of you got capacities, feel free to finish the implementation. Kind regards, |
@AlexanderSkrock Thanks for the heads-up and I wish you and your family all the best 🍀 Since the PR is nearly done, I think we will try to finish it. Thank you again for all the work you put into it! |
With JSpecify coming out we've done a write up of our migration from internal annotations to JSpecify: |
FYI: There's now a parallel effort in |
With the release of JSpecify we've created separate recipes in rewrite-migrate-java to migrate from various other libraries to JSpecify: https://docs.openrewrite.org/recipes/java/jspecify/migratetojspecify I propose we close this effort, and pull over anything that's still applicable to rewrite-migrate-java instead. Thanks again @AlexanderSkrock ! |