Skip to content

Commit

Permalink
Migrate to JSpecify (openrewrite#4415)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider authored Aug 14, 2024
1 parent 9a10769 commit e22f9c6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
2 changes: 2 additions & 0 deletions rewrite-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies {
api("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation("net.java.dev.jna:jna-platform:latest.release")

implementation("org.jspecify:jspecify:latest.release")

// Pinning okhttp while waiting on 5.0.0
// https://github.com/openrewrite/rewrite/issues/1479
compileOnly("com.squareup.okhttp3:okhttp:4.9.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
* @see NonNullApi
* @see NonNullFields
* @see Nullable
* @deprecated Use {@link org.jspecify.annotations.NonNull} instead.
*/
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.TYPE, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull
@TypeQualifierNickname
@Deprecated
public @interface NonNull {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@
*/
package org.openrewrite.internal.lang;

import javax.annotation.Nonnull;
import org.jspecify.annotations.NullMarked;

import javax.annotation.meta.TypeQualifierDefault;
import java.lang.annotation.*;

/**
* A common annotation to declare that parameters and return values
* are to be considered as non-nullable by default for a given package.
* <p>Leverages JSR-305 meta-annotations to indicate nullability in Java to common
* tools with JSR-305 support and used by Kotlin to infer nullability of the API.
* <p>Leverages JSpecify meta-annotations to indicate nullability in Java to common
* tools with JSpecify support and used by Kotlin to infer nullability of the API.
* <p>Should be used at package level in association with {@link Nullable}
* annotations at parameter and return value level.
*
* @see NonNullFields
* @see Nullable
* @see NonNull
* @deprecated Use {@link org.jspecify.annotations.NullMarked} instead.
*/
@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull
@NullMarked
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
@Deprecated
public @interface NonNullApi {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,25 @@
*/
package org.openrewrite.internal.lang;

import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import java.lang.annotation.*;

/**
* A common annotation to declare that fields are to be considered as
* non-nullable by default for a given package.
* <p>Leverages JSR-305 meta-annotations to indicate nullability in Java to common
* tools with JSR-305 support and used by Kotlin to infer nullability of the API.
* <p>Should be used at package level in association with {@link Nullable}
* <p>Leverages JSpecify meta-annotations to indicate nullability in Java to common
* tools with JSpecify support and used by Kotlin to infer nullability of the API.
* <p>Should be used at package level in association with {@link org.jspecify.annotations.Nullable}
* annotations at field level.
*
* @see NonNullFields
* @see Nullable
* @see NonNull
* @see org.jspecify.annotations.NonNull
* @see org.jspecify.annotations.Nullable
*/
@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull
@org.jspecify.annotations.NonNull
@TypeQualifierDefault(ElementType.FIELD)
public @interface NonNullFields {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
/**
* A common annotation to declare that fields are to be considered as
* non-nullable by default for a given package.
* <p>Leverages JSR-305 meta-annotations to indicate nullability in Java to common
* tools with JSR-305 support and used by Kotlin to infer nullability of the API.
* <p>Leverages JSpecify meta-annotations to indicate nullability in Java to common
* tools with JSpecify support and used by Kotlin to infer nullability of the API.
* <p>Should be used at package level in association with {@link Nullable}
* annotations at field level.
*
* @see NullFields
* @see Nullable
* @see NonNull
* @see org.jspecify.annotations.Nullable
* @see org.jspecify.annotations.NonNull
*/
@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@javax.annotation.Nullable
@org.jspecify.annotations.Nullable
@TypeQualifierDefault(ElementType.FIELD)
public @interface NullFields {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/
package org.openrewrite.internal.lang;

import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierNickname;
import javax.annotation.meta.When;
import java.lang.annotation.*;

/**
Expand All @@ -32,11 +30,13 @@
* @see NonNullApi
* @see NonNullFields
* @see NonNull
* @deprecated Use {@link org.jspecify.annotations.Nullable} instead.
*/
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull(when = When.MAYBE)
@org.jspecify.annotations.Nullable
@TypeQualifierNickname
@Deprecated
public @interface Nullable {
}

0 comments on commit e22f9c6

Please sign in to comment.