FIR: use JSR-305 state from command line flags

This commit is contained in:
pyos
2021-08-19 17:17:03 +02:00
committed by teamcityserver
parent bff4b8639b
commit 24210aacc8
19 changed files with 26 additions and 376 deletions
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.session
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.config.JvmAnalysisFlags
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.analysis.CheckersComponent
@@ -35,7 +36,6 @@ import org.jetbrains.kotlin.fir.resolve.transformers.plugin.GeneratedClassIndex
import org.jetbrains.kotlin.fir.scopes.impl.FirDeclaredMemberScopeProvider
import org.jetbrains.kotlin.fir.types.FirCorrespondingSupertypesCache
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.load.java.JavaTypeEnhancementState
// -------------------------- Required components --------------------------
@@ -63,7 +63,8 @@ fun FirSession.registerCliCompilerOnlyComponents() {
@OptIn(SessionConfiguration::class)
fun FirSession.registerCommonJavaComponents() {
register(FirJavaTypeEnhancementStateComponent::class, FirJavaTypeEnhancementStateComponent(JavaTypeEnhancementState.DEFAULT))
val jsr305State = languageVersionSettings.getFlag(JvmAnalysisFlags.javaTypeEnhancementState)
register(FirJavaTypeEnhancementStateComponent::class, FirJavaTypeEnhancementStateComponent(jsr305State))
}
// -------------------------- Resolve components --------------------------
@@ -135,8 +135,8 @@ object FirSessionFactory {
sessionProvider.registerSession(moduleData, this@session)
registerModuleData(moduleData)
registerCliCompilerOnlyComponents()
registerCommonJavaComponents()
registerCommonComponents(languageVersionSettings)
registerCommonJavaComponents()
registerResolveComponents(lookupTracker)
registerJavaSpecificResolveComponents()
@@ -1,33 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: ignore
// FILE: A.java
import javax.annotation.*;
@ParametersAreNonnullByDefault
public class A {
@Nullable public String field = null;
public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) {
return "";
}
@Nonnull
public String bar() {
return "";
}
}
// FILE: main.kt
fun main(a: A) {
// foo is platform
a.foo("", "", null)?.length
a.foo("", "", null).length
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, <!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
a.bar().length
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.field?.length
a.field<!UNSAFE_CALL!>.<!>length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: ignore
@@ -1,92 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: strict
// FILE: spr/NonNullApi.java
package spr;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
public @interface NonNullApi {
}
// FILE: spr/UnknownNullability.java
package spr;
import javax.annotation.*;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.annotation.meta.TypeQualifierNickname;
import javax.annotation.meta.When;
@Documented
@TypeQualifierNickname
@Nonnull(when = When.UNKNOWN)
@Retention(RetentionPolicy.RUNTIME)
public @interface UnknownNullability {
}
// FILE: spr/ForceFlexibility.java
package spr;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import javax.annotation.meta.When;
@Retention(RetentionPolicy.RUNTIME)
@Documented
@UnknownNullability
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
public @interface ForceFlexibility {
}
// FILE: B.java
public interface B {
public void foo(@javax.annotation.Nonnull String x);
public void bar(@javax.annotation.Nonnull String x);
public void baz(@javax.annotation.Nonnull String x);
public void foobar(@javax.annotation.Nonnull String x);
}
// FILE: A.java
import spr.*;
@NonNullApi
public class A implements B {
@ForceFlexibility
public void foo(String x) {}
public void bar(@ForceFlexibility String x) {}
public void baz(@UnknownNullability String x) {}
public void foobar(@javax.annotation.Nonnull(when = javax.annotation.meta.When.UNKNOWN) String x) {}
}
// FILE: main.kt
fun main(a: A, b: B) {
b.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>)
b.bar(<!NULL_FOR_NONNULL_TYPE!>null<!>)
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)
b.foobar(<!NULL_FOR_NONNULL_TYPE!>null<!>)
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>)
a.bar(<!NULL_FOR_NONNULL_TYPE!>null<!>)
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)
a.foobar(null)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: strict
@@ -1,152 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: strict
// FILE: NonNullApi.java
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
public @interface NonNullApi {
}
// FILE: NullableApi.java
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.annotation.CheckForNull;
import javax.annotation.meta.TypeQualifierDefault;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@CheckForNull
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
public @interface NullableApi {
}
// FILE: A.java
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;
@NonNullApi
public class A {
public String foo1(String x) { return ""; }
public String foo2(String x) { return ""; }
public String foo3(String x) { return ""; }
@Nullable
public String bar1(@Nullable String x) { return ""; }
@Nullable
public String bar2(@Nullable String x) { return ""; }
public String baz(@Nonnull String x) { return ""; }
}
// FILE: AInt.java
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;
@NonNullApi
public interface AInt {
public CharSequence foo1(String x);
public CharSequence foo2(String x);
public CharSequence foo3(String x);
@Nullable
public CharSequence bar1(@Nullable String x);
@Nullable
public CharSequence bar2(@Nullable String x);
public CharSequence baz(@Nonnull String x);
}
// FILE: B.java
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;
@NullableApi
public class B extends A implements AInt {
// conflicts
public String foo1(String x) { return ""; }
// no conflicts
@Nonnull
public String foo2(@Nonnull String x) { return ""; }
// fake override for foo3 shouldn't have any conflicts
// no conflicts
public String bar1(String x) { return ""; }
// conflicts
public String baz(String x) { return ""; }
}
// FILE: C.java
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;
@NonNullApi
public class C extends A implements AInt {
// no conflicts
public String foo1(String x) { return ""; }
// no conflicts
public String foo2(@Nonnull String x) { return ""; }
// fake override for foo3 shouldn't have any conflicts
// no conflicts, covariant override
public String bar1(String x) { return ""; }
// no conflicts
@Nullable
public String bar2(@Nullable String x) { return ""; }
// no conflicts
public String baz(String x) { return ""; }
}
// FILE: main.kt
fun main(a: A, b: B, c: C) {
a.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
a.foo3(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
a.bar1(null)<!UNSAFE_CALL!>.<!>length
a.bar2(null)<!UNSAFE_CALL!>.<!>length
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
b.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
b.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNNECESSARY_SAFE_CALL!>?.<!>length
b.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
b.foo3(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
b.bar1(null)<!UNSAFE_CALL!>.<!>length
b.bar2(null)<!UNSAFE_CALL!>.<!>length
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNNECESSARY_SAFE_CALL!>?.<!>length
c.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
c.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
c.foo3(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
c.bar1(null)<!UNSAFE_CALL!>.<!>length
c.bar1(null)?.length
c.bar2(null)<!UNSAFE_CALL!>.<!>length
c.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: strict
@@ -44,12 +44,12 @@ fun main(a: A) {
a.field<!UNSAFE_CALL!>.<!>length
a.foo2("", null)?.length
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
a.foo2("", null).length
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
a.bar2().length
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.field2?.length
a.field2<!UNSAFE_CALL!>.<!>length
a.field2.length
}
@@ -34,14 +34,14 @@ public class A {
// 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.foo("", null).length
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
a.bar().length
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.field?.length
a.field<!UNSAFE_CALL!>.<!>length
a.field.length
a.foo2("", null)?.length
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
@@ -63,10 +63,10 @@ fun main(a: A) {
a.foo2("", null)?.length
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
a.foo2(null, "")<!UNSAFE_CALL!>.<!>length
a.bar2().length
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.bar2()!!.length
a.field2?.length
a.field2<!UNSAFE_CALL!>.<!>length
@@ -34,14 +34,14 @@ public class A {
// 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.foo("", null).length
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
a.bar().length
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.field?.length
a.field<!UNSAFE_CALL!>.<!>length
a.field.length
a.foo2("", null)?.length
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
@@ -44,12 +44,12 @@ fun main(a: A) {
a.field<!UNSAFE_CALL!>.<!>length
a.foo2("", null)?.length
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
a.foo2("", null).length
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
a.bar2().length
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.field2?.length
a.field2<!UNSAFE_CALL!>.<!>length
a.field2.length
}
@@ -1,35 +0,0 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: ignore
// JSR305_MIGRATION_REPORT: ignore
// JSR305_SPECIAL_REPORT: MyNonnull:warn, MyMigrationNonnull:strict
// FILE: A.java
import javax.annotation.*;
public class A {
@MyMigrationNullable public String field = null;
@MyMigrationNullable
public String foo(@MyMigrationNonnull String x, CharSequence y) {
return "";
}
@MyNonnull
@MyMigrationNonnull
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
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: ignore
// JSR305_MIGRATION_REPORT: ignore
@@ -44,12 +44,12 @@ fun main(a: A) {
a.field<!UNSAFE_CALL!>.<!>length
a.foo2("", null)?.length
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
a.foo2("", null).length
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
a.bar2().length
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.field2?.length
a.field2<!UNSAFE_CALL!>.<!>length
a.field2.length
}
@@ -1 +0,0 @@
INCONSISTENT_DIAGNOSTICS
@@ -1,43 +0,0 @@
// NULLABILITY_ANNOTATIONS: @io.reactivex.rxjava3.annotations:ignore
// FILE: A.java
import io.reactivex.rxjava3.annotations.*;
public class A<T> {
@Nullable public String field = null;
@Nullable
public String foo(@NonNull String x, @Nullable CharSequence y) {
return "";
}
@NonNull
public String bar() {
return "";
}
@Nullable
public T baz(@NonNull T x) { return x; }
}
// FILE: main.kt
fun main(a: A<String>, a1: A<String?>) {
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
a.baz("")<!UNSAFE_CALL!>.<!>length
a.baz("")?.length
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
a1.baz("")!!.length
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// NULLABILITY_ANNOTATIONS: @io.reactivex.rxjava3.annotations:ignore
// FILE: A.java