Support configuring of nullability annotations with their report levels through a test directive

This commit is contained in:
Victor Petukhov
2021-06-02 17:21:42 +03:00
parent 61c2f1b203
commit 6d3badb2cd
8 changed files with 237 additions and 2 deletions
@@ -86,6 +86,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/lombokSimple.kt");
}
@Test
@TestMetadata("multiple.kt")
public void testMultiple() throws Exception {
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/multiple.kt");
}
@Test
@TestMetadata("rxjava.kt")
public void testRxjava() throws Exception {
@@ -86,6 +86,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/lombokSimple.kt");
}
@Test
@TestMetadata("multiple.kt")
public void testMultiple() throws Exception {
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/multiple.kt");
}
@Test
@TestMetadata("rxjava.kt")
public void testRxjava() throws Exception {
@@ -86,6 +86,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/lombokSimple.kt");
}
@Test
@TestMetadata("multiple.kt")
public void testMultiple() throws Exception {
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/multiple.kt");
}
@Test
@TestMetadata("rxjava.kt")
public void testRxjava() throws Exception {
@@ -5,9 +5,11 @@
package org.jetbrains.kotlin.test.directives
import org.jetbrains.kotlin.cli.common.arguments.JavaTypeEnhancementStateParser
import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer
import org.jetbrains.kotlin.test.services.configuration.JavaForeignAnnotationType
import org.jetbrains.kotlin.load.java.ReportLevel
import org.jetbrains.kotlin.name.FqName
@Suppress("RemoveExplicitTypeArguments")
object ForeignAnnotationsDirectives : SimpleDirectivesContainer() {
@@ -30,6 +32,11 @@ object ForeignAnnotationsDirectives : SimpleDirectivesContainer() {
additionalParser = ReportLevel.Companion::findByDescription
)
val NULLABILITY_ANNOTATIONS by valueDirective<Pair<FqName, ReportLevel>>(
description = "List of annotations with their report levels",
parser = JavaTypeEnhancementStateParser.Companion::parsePlainNullabilityAnnotationReportLevels
)
val ANNOTATIONS_PATH by enumDirective<JavaForeignAnnotationType>(
description = "Path to foreign annotations"
)
@@ -45,6 +45,7 @@ open class JvmForeignAnnotationsConfigurator(testServices: TestServices) : Envir
override val directivesContainers: List<DirectivesContainer>
get() = listOf(ForeignAnnotationsDirectives)
@OptIn(ExperimentalStdlibApi::class)
override fun provideAdditionalAnalysisFlags(directives: RegisteredDirectives): Map<AnalysisFlag<*>, Any?> {
val defaultJsr305Settings = Jsr305Settings.DEFAULT
val globalState = directives.singleOrZeroValue(JSR305_GLOBAL_REPORT) ?: defaultJsr305Settings.globalLevel
@@ -54,8 +55,13 @@ open class JvmForeignAnnotationsConfigurator(testServices: TestServices) : Envir
val state = ReportLevel.findByDescription(stateDescription) ?: return@mapNotNull null
FqName(name) to state
}.toMap()
val configuredReportLevels =
directives.singleOrZeroValue(JSPECIFY_STATE)?.let { mapOf(JSPECIFY_ANNOTATIONS_PACKAGE to it) } ?: emptyMap()
val configuredReportLevels = buildMap<FqName, ReportLevel> {
directives.singleOrZeroValue(JSPECIFY_STATE)?.let { put(JSPECIFY_ANNOTATIONS_PACKAGE, it) }
for ((fqname, reportLevel) in directives[ForeignAnnotationsDirectives.NULLABILITY_ANNOTATIONS]) {
put(fqname, reportLevel)
}
}
return mapOf(
JvmAnalysisFlags.javaTypeEnhancementState to JavaTypeEnhancementState(
Jsr305Settings(globalState, migrationState, userAnnotationsState),