K1/K2: support org.jspecify.annotations.NonNull in Java interop
#KT-62352 Fixed
This commit is contained in:
committed by
Space Team
parent
dcbc1e6a04
commit
1eacd5efc2
+12
@@ -684,6 +684,12 @@ public class FirPsiOldFrontendForeignAnnotationsCompiledJavaTestGenerated extend
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
@@ -796,6 +802,12 @@ public class FirPsiOldFrontendForeignAnnotationsCompiledJavaTestGenerated extend
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
|
||||
+12
@@ -742,6 +742,12 @@ public class FirPsiOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingT
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
@@ -854,6 +860,12 @@ public class FirPsiOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingT
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
|
||||
+12
@@ -742,6 +742,12 @@ public class FirPsiOldFrontendForeignAnnotationsSourceJavaTestGenerated extends
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
@@ -854,6 +860,12 @@ public class FirPsiOldFrontendForeignAnnotationsSourceJavaTestGenerated extends
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// FIR_IDENTICAL
|
||||
// JSPECIFY_STATE: strict
|
||||
|
||||
// FILE: SomeJavaClass.java
|
||||
|
||||
import org.jspecify.annotations.*;
|
||||
|
||||
public class SomeJavaClass {
|
||||
@NonNull
|
||||
public String foo() { return ""; }
|
||||
|
||||
@Nullable
|
||||
public String bar() { return ""; }
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class DerivedNullable : SomeJavaClass() {
|
||||
// jspecify_nullness_mismatch
|
||||
override fun foo(): <!RETURN_TYPE_MISMATCH_ON_OVERRIDE!>String?<!> { return null }
|
||||
|
||||
override fun bar(): String? { return null }
|
||||
}
|
||||
|
||||
class DerivedNonNull : SomeJavaClass() {
|
||||
override fun foo(): String { return "" }
|
||||
|
||||
override fun bar(): String { return "" }
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// FIR_IDENTICAL
|
||||
// JSPECIFY_STATE: warn
|
||||
|
||||
// FILE: SomeJavaClass.java
|
||||
|
||||
import org.jspecify.annotations.*;
|
||||
|
||||
public class SomeJavaClass {
|
||||
@NonNull
|
||||
public String foo() { return ""; }
|
||||
|
||||
@Nullable
|
||||
public String bar() { return ""; }
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class DerivedNullable : SomeJavaClass() {
|
||||
<!WRONG_NULLABILITY_FOR_JAVA_OVERRIDE!>override<!> fun foo(): String? { return null }
|
||||
|
||||
override fun bar(): String? { return null }
|
||||
}
|
||||
|
||||
class DerivedNonNull : SomeJavaClass() {
|
||||
override fun foo(): String { return "" }
|
||||
|
||||
override fun bar(): String { return "" }
|
||||
}
|
||||
+12
@@ -684,6 +684,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
@@ -796,6 +802,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
|
||||
+12
@@ -742,6 +742,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
@@ -854,6 +860,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
|
||||
+12
@@ -742,6 +742,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
@@ -854,6 +860,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DerivedAsNullableOrNotNull.kt")
|
||||
public void testDerivedAsNullableOrNotNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/DerivedAsNullableOrNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IgnoreAnnotations.kt")
|
||||
public void testIgnoreAnnotations() throws Exception {
|
||||
|
||||
+1
@@ -185,6 +185,7 @@ abstract class AbstractAnnotationTypeQualifierResolver<TAnnotation : Any>(
|
||||
in NULLABLE_ANNOTATIONS -> NullabilityQualifier.NULLABLE
|
||||
in NOT_NULL_ANNOTATIONS -> NullabilityQualifier.NOT_NULL
|
||||
JSPECIFY_OLD_NULLABLE, JSPECIFY_NULLABLE -> NullabilityQualifier.NULLABLE
|
||||
JSPECIFY_NON_NULL -> NullabilityQualifier.NOT_NULL
|
||||
JSPECIFY_OLD_NULLNESS_UNKNOWN, JSPECIFY_NULLNESS_UNKNOWN -> NullabilityQualifier.FORCE_FLEXIBILITY
|
||||
JAVAX_NONNULL_ANNOTATION ->
|
||||
when (annotation.enumArguments(onlyValue = false).firstOrNull()) {
|
||||
|
||||
@@ -25,6 +25,7 @@ val JSPECIFY_OLD_NULL_MARKED = FqName("org.jspecify.nullness.NullMarked")
|
||||
val JSPECIFY_NULLABLE = FqName("org.jspecify.annotations.Nullable")
|
||||
val JSPECIFY_NULLNESS_UNKNOWN = FqName("org.jspecify.annotations.NullnessUnspecified")
|
||||
val JSPECIFY_NULL_MARKED = FqName("org.jspecify.annotations.NullMarked")
|
||||
val JSPECIFY_NON_NULL = FqName("org.jspecify.annotations.NonNull")
|
||||
|
||||
val NULLABLE_ANNOTATIONS = listOf(
|
||||
JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION,
|
||||
|
||||
Reference in New Issue
Block a user