Recognize Checker Framework declaration annotations.
We are migrating Guava to use these annotations rather than jsr305's @Nullable. We can't use the Checker Framework's _@Nullable_ yet because we promise compatibility with Java 7, which doesn't support type annotations. This is related to but distinct from https://youtrack.jetbrains.com/issue/KT-21408, which is about a different jsr305 annotation we use, @ParametersAreNonnullByDefault. I've also updated some docs to mention Kotlin's existing support for the Checker Framework _@NonNull_.
This commit is contained in:
committed by
Alexander Udalov
parent
79359b7bc2
commit
ac87ad422d
@@ -0,0 +1,33 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// FILE: A.java
|
||||
|
||||
import org.checkerframework.checker.nullness.compatqual.*;
|
||||
|
||||
public class A {
|
||||
@NullableDecl public String field = null;
|
||||
|
||||
@NullableDecl
|
||||
public String foo(@NonNullDecl String x, @NullableDecl CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNullDecl
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
public fun main(/*0*/ a: A): kotlin.Unit
|
||||
|
||||
public open class A {
|
||||
public constructor A()
|
||||
@org.checkerframework.checker.nullness.compatqual.NullableDecl public final var field: kotlin.String?
|
||||
@org.checkerframework.checker.nullness.compatqual.NonNullDecl public open fun bar(): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@org.checkerframework.checker.nullness.compatqual.NullableDecl public open fun foo(/*0*/ @org.checkerframework.checker.nullness.compatqual.NonNullDecl x: kotlin.String, /*1*/ @org.checkerframework.checker.nullness.compatqual.NullableDecl y: kotlin.CharSequence?): kotlin.String?
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user