Depend on passed language version explicitly to compute nullability annotation settings

This commit is contained in:
Victor Petukhov
2021-06-11 10:25:29 +03:00
parent 18384788a4
commit a82772f31a
16 changed files with 102 additions and 47 deletions
@@ -44,17 +44,18 @@ val nullabilityAnnotationSettings = mapOf(
),
)
private val jsr305Settings = JavaNullabilityAnnotationsStatus(
private val JSR_305_DEFAULT_SETTINGS = JavaNullabilityAnnotationsStatus(
reportLevelBefore = ReportLevel.WARN,
sinceVersion = null
)
fun getDefaultJsr305Settings(): Jsr305Settings {
val globalReportLevel = if (jsr305Settings.sinceVersion != null && jsr305Settings.sinceVersion <= KotlinVersion.CURRENT) {
jsr305Settings.reportLevelAfter
} else {
jsr305Settings.reportLevelBefore
}
fun getDefaultJsr305Settings(configuredKotlinVersion: KotlinVersion = KotlinVersion.CURRENT): Jsr305Settings {
val globalReportLevel =
if (JSR_305_DEFAULT_SETTINGS.sinceVersion != null && JSR_305_DEFAULT_SETTINGS.sinceVersion <= configuredKotlinVersion) {
JSR_305_DEFAULT_SETTINGS.reportLevelAfter
} else {
JSR_305_DEFAULT_SETTINGS.reportLevelBefore
}
val migrationLevel = getDefaultMigrationJsr305ReportLevelForGivenGlobal(globalReportLevel)
return Jsr305Settings(globalReportLevel, migrationLevel)
}
@@ -64,12 +65,15 @@ fun getDefaultMigrationJsr305ReportLevelForGivenGlobal(globalReportLevel: Report
fun getDefaultReportLevelForAnnotation(annotationFqName: FqName) = getReportLevelForAnnotation(annotationFqName, emptyMap())
fun getReportLevelForAnnotation(annotation: FqName, configuredReportLevels: Map<FqName, ReportLevel>): ReportLevel {
fun getReportLevelForAnnotation(
annotation: FqName, configuredReportLevels: Map<FqName, ReportLevel>,
configuredKotlinVersion: KotlinVersion = KotlinVersion.CURRENT
): ReportLevel {
annotation.findValueForMostSpecificFqname(configuredReportLevels)?.let { return it }
val defaultReportLevel = annotation.findValueForMostSpecificFqname(nullabilityAnnotationSettings) ?: return ReportLevel.IGNORE
return if (defaultReportLevel.sinceVersion != null && defaultReportLevel.sinceVersion <= KotlinVersion.CURRENT) {
return if (defaultReportLevel.sinceVersion != null && defaultReportLevel.sinceVersion <= configuredKotlinVersion) {
defaultReportLevel.reportLevelAfter
} else {
defaultReportLevel.reportLevelBefore
@@ -8,12 +8,12 @@ package org.jetbrains.kotlin.load.java
import org.jetbrains.kotlin.name.FqName
class JavaTypeEnhancementState(
val jsr305: Jsr305Settings = Jsr305Settings.DEFAULT,
val getReportLevelForAnnotation: (FqName) -> ReportLevel = ::getDefaultReportLevelForAnnotation
val jsr305: Jsr305Settings,
val getReportLevelForAnnotation: (FqName) -> ReportLevel
) {
val disabledDefaultAnnotations = jsr305.isDisabled || getReportLevelForAnnotation(JSPECIFY_ANNOTATIONS_PACKAGE) == ReportLevel.IGNORE
companion object {
val DEFAULT = JavaTypeEnhancementState()
val DEFAULT = JavaTypeEnhancementState(getDefaultJsr305Settings(), ::getDefaultReportLevelForAnnotation)
}
}
@@ -12,10 +12,6 @@ data class Jsr305Settings(
val migrationLevel: ReportLevel? = null,
val userDefinedLevelForSpecificAnnotation: Map<FqName, ReportLevel> = emptyMap()
) {
companion object {
val DEFAULT = getDefaultJsr305Settings()
}
@OptIn(ExperimentalStdlibApi::class)
val description by lazy {
buildList {