From 61c2f1b203c85860648cedf1f62ec523c876cad1 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Wed, 2 Jun 2021 17:19:05 +0300 Subject: [PATCH] Extract building JSR-305 settings to separate function --- .../JvmForeignAnnotationsConfigurator.kt | 5 +++-- .../load/java/JavaNullabilityAnnotationSettings.kt | 12 +++++++++++- .../org/jetbrains/kotlin/load/java/Jsr305Settings.kt | 8 +------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmForeignAnnotationsConfigurator.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmForeignAnnotationsConfigurator.kt index 6f331394842..80f91903e24 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmForeignAnnotationsConfigurator.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmForeignAnnotationsConfigurator.kt @@ -46,8 +46,9 @@ open class JvmForeignAnnotationsConfigurator(testServices: TestServices) : Envir get() = listOf(ForeignAnnotationsDirectives) override fun provideAdditionalAnalysisFlags(directives: RegisteredDirectives): Map, Any?> { - val globalState = directives.singleOrZeroValue(JSR305_GLOBAL_REPORT) ?: ReportLevel.WARN - val migrationState = directives.singleOrZeroValue(JSR305_MIGRATION_REPORT) + val defaultJsr305Settings = Jsr305Settings.DEFAULT + val globalState = directives.singleOrZeroValue(JSR305_GLOBAL_REPORT) ?: defaultJsr305Settings.globalLevel + val migrationState = directives.singleOrZeroValue(JSR305_MIGRATION_REPORT) ?: defaultJsr305Settings.migrationLevel val userAnnotationsState = directives[JSR305_SPECIAL_REPORT].mapNotNull { val (name, stateDescription) = it.split(":").takeIf { it.size == 2 } ?: return@mapNotNull null val state = ReportLevel.findByDescription(stateDescription) ?: return@mapNotNull null diff --git a/core/util.runtime/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt b/core/util.runtime/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt index 6093d21dda1..a73baf04f99 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt @@ -39,11 +39,21 @@ val nullabilityAnnotationSettings = mapOf( ), ) -val jsr305Settings = JavaNullabilityAnnotationsStatus( +private val jsr305Settings = JavaNullabilityAnnotationsStatus( reportLevelBefore = ReportLevel.WARN, sinceVersion = null ) +fun getDefaultJsr305Settings(): Jsr305Settings { + val globalReportLevel = if (jsr305Settings.sinceVersion != null && jsr305Settings.sinceVersion <= KotlinVersion.CURRENT) { + jsr305Settings.reportLevelAfter + } else { + jsr305Settings.reportLevelBefore + } + val migrationLevel = if (globalReportLevel == ReportLevel.WARN) null else globalReportLevel + return Jsr305Settings(globalReportLevel, migrationLevel) +} + fun getDefaultReportLevelForAnnotation(annotationFqName: FqName) = getReportLevelForAnnotation(annotationFqName, emptyMap()) fun getReportLevelForAnnotation(annotation: FqName, configuredReportLevels: Map): ReportLevel { diff --git a/core/util.runtime/src/org/jetbrains/kotlin/load/java/Jsr305Settings.kt b/core/util.runtime/src/org/jetbrains/kotlin/load/java/Jsr305Settings.kt index d58c2006809..aa2af4da3aa 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/load/java/Jsr305Settings.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/load/java/Jsr305Settings.kt @@ -13,13 +13,7 @@ data class Jsr305Settings( val userDefinedLevelForSpecificAnnotation: Map = emptyMap() ) { companion object { - val DEFAULT by lazy { - val reportLevelBefore = if (jsr305Settings.sinceVersion != null && jsr305Settings.sinceVersion <= KotlinVersion.CURRENT) { - jsr305Settings.reportLevelBefore - } else jsr305Settings.reportLevelAfter - - Jsr305Settings(reportLevelBefore, if (reportLevelBefore == ReportLevel.WARN) null else reportLevelBefore) - } + val DEFAULT = getDefaultJsr305Settings() } @OptIn(ExperimentalStdlibApi::class)