Move type enhancement state stuff into core:descriptors.jvm

This commit is contained in:
Victor Petukhov
2021-06-04 15:29:18 +03:00
parent 8de05691a9
commit 18384788a4
8 changed files with 20 additions and 31 deletions
@@ -1,79 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.load.java
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.findValueForMostSpecificFqname
val JSPECIFY_ANNOTATIONS_PACKAGE = FqName("org.jspecify.nullness")
val CHECKER_FRAMEWORK_COMPATQUAL_ANNOTATIONS_PACKAGE = FqName("org.checkerframework.checker.nullness.compatqual")
val nullabilityAnnotationSettings = mapOf(
FqName("org.jetbrains.annotations") to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("androidx.annotation") to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("android.support.annotation") to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("android.annotation") to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("com.android.annotations") to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("org.eclipse.jdt.annotation") to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("org.checkerframework.checker.nullness.qual") to JavaNullabilityAnnotationsStatus.DEFAULT,
CHECKER_FRAMEWORK_COMPATQUAL_ANNOTATIONS_PACKAGE to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("javax.annotation") to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("edu.umd.cs.findbugs.annotations") to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("io.reactivex.annotations") to JavaNullabilityAnnotationsStatus.DEFAULT,
FqName("androidx.annotation.RecentlyNullable") to JavaNullabilityAnnotationsStatus(
reportLevelBefore = ReportLevel.WARN,
sinceVersion = null
),
FqName("androidx.annotation.RecentlyNonNull") to JavaNullabilityAnnotationsStatus(
reportLevelBefore = ReportLevel.WARN,
sinceVersion = null
),
FqName("lombok") to JavaNullabilityAnnotationsStatus.DEFAULT,
JSPECIFY_ANNOTATIONS_PACKAGE to JavaNullabilityAnnotationsStatus(
reportLevelBefore = ReportLevel.WARN,
sinceVersion = KotlinVersion(1, 6),
reportLevelAfter = ReportLevel.STRICT
),
FqName("io.reactivex.rxjava3.annotations") to JavaNullabilityAnnotationsStatus(
reportLevelBefore = ReportLevel.WARN,
sinceVersion = KotlinVersion(1, 7),
reportLevelAfter = ReportLevel.STRICT
),
)
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 = getDefaultMigrationJsr305ReportLevelForGivenGlobal(globalReportLevel)
return Jsr305Settings(globalReportLevel, migrationLevel)
}
fun getDefaultMigrationJsr305ReportLevelForGivenGlobal(globalReportLevel: ReportLevel) =
if (globalReportLevel == ReportLevel.WARN) null else globalReportLevel
fun getDefaultReportLevelForAnnotation(annotationFqName: FqName) = getReportLevelForAnnotation(annotationFqName, emptyMap())
fun getReportLevelForAnnotation(annotation: FqName, configuredReportLevels: Map<FqName, ReportLevel>): ReportLevel {
annotation.findValueForMostSpecificFqname(configuredReportLevels)?.let { return it }
val defaultReportLevel = annotation.findValueForMostSpecificFqname(nullabilityAnnotationSettings) ?: return ReportLevel.IGNORE
return if (defaultReportLevel.sinceVersion != null && defaultReportLevel.sinceVersion <= KotlinVersion.CURRENT) {
defaultReportLevel.reportLevelAfter
} else {
defaultReportLevel.reportLevelBefore
}
}
@@ -1,16 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.load.java
data class JavaNullabilityAnnotationsStatus(
val reportLevelBefore: ReportLevel,
val sinceVersion: KotlinVersion? = KotlinVersion(1, 0),
val reportLevelAfter: ReportLevel = reportLevelBefore,
) {
companion object {
val DEFAULT = JavaNullabilityAnnotationsStatus(ReportLevel.STRICT)
}
}
@@ -1,30 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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 disabledDefaultAnnotations = jsr305.isDisabled || getReportLevelForAnnotation(JSPECIFY_ANNOTATIONS_PACKAGE) == ReportLevel.IGNORE
companion object {
val DEFAULT = JavaTypeEnhancementState()
}
}
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.load.java
import org.jetbrains.kotlin.name.FqName
data class Jsr305Settings(
val globalLevel: ReportLevel,
val migrationLevel: ReportLevel? = null,
val userDefinedLevelForSpecificAnnotation: Map<FqName, ReportLevel> = emptyMap()
) {
companion object {
val DEFAULT = getDefaultJsr305Settings()
}
@OptIn(ExperimentalStdlibApi::class)
val description by lazy {
buildList {
add(globalLevel.description)
migrationLevel?.let { add("under-migration:${it.description}") }
userDefinedLevelForSpecificAnnotation.forEach { add("@${it.key}:${it.value.description}") }
}.toTypedArray()
}
val isDisabled = globalLevel == ReportLevel.IGNORE
&& migrationLevel == ReportLevel.IGNORE
&& userDefinedLevelForSpecificAnnotation.isEmpty()
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.load.java
enum class ReportLevel(val description: String) {
IGNORE("ignore"),
WARN("warn"),
STRICT("strict"),
;
companion object {
fun findByDescription(description: String?): ReportLevel? = values().firstOrNull { it.description == description }
}
val isWarning: Boolean get() = this == WARN
val isIgnore: Boolean get() = this == IGNORE
}