From e93133a28ffe03a37be20c210a56223a36d33835 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Fri, 16 Apr 2021 14:26:38 +0300 Subject: [PATCH] Implement jspecify marks processing in the tests properly, by adding specific handler and cleanuper --- .../codeMetaInfo/CodeMetaInfoRenderer.kt | 19 +- .../kotlin/codeMetaInfo/model/CodeMetaInfo.kt | 4 + .../model/JspecifyMarkerCodeMetaInfo.kt | 27 +++ ...JspecifyCodeMetaInfoRenderConfiguration.kt | 20 +++ .../jspecify/strictMode/Defaults.fir.kt | 2 +- .../jspecify/strictMode/Defaults.kt | 2 +- .../strictMode/IgnoreAnnotations.fir.kt | 2 +- .../jspecify/strictMode/IgnoreAnnotations.kt | 2 +- .../NullnessUnspecifiedTypeParameter.fir.kt | 4 +- .../NullnessUnspecifiedTypeParameter.kt | 4 +- .../jspecify/strictMode/Simple.fir.kt | 2 +- .../java8Tests/jspecify/strictMode/Simple.kt | 2 +- .../strictMode/TypeParameterBounds.fir.kt | 10 +- .../strictMode/TypeParameterBounds.kt | 10 +- .../warnMode/AnnotatedBoundsOfWildcard.fir.kt | 20 +-- .../warnMode/AnnotatedBoundsOfWildcard.kt | 20 +-- .../jspecify/warnMode/Defaults.fir.kt | 2 +- .../java8Tests/jspecify/warnMode/Defaults.kt | 2 +- .../warnMode/IgnoreAnnotations.fir.kt | 2 +- .../jspecify/warnMode/IgnoreAnnotations.kt | 2 +- .../warnMode/NonPlatformTypeParameter.fir.kt | 8 +- .../warnMode/NonPlatformTypeParameter.kt | 8 +- .../NullnessUnspecifiedTypeParameter.fir.kt | 10 +- .../NullnessUnspecifiedTypeParameter.kt | 9 +- .../jspecify/warnMode/SelfType.fir.kt | 12 +- .../java8Tests/jspecify/warnMode/SelfType.kt | 12 +- .../jspecify/warnMode/Simple.fir.kt | 2 +- .../java8Tests/jspecify/warnMode/Simple.kt | 2 +- .../TypeArgumentsFromParameterBounds.fir.kt | 12 +- .../TypeArgumentsFromParameterBounds.kt | 12 +- .../warnMode/TypeParameterBounds.fir.kt | 16 +- .../jspecify/warnMode/TypeParameterBounds.kt | 16 +- .../warnMode/WildcardsWithDefault.fir.kt | 8 +- .../jspecify/warnMode/WildcardsWithDefault.kt | 8 +- .../JvmEnvironmentConfigurationDirectives.kt | 5 - .../JspecifyDiagnosticComplianceHandler.kt | 67 +++++++ .../JspecifyMarksCleanupPreprocessor.kt | 19 ++ .../JspecifyTestsPreprocessor.kt | 163 ------------------ .../runners/AbstractForeignAnnotationsTest.kt | 6 +- 39 files changed, 246 insertions(+), 307 deletions(-) create mode 100644 compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/model/JspecifyMarkerCodeMetaInfo.kt create mode 100644 compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/renderConfigurations/JspecifyCodeMetaInfoRenderConfiguration.kt create mode 100644 compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/JspecifyDiagnosticComplianceHandler.kt create mode 100644 compiler/tests-common-new/tests/org/jetbrains/kotlin/test/preprocessors/JspecifyMarksCleanupPreprocessor.kt delete mode 100644 compiler/tests-common-new/tests/org/jetbrains/kotlin/test/preprocessors/JspecifyTestsPreprocessor.kt diff --git a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/CodeMetaInfoRenderer.kt b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/CodeMetaInfoRenderer.kt index 01f783596a4..4dadb21a64a 100644 --- a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/CodeMetaInfoRenderer.kt +++ b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/CodeMetaInfoRenderer.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.codeMetaInfo import com.intellij.util.containers.Stack -import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo import java.io.File @@ -55,21 +54,24 @@ object CodeMetaInfoRenderer { checkOpenedAndCloseStringIfNeeded(opened, offset, builder) val matchedCodeMetaInfos = sortedMetaInfos[offset] ?: emptyList() if (matchedCodeMetaInfos.isNotEmpty()) { - openStartTag(builder) val iterator = matchedCodeMetaInfos.listIterator() var current: CodeMetaInfo? = iterator.next() + if (current != null) builder.append(current.tagPrefix) + while (current != null) { val next: CodeMetaInfo? = if (iterator.hasNext()) iterator.next() else null opened.push(current) builder.append(current.asString()) when { next == null -> - closeStartTag(builder) + builder.append(current.tagPostfix) next.end == current.end -> builder.append(", ") - else -> - closeStartAndOpenNewTag(builder) + else -> { + builder.append(current.tagPostfix) + builder.append(next.tagPrefix) + } } current = next } @@ -84,16 +86,11 @@ object CodeMetaInfoRenderer { return metaInfos.sortedWith(metaInfoComparator) } - private fun closeString(result: StringBuilder) = result.append("") - private fun openStartTag(result: StringBuilder) = result.append("") - private fun closeStartAndOpenNewTag(result: StringBuilder) = result.append("!>, end: Int, result: StringBuilder) { var prev: CodeMetaInfo? = null while (!opened.isEmpty() && end == opened.peek().end) { if (prev == null || prev.start != opened.peek().start) - closeString(result) + result.append(opened.peek().closingTag) prev = opened.pop() } } diff --git a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/model/CodeMetaInfo.kt b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/model/CodeMetaInfo.kt index aec752b7a48..d87e6eb1356 100644 --- a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/model/CodeMetaInfo.kt +++ b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/model/CodeMetaInfo.kt @@ -14,5 +14,9 @@ interface CodeMetaInfo { val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration val attributes: MutableList + val tagPrefix: String get() = "" + val closingTag: String get() = "" + fun asString(): String } diff --git a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/model/JspecifyMarkerCodeMetaInfo.kt b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/model/JspecifyMarkerCodeMetaInfo.kt new file mode 100644 index 00000000000..97a1c13394c --- /dev/null +++ b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/model/JspecifyMarkerCodeMetaInfo.kt @@ -0,0 +1,27 @@ +/* + * 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.codeMetaInfo.model + +import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.JspecifyCodeMetaInfoRenderConfiguration + +class JspecifyMarkerCodeMetaInfo( + override val start: Int, + override val end: Int, + val offset: Int, + val name: String +) : CodeMetaInfo { + override val tagPrefix = "\n${" ".repeat(offset)}// " + override val tagPostfix = "" + override val closingTag = "" + + override val renderConfiguration = JspecifyCodeMetaInfoRenderConfiguration + + override val tag = renderConfiguration.getTag(this) + + override val attributes: MutableList = mutableListOf() + + override fun asString(): String = renderConfiguration.asString(this) +} diff --git a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/renderConfigurations/JspecifyCodeMetaInfoRenderConfiguration.kt b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/renderConfigurations/JspecifyCodeMetaInfoRenderConfiguration.kt new file mode 100644 index 00000000000..787bb10a959 --- /dev/null +++ b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/renderConfigurations/JspecifyCodeMetaInfoRenderConfiguration.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2020 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.codeMetaInfo.renderConfigurations + +import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo +import org.jetbrains.kotlin.codeMetaInfo.model.JspecifyMarkerCodeMetaInfo + +object JspecifyCodeMetaInfoRenderConfiguration : AbstractCodeMetaInfoRenderConfiguration() { + override fun asString(codeMetaInfo: CodeMetaInfo): String { + if (codeMetaInfo !is JspecifyMarkerCodeMetaInfo) return "" + return getTag(codeMetaInfo) + } + + fun getTag(codeMetaInfo: JspecifyMarkerCodeMetaInfo): String { + return codeMetaInfo.name + } +} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.fir.kt index 0cfa09edac7..257cd1ade47 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.fir.kt @@ -35,7 +35,7 @@ fun main(a: Defaults, x: Foo): Unit { a.everythingUnknown(null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.mixed(null).foo() // jspecify_nullness_mismatch a.mixed(x).foo() diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt index 8ac3346eaa1..947b5f5851b 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Defaults.kt @@ -35,7 +35,7 @@ fun main(a: Defaults, x: Foo): Unit { a.everythingUnknown(null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.mixed(null).foo() // jspecify_nullness_mismatch a.mixed(x).foo() diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/IgnoreAnnotations.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/IgnoreAnnotations.fir.kt index d959bf5b316..bc488dea889 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/IgnoreAnnotations.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/IgnoreAnnotations.fir.kt @@ -31,7 +31,7 @@ public class Derived extends Base { } fun main(a: IgnoreAnnotations, x: Derived): Unit { // jspecify_nullness_mismatch a.foo(x, null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.foo(null, x).foo() // jspecify_nullness_mismatch diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/IgnoreAnnotations.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/IgnoreAnnotations.kt index 7dc46c25e76..e88a501152b 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/IgnoreAnnotations.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/IgnoreAnnotations.kt @@ -31,7 +31,7 @@ public class Derived extends Base { } fun main(a: IgnoreAnnotations, x: Derived): Unit { // jspecify_nullness_mismatch a.foo(x, null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.foo(null, x).foo() // jspecify_nullness_mismatch diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullnessUnspecifiedTypeParameter.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullnessUnspecifiedTypeParameter.fir.kt index 673cc3a63ce..a015835f3be 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullnessUnspecifiedTypeParameter.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullnessUnspecifiedTypeParameter.fir.kt @@ -24,13 +24,13 @@ fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeP a2.foo(null) a2.foo(1) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a1.bar(null, null) // jspecify_nullness_mismatch a1.bar(x, null) a1.bar(x, 1) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a2.bar(null, null) // jspecify_nullness_mismatch a2.bar(x, null) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullnessUnspecifiedTypeParameter.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullnessUnspecifiedTypeParameter.kt index 97227d59e56..b33dd528a76 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullnessUnspecifiedTypeParameter.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/NullnessUnspecifiedTypeParameter.kt @@ -24,13 +24,13 @@ fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeP a2.foo(null) a2.foo(1) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a1.bar(null, null) // jspecify_nullness_mismatch a1.bar(x, null) a1.bar(x, 1) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a2.bar(null, null) // jspecify_nullness_mismatch a2.bar(x, null) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Simple.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Simple.fir.kt index edbd1fbe8b5..832132170ff 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Simple.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Simple.fir.kt @@ -29,7 +29,7 @@ public class Derived extends Base { fun main(a: Simple, x: Derived): Unit { // jspecify_nullness_mismatch a.foo(x, null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.foo(null, x).foo() a.bar().foo() diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Simple.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Simple.kt index edbd1fbe8b5..832132170ff 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Simple.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Simple.kt @@ -29,7 +29,7 @@ public class Derived extends Base { fun main(a: Simple, x: Derived): Unit { // jspecify_nullness_mismatch a.foo(x, null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.foo(null, x).foo() a.bar().foo() diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.fir.kt index 9d813421a33..0453bdfe237 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.fir.kt @@ -21,27 +21,27 @@ public class B { public class Test {} // FILE: main.kt -// jspecify_nullness_mismatch +// jspecify_nullness_mismatch, jspecify_nullness_mismatch fun main(a1: A<Any?>, a2: A, b1: B<Any?>, b2: B, x: T): Unit { a1.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a1.bar<T?>(null) a1.bar(x) a2.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a2.bar<T?>(null) a2.bar(x) // jspecify_nullness_mismatch b1.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch b1.bar<T?>(null) b1.bar(x) // jspecify_nullness_mismatch b2.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch b2.bar<T?>(null) b2.bar(x) } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt index b932a35b721..952a722b241 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/TypeParameterBounds.kt @@ -21,27 +21,27 @@ public class B { public class Test {} // FILE: main.kt -// jspecify_nullness_mismatch +// jspecify_nullness_mismatch, jspecify_nullness_mismatch fun main(a1: A<Any?>, a2: A, b1: B<Any?>, b2: B, x: T): Unit { a1.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a1.bar<T?>(null) a1.bar(x) a2.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a2.bar<T?>(null) a2.bar(x) // jspecify_nullness_mismatch b1.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch b1.bar<T?>(null) b1.bar(x) // jspecify_nullness_mismatch b2.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch b2.bar<T?>(null) b2.bar(x) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.fir.kt index 850db9087d8..839eeea72f4 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.fir.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: AnnotatedBoundsOfWildcard.java import org.jspecify.nullness.*; @@ -42,9 +40,9 @@ fun main( b: AnnotatedBoundsOfWildcard ): Unit { - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superAsIs(aAnyNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superAsIs(aAnyNotNullNotNullNull) b.superAsIs(aAnyNotNullNullNotNull) b.superAsIs(aAnyNotNullNullNull) @@ -54,13 +52,13 @@ fun main( b.superNotNull(aAnyNotNullNullNotNull) b.superNotNull(aAnyNotNullNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superNullable(aAnyNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superNullable(aAnyNotNullNotNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superNullable(aAnyNotNullNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superNullable(aAnyNotNullNullNull) b.extendsAsIs(aNotNullNotNullNotNull) @@ -69,11 +67,11 @@ fun main( b.extendsAsIs(aNotNullNullNull) b.extendsNotNull(aNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.extendsNotNull(aNotNullNotNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.extendsNotNull(aNotNullNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.extendsNotNull(aNotNullNullNull) b.extendsNullable(aNotNullNotNullNotNull) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.kt index 850db9087d8..839eeea72f4 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: AnnotatedBoundsOfWildcard.java import org.jspecify.nullness.*; @@ -42,9 +40,9 @@ fun main( b: AnnotatedBoundsOfWildcard ): Unit { - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superAsIs(aAnyNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superAsIs(aAnyNotNullNotNullNull) b.superAsIs(aAnyNotNullNullNotNull) b.superAsIs(aAnyNotNullNullNull) @@ -54,13 +52,13 @@ fun main( b.superNotNull(aAnyNotNullNullNotNull) b.superNotNull(aAnyNotNullNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superNullable(aAnyNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superNullable(aAnyNotNullNotNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superNullable(aAnyNotNullNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.superNullable(aAnyNotNullNullNull) b.extendsAsIs(aNotNullNotNullNotNull) @@ -69,11 +67,11 @@ fun main( b.extendsAsIs(aNotNullNullNull) b.extendsNotNull(aNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.extendsNotNull(aNotNullNotNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.extendsNotNull(aNotNullNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.extendsNotNull(aNotNullNullNull) b.extendsNullable(aNotNullNotNullNotNull) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.fir.kt index d8a0910a49c..9ddee588286 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.fir.kt @@ -34,7 +34,7 @@ fun main(a: Defaults, x: Foo): Unit { a.everythingUnknown(null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.mixed(null).foo() // jspecify_nullness_mismatch a.mixed(x).foo() diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt index decabac6a75..eb9b3e42c9c 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Defaults.kt @@ -34,7 +34,7 @@ fun main(a: Defaults, x: Foo): Unit { a.everythingUnknown(null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.mixed(null).foo() // jspecify_nullness_mismatch a.mixed(x).foo() diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.fir.kt index e9dbc240304..50f7a355ef1 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.fir.kt @@ -30,7 +30,7 @@ public class Derived extends Base { } fun main(a: IgnoreAnnotations, x: Derived): Unit { // jspecify_nullness_mismatch a.foo(x, null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.foo(null, x).foo() // jspecify_nullness_mismatch diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.kt index e9dbc240304..50f7a355ef1 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.kt @@ -30,7 +30,7 @@ public class Derived extends Base { } fun main(a: IgnoreAnnotations, x: Derived): Unit { // jspecify_nullness_mismatch a.foo(x, null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.foo(null, x).foo() // jspecify_nullness_mismatch diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NonPlatformTypeParameter.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NonPlatformTypeParameter.fir.kt index de788ad31c8..97bf3d28136 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NonPlatformTypeParameter.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NonPlatformTypeParameter.fir.kt @@ -1,6 +1,4 @@ // !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated -// JSPECIFY_MUTE - // FILE: NonPlatformTypeParameter.java import org.jspecify.nullness.*; @@ -16,14 +14,14 @@ public class Test {} fun main(a1: NonPlatformTypeParameter, a2: NonPlatformTypeParameter, x: T): Unit { a1.foo(null) a1.bar(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a1.bar(null) a1.bar(x) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.foo(null) a2.bar(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.bar(null) a2.bar(x) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NonPlatformTypeParameter.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NonPlatformTypeParameter.kt index de788ad31c8..97bf3d28136 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NonPlatformTypeParameter.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NonPlatformTypeParameter.kt @@ -1,6 +1,4 @@ // !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated -// JSPECIFY_MUTE - // FILE: NonPlatformTypeParameter.java import org.jspecify.nullness.*; @@ -16,14 +14,14 @@ public class Test {} fun main(a1: NonPlatformTypeParameter, a2: NonPlatformTypeParameter, x: T): Unit { a1.foo(null) a1.bar(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a1.bar(null) a1.bar(x) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.foo(null) a2.bar(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.bar(null) a2.bar(x) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.fir.kt index 998d0da1678..88d72080abb 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.fir.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: NullnessUnspecifiedTypeParameter.java import org.jspecify.nullness.*; @@ -16,23 +14,23 @@ public class Test {} // FILE: main.kt // jspecify_nullness_mismatch fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeParameter<Any?>, x: Test): Unit { - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a1.foo(null) a1.foo(1) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.foo(null) a2.foo(1) // jspecify_nullness_mismatch a1.bar(null, null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a1.bar(x, null) a1.bar(x, 1) // jspecify_nullness_mismatch a2.bar(null, null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.bar(x, null) a2.bar(x, 1) } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.kt index 97e0039bd71..da92c40346c 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/NullnessUnspecifiedTypeParameter.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: NullnessUnspecifiedTypeParameter.java import org.jspecify.nullness.*; @@ -16,23 +14,22 @@ public class Test {} // FILE: main.kt // jspecify_nullness_mismatch fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeParameter<Any?>, x: Test): Unit { - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a1.foo(null) a1.foo(1) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.foo(null) a2.foo(1) // jspecify_nullness_mismatch a1.bar(null, null) - // jspecify_nullness_mismatch a1.bar(x, null) a1.bar(x, 1) // jspecify_nullness_mismatch a2.bar(null, null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.bar(x, null) a2.bar(x, 1) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.fir.kt index 82513de91a5..447ebaf3e83 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.fir.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: SelfType.java import org.jspecify.nullness.*; @@ -39,20 +37,20 @@ public class CKN extends C<@Nullable CK> {} // FILE: main.kt fun main(ak: AK, akn: AKN, bk: BK, ck: CK, ckn: CKN): Unit { ak.foo(ak) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} ak.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} akn.foo(null) bk.foo(bk) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} bk.foo(null) ck.foo(ck) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} ck.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} ckn.foo(null) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.kt index 82513de91a5..447ebaf3e83 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/SelfType.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: SelfType.java import org.jspecify.nullness.*; @@ -39,20 +37,20 @@ public class CKN extends C<@Nullable CK> {} // FILE: main.kt fun main(ak: AK, akn: AKN, bk: BK, ck: CK, ckn: CKN): Unit { ak.foo(ak) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} ak.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} akn.foo(null) bk.foo(bk) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} bk.foo(null) ck.foo(ck) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} ck.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} ckn.foo(null) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Simple.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Simple.fir.kt index ae70daf30b9..264efbcd9f3 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Simple.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Simple.fir.kt @@ -28,7 +28,7 @@ public class Derived extends Base { fun main(a: Simple, x: Derived): Unit { // jspecify_nullness_mismatch a.foo(x, null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.foo(null, x).foo() a.bar().foo() diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Simple.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Simple.kt index ef56fed8c79..c6d8f5eba4e 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Simple.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Simple.kt @@ -28,7 +28,7 @@ public class Derived extends Base { fun main(a: Simple, x: Derived): Unit { // jspecify_nullness_mismatch a.foo(x, null).foo() - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch, jspecify_nullness_mismatch a.foo(null, x).foo() a.bar().foo() diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeArgumentsFromParameterBounds.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeArgumentsFromParameterBounds.fir.kt index f4643f099da..dcca56948e6 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeArgumentsFromParameterBounds.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeArgumentsFromParameterBounds.fir.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: TypeArgumentsFromParameterBounds.java import org.jspecify.nullness.*; @@ -33,16 +31,16 @@ fun main( a: A, b: B ): Unit { a.bar(aNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a.bar(aNotNullNotNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a.bar(aNotNullNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a.bar(aNotNullNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.bar(aNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.bar(aNotNullNotNullNull) b.bar(aNotNullNullNotNull) b.bar(aNotNullNullNull) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeArgumentsFromParameterBounds.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeArgumentsFromParameterBounds.kt index f4643f099da..dcca56948e6 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeArgumentsFromParameterBounds.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeArgumentsFromParameterBounds.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: TypeArgumentsFromParameterBounds.java import org.jspecify.nullness.*; @@ -33,16 +31,16 @@ fun main( a: A, b: B ): Unit { a.bar(aNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a.bar(aNotNullNotNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a.bar(aNotNullNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a.bar(aNotNullNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.bar(aNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.bar(aNotNullNotNullNull) b.bar(aNotNullNullNotNull) b.bar(aNotNullNullNull) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.fir.kt index 8ac35fd76ea..581183552af 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.fir.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: A.java import org.jspecify.nullness.*; @@ -21,27 +19,27 @@ public class B { public class Test {} // FILE: main.kt -// jspecify_nullness_mismatch +// jspecify_nullness_mismatch, jspecify_nullness_mismatch fun main(a1: A<Any?>, a2: A, b1: B<Any?>, b2: B, x: T): Unit { a1.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a1.bar(null) a1.bar(x) a2.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.bar(null) a2.bar(x) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b1.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b1.bar(null) b1.bar(x) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b2.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b2.bar(null) b2.bar(x) } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt index 64a3e932bc3..156ae02e400 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: A.java import org.jspecify.nullness.*; @@ -21,27 +19,27 @@ public class B { public class Test {} // FILE: main.kt -// jspecify_nullness_mismatch +// jspecify_nullness_mismatch, jspecify_nullness_mismatch fun main(a1: A<Any?>, a2: A, b1: B<Any?>, b2: B, x: T): Unit { a1.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a1.bar(null) a1.bar(x) a2.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} a2.bar(null) a2.bar(x) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b1.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b1.bar(null) b1.bar(x) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b2.foo(null) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b2.bar(null) b2.bar(x) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/WildcardsWithDefault.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/WildcardsWithDefault.fir.kt index e829d871a8f..8fedec332fc 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/WildcardsWithDefault.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/WildcardsWithDefault.fir.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: WildcardsWithDefault.java import org.jspecify.nullness.*; @@ -23,11 +21,11 @@ fun main( b: WildcardsWithDefault ): Unit { b.noBoundsNotNull(aNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.noBoundsNotNull(aNotNullNotNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.noBoundsNotNull(aNotNullNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.noBoundsNotNull(aNotNullNullNull) b.noBoundsNullable(aNotNullNotNullNotNull) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/WildcardsWithDefault.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/WildcardsWithDefault.kt index e829d871a8f..8fedec332fc 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/WildcardsWithDefault.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/WildcardsWithDefault.kt @@ -1,5 +1,3 @@ -// JSPECIFY_MUTE - // FILE: WildcardsWithDefault.java import org.jspecify.nullness.*; @@ -23,11 +21,11 @@ fun main( b: WildcardsWithDefault ): Unit { b.noBoundsNotNull(aNotNullNotNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.noBoundsNotNull(aNotNullNotNullNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.noBoundsNotNull(aNotNullNullNotNull) - // jspecify_nullness_mismatch + // jspecify_nullness_mismatch{mute} b.noBoundsNotNull(aNotNullNullNull) b.noBoundsNullable(aNotNullNotNullNotNull) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/JvmEnvironmentConfigurationDirectives.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/JvmEnvironmentConfigurationDirectives.kt index af6a6dbff10..8d45ba6b353 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/JvmEnvironmentConfigurationDirectives.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/JvmEnvironmentConfigurationDirectives.kt @@ -59,11 +59,6 @@ object JvmEnvironmentConfigurationDirectives : SimpleDirectivesContainer() { applicability = DirectiveApplicability.Global ) - val JSPECIFY_MUTE by directive( - "Skip jspecify checks for compliance Kotlin diagnostics to jspecify marks", - applicability = DirectiveApplicability.Global - ) - @Suppress("RemoveExplicitTypeArguments") val STRING_CONCAT by enumDirective( description = "Configure mode of string concatenation", diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/JspecifyDiagnosticComplianceHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/JspecifyDiagnosticComplianceHandler.kt new file mode 100644 index 00000000000..c6f3eae9478 --- /dev/null +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/JspecifyDiagnosticComplianceHandler.kt @@ -0,0 +1,67 @@ +/* + * 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.test.frontend.classic.handlers + +import org.jetbrains.kotlin.codeMetaInfo.model.DiagnosticCodeMetaInfo +import org.jetbrains.kotlin.codeMetaInfo.model.JspecifyMarkerCodeMetaInfo +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm +import org.jetbrains.kotlin.test.directives.ForeignAnnotationsDirectives +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.globalMetadataInfoHandler +import org.jetbrains.kotlin.utils.JavaTypeEnhancementState +import org.jetbrains.kotlin.utils.ReportLevel + +// Not that this diagnostic handler should be included only with `ClassicDiagnosticsHandler` and go after it +class JspecifyDiagnosticComplianceHandler(testServices: TestServices) : ClassicFrontendAnalysisHandler(testServices) { + override fun processModule(module: TestModule, info: ClassicFrontendOutputArtifact) { + val jspecifyMode = module.directives[ForeignAnnotationsDirectives.JSPECIFY_STATE].singleOrNull() + ?: JavaTypeEnhancementState.DEFAULT_REPORT_LEVEL_FOR_JSPECIFY + + for ((testFile, ktFile) in info.allKtFiles) { + val reportedDiagnostics = + testServices.globalMetadataInfoHandler.getReportedMetaInfosForFile(testFile).filterIsInstance() + for (metaInfo in reportedDiagnostics) { + val jspecifyMark = diagnosticsToJspecifyMarks.getValue(jspecifyMode)[metaInfo.diagnostic.factory] ?: continue + val fileLines = ktFile.text.lines() + val fileLinePositions = + fileLines.map { it.length }.runningReduce { sumLength, length -> sumLength + length + System.lineSeparator().length } + val lineIndexToPasteJspecifyMark = fileLinePositions.indexOfLast { it < metaInfo.start } + val positionToPasteJspecifyMark = fileLinePositions[lineIndexToPasteJspecifyMark] + val offset = fileLines[lineIndexToPasteJspecifyMark + 1].takeWhile { it == ' ' }.length + + testServices.globalMetadataInfoHandler.addMetadataInfosForFile( + testFile, + listOf(JspecifyMarkerCodeMetaInfo(positionToPasteJspecifyMark, positionToPasteJspecifyMark, offset, jspecifyMark)) + ) + } + } + } + + override fun processAfterAllModules(someAssertionWasFailed: Boolean) {} + + companion object { + val diagnosticsToJspecifyMarks = mapOf( + ReportLevel.WARN to mapOf( + ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS to "jspecify_nullness_mismatch", + ErrorsJvm.UPPER_BOUND_VIOLATED_BASED_ON_JAVA_ANNOTATIONS to "jspecify_nullness_mismatch", + ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS to "jspecify_nullness_mismatch", + ErrorsJvm.RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS to "jspecify_nullness_mismatch", + ), + ReportLevel.STRICT to mapOf( + Errors.TYPE_MISMATCH to "jspecify_nullness_mismatch", + Errors.NULL_FOR_NONNULL_TYPE to "jspecify_nullness_mismatch", + Errors.NOTHING_TO_OVERRIDE to "jspecify_nullness_mismatch", + Errors.RETURN_TYPE_MISMATCH_ON_OVERRIDE to "jspecify_nullness_mismatch", + Errors.UPPER_BOUND_VIOLATED to "jspecify_nullness_mismatch", + Errors.UNSAFE_CALL to "jspecify_nullness_mismatch", + ), + ReportLevel.IGNORE to emptyMap() + ) + } +} \ No newline at end of file diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/preprocessors/JspecifyMarksCleanupPreprocessor.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/preprocessors/JspecifyMarksCleanupPreprocessor.kt new file mode 100644 index 00000000000..e0221d53498 --- /dev/null +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/preprocessors/JspecifyMarksCleanupPreprocessor.kt @@ -0,0 +1,19 @@ +/* + * 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.test.preprocessors + +import org.jetbrains.kotlin.test.frontend.classic.handlers.JspecifyDiagnosticComplianceHandler.Companion.diagnosticsToJspecifyMarks +import org.jetbrains.kotlin.test.model.TestFile +import org.jetbrains.kotlin.test.services.* + +class JspecifyMarksCleanupPreprocessor(testServices: TestServices) : SourceFilePreprocessor(testServices) { + override fun process(file: TestFile, content: String) = content.replace(regexToCleanup, "") + + companion object { + private val jspecifyMarks = diagnosticsToJspecifyMarks.values.map { it.values }.flatten().joinToString("|") + private val regexToCleanup = Regex("""[ ]*// ($jspecifyMarks)(, ($jspecifyMarks))*${System.lineSeparator()}""") + } +} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/preprocessors/JspecifyTestsPreprocessor.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/preprocessors/JspecifyTestsPreprocessor.kt deleted file mode 100644 index f50ab1e00e4..00000000000 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/preprocessors/JspecifyTestsPreprocessor.kt +++ /dev/null @@ -1,163 +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.test.preprocessors - -import org.jetbrains.kotlin.checkers.DiagnosedRange -import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil -import org.jetbrains.kotlin.diagnostics.Errors -import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm -import org.jetbrains.kotlin.test.KtAssert -import org.jetbrains.kotlin.test.directives.ForeignAnnotationsDirectives -import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.JSPECIFY_MUTE -import org.jetbrains.kotlin.test.model.TestFile -import org.jetbrains.kotlin.test.services.* -import org.jetbrains.kotlin.utils.JavaTypeEnhancementState -import org.jetbrains.kotlin.utils.ReportLevel -import java.util.* - -class JspecifyTestsPreprocessor(testServices: TestServices) : SourceFilePreprocessor(testServices) { - val shouldAutoApplyChanges = System.getProperty("autoApply") == "true" - - private fun getJspecifyMarkRegex(jspecifyMark: String) = Regex("""^\s*// $jspecifyMark$""") - private fun checkIfAllJspecifyMarksByDiagnosticsArePresent( - diagnosedRanges: List, - lineIndexesByRanges: TreeMap, - textLines: List, - compilerDiagnosticsToJspecifyMarksMap: Map - ) { - for (diagnosticRange in diagnosedRanges) { - val lineIndex = lineIndexesByRanges.floorEntry(diagnosticRange.start).value - - for (diagnostic in diagnosticRange.getDiagnostics()) { - val requiredJspecifyMark = compilerDiagnosticsToJspecifyMarksMap[diagnostic.name] ?: continue - - fun getErrorMessage(lineIndex: Int) = - "Jspecify mark '$requiredJspecifyMark' not found for diagnostic '${diagnostic}' at ${lineIndex + 1} line.\n" + - "It should be located at the previous line as a comment." - - assert(lineIndex != 0) { getErrorMessage(0) } - - val previousLine = textLines[lineIndex - 1] - - assert(getJspecifyMarkRegex(requiredJspecifyMark).matches(previousLine)) { getErrorMessage(lineIndex) } - } - } - } - - private fun checkIfAllDiagnosticsByJspecifyMarksArePresent( - diagnosedRanges: List, - lineIndexesByRanges: TreeMap, - textLines: List, - compilerDiagnosticsToJspecifyMarksMap: Map> - ) { - for ((jspecifyMark, possibleDiagnostics) in compilerDiagnosticsToJspecifyMarksMap) { - val diagnosticRanges = diagnosedRanges.mapNotNull { - val relevantDiagnostics = it.getDiagnostics().filter { it.name in possibleDiagnostics } - if (relevantDiagnostics.isEmpty()) return@mapNotNull null - it.start - } - - val lineIndexesWithJspecifyMarks = - textLines.mapIndexedNotNull { index, it -> getJspecifyMarkRegex(jspecifyMark).find(it)?.let { index } } - - if (diagnosticRanges.isEmpty()) { - if (lineIndexesWithJspecifyMarks.isEmpty()) { - continue - } else { - KtAssert.fail( - "None of \"${possibleDiagnostics.joinToString(", ")}\" diagnostics not found " + - "for jspecify mark '$jspecifyMark' at lines: ${lineIndexesWithJspecifyMarks.map { it + 1 }.joinToString()}" - ) - } - } - - for (lineIndex in lineIndexesWithJspecifyMarks) { - val lineStartPosition = lineIndexesByRanges.entries.find { (_, index) -> index == lineIndex + 1 }?.key - val errorMessage = "None of \"${possibleDiagnostics.joinToString()}\" diagnostics not found " + - "for jspecify mark '$jspecifyMark' at ${lineIndex + 1} line" - - KtAssert.assertTrue(errorMessage, lineStartPosition != null) - - val lineEndPosition = lineStartPosition!! + textLines[lineIndex + 1].length - val isCorrespondingDiagnosticPresent = diagnosticRanges.any { it in lineStartPosition..lineEndPosition } - - KtAssert.assertTrue(errorMessage, isCorrespondingDiagnosticPresent) - } - } - } - - override fun process(file: TestFile, content: String): String { - if (!file.relativePath.endsWith(".kt")) return content - - val textWithDiagnostics = content.substringAfter(MAIN_KT_FILE_DIRECTIVE).removeSuffix("\n") - val diagnosedRanges = mutableListOf() - val textWithoutDiagnostics = CheckerTestUtil.parseDiagnosedRanges(textWithDiagnostics, diagnosedRanges) - - val textLines = textWithoutDiagnostics.lines() - val lineIndexesByRanges = TreeMap().apply { - textLines.scanIndexed(0) { index, position, line -> - put(position, index) - position + line.length + 1 // + new line symbol - } - } - - val jspecifyMode = file.directives[ForeignAnnotationsDirectives.JSPECIFY_STATE].singleOrNull() - ?: JavaTypeEnhancementState.DEFAULT_REPORT_LEVEL_FOR_JSPECIFY - val compilerDiagnosticsToJspecifyMarksMap = when (jspecifyMode) { - ReportLevel.STRICT -> diagnosticsToJspecifyMarksMapForStrictMode - ReportLevel.WARN -> diagnosticsToJspecifyMarksMapForWarnMode - ReportLevel.IGNORE -> mapOf() - } - val jspecifyMarksToCompilerDiagnosticsMap = when (jspecifyMode) { - ReportLevel.STRICT -> jspecifyMarksToPossibleDiagnosticsForStrictMode - ReportLevel.WARN -> jspecifyMarksToPossibleDiagnosticsForWarnMode - ReportLevel.IGNORE -> mapOf() - } - - if (shouldAutoApplyChanges || JSPECIFY_MUTE in testServices.moduleStructure.allDirectives) { - return content - } - - checkIfAllJspecifyMarksByDiagnosticsArePresent( - diagnosedRanges, - lineIndexesByRanges, - textLines, - compilerDiagnosticsToJspecifyMarksMap - ) - checkIfAllDiagnosticsByJspecifyMarksArePresent( - diagnosedRanges, - lineIndexesByRanges, - textLines, - jspecifyMarksToCompilerDiagnosticsMap - ) - - return content - } - - companion object { - const val MAIN_KT_FILE_DIRECTIVE = "// FILE: main.kt\n" - - val diagnosticsToJspecifyMarksMapForWarnMode = mapOf( - ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.name to "jspecify_nullness_mismatch", - Errors.TYPE_MISMATCH.name to "jspecify_nullness_mismatch", - Errors.NULL_FOR_NONNULL_TYPE.name to "jspecify_nullness_mismatch", - Errors.NOTHING_TO_OVERRIDE.name to "jspecify_nullness_mismatch", - Errors.RETURN_TYPE_MISMATCH_ON_OVERRIDE.name to "jspecify_nullness_mismatch", - Errors.UPPER_BOUND_VIOLATED.name to "jspecify_nullness_mismatch", - ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.name to "jspecify_nullness_mismatch", - ErrorsJvm.RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.name to "jspecify_nullness_mismatch", - Errors.UNSAFE_CALL.name to "jspecify_nullness_mismatch", - ) - - val jspecifyMarksToPossibleDiagnosticsForWarnMode = - diagnosticsToJspecifyMarksMapForWarnMode.entries.groupBy({ it.value }, { it.key }) - - val diagnosticsToJspecifyMarksMapForStrictMode = diagnosticsToJspecifyMarksMapForWarnMode - - val jspecifyMarksToPossibleDiagnosticsForStrictMode = - diagnosticsToJspecifyMarksMapForStrictMode.entries.groupBy({ it.value }, { it.key }) - } -} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractForeignAnnotationsTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractForeignAnnotationsTest.kt index cd08b3e57ca..69a2ef0efe9 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractForeignAnnotationsTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractForeignAnnotationsTest.kt @@ -22,10 +22,11 @@ import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirective import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticsHandler import org.jetbrains.kotlin.test.frontend.classic.handlers.DeclarationsDumpHandler +import org.jetbrains.kotlin.test.frontend.classic.handlers.JspecifyDiagnosticComplianceHandler import org.jetbrains.kotlin.test.frontend.classic.handlers.OldNewInferenceMetaInfoProcessor import org.jetbrains.kotlin.test.model.DependencyKind import org.jetbrains.kotlin.test.model.FrontendKinds -import org.jetbrains.kotlin.test.preprocessors.JspecifyTestsPreprocessor +import org.jetbrains.kotlin.test.preprocessors.JspecifyMarksCleanupPreprocessor import org.jetbrains.kotlin.test.services.configuration.* import org.jetbrains.kotlin.test.services.jvm.ForeignAnnotationAgainstCompiledJavaTestSuppressor import org.jetbrains.kotlin.test.services.sourceProviders.AdditionalDiagnosticsSourceFilesProvider @@ -89,7 +90,8 @@ abstract class AbstractForeignAnnotationsTestBase : AbstractKotlinCompilerTest() } forTestsMatching("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/*") { - useSourcePreprocessor(::JspecifyTestsPreprocessor, needToPrepend = true) + useFrontendHandlers(::JspecifyDiagnosticComplianceHandler) + useSourcePreprocessor(::JspecifyMarksCleanupPreprocessor) } } }