FE1.0/FIR: slightly fix diagnostic messages about OptIn

This commit is contained in:
Mikhail Glukhikh
2022-03-10 16:26:41 +03:00
committed by Space
parent 6b53ac8367
commit 5810ac01d2
8 changed files with 18 additions and 18 deletions
@@ -238,7 +238,7 @@ object FirOptInUsageBaseChecker {
}
val fqName = annotationClassId.asSingleFqName()
val reportedMessage = message?.takeIf { it.isNotBlank() }
?: OptInNames.buildDefaultDiagnosticMessage(OptInNames.buildMessagePrefix(verb), fqName)
?: OptInNames.buildDefaultDiagnosticMessage(OptInNames.buildMessagePrefix(verb), fqName.asString())
reporter.reportOn(element.source, diagnostic, fqName, reportedMessage, context)
}
}
@@ -119,7 +119,7 @@ class ExperimentalUsageChecker(project: Project) : CallChecker {
private val ERROR_LEVEL = Name.identifier("ERROR")
internal fun getDefaultDiagnosticMessage(prefix: String): (FqName) -> String = { fqName: FqName ->
OptInNames.buildDefaultDiagnosticMessage(prefix, fqName)
OptInNames.buildDefaultDiagnosticMessage(prefix, fqName.asString())
}
private val USAGE_DIAGNOSTICS = ExperimentalityDiagnostics(
+1 -1
View File
@@ -1,4 +1,4 @@
compiler/testData/cli/jvm/optInEmptyMessage.kt:8:5: error: this declaration needs OptIn. Its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)'
compiler/testData/cli/jvm/optInEmptyMessage.kt:8:5: error: this declaration needs opt-in. Its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)'
foo()
^
COMPILATION_ERROR
+1 -1
View File
@@ -1,7 +1,7 @@
warning: ATTENTION!
This build uses in-dev FIR:
-Xuse-fir
compiler/testData/cli/jvm/optInEmptyMessageFir.kt:8:5: error: this declaration needs OptIn. Its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)'
compiler/testData/cli/jvm/optInEmptyMessageFir.kt:8:5: error: this declaration needs opt-in. Its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)'
foo()
^
COMPILATION_ERROR
+2 -2
View File
@@ -1,7 +1,7 @@
compiler/testData/cli/jvm/optInOverrideMessage.kt:16:18: error: base declaration of supertype 'Base' needs OptIn. This API is experimental and can change at any time, please use with care. The declaration override must be annotated with '@Marker'
compiler/testData/cli/jvm/optInOverrideMessage.kt:16:18: error: base declaration of supertype 'Base' needs opt-in. This API is experimental and can change at any time, please use with care. The declaration override must be annotated with '@Marker' or '@OptIn(Marker::class)'
override fun foo() {}
^
compiler/testData/cli/jvm/optInOverrideMessage.kt:18:18: error: base declaration of supertype 'Base' needs OptIn. The declaration override must be annotated with '@EmptyMarker'
compiler/testData/cli/jvm/optInOverrideMessage.kt:18:18: error: base declaration of supertype 'Base' needs opt-in. The declaration override must be annotated with '@EmptyMarker' or '@OptIn(EmptyMarker::class)'
override fun bar() {}
^
COMPILATION_ERROR
+2 -2
View File
@@ -1,10 +1,10 @@
warning: ATTENTION!
This build uses in-dev FIR:
-Xuse-fir
compiler/testData/cli/jvm/optInOverrideMessageFir.kt:16:18: error: base declaration of supertype 'Base' needs OptIn. This API is experimental and can change at any time, please use with care. The declaration override must be annotated with '@Marker'
compiler/testData/cli/jvm/optInOverrideMessageFir.kt:16:18: error: base declaration of supertype 'Base' needs opt-in. This API is experimental and can change at any time, please use with care. The declaration override must be annotated with '@Marker' or '@OptIn(Marker::class)'
override fun foo() {}
^
compiler/testData/cli/jvm/optInOverrideMessageFir.kt:18:18: error: base declaration of supertype 'Base' needs OptIn. The declaration override must be annotated with '@EmptyMarker'
compiler/testData/cli/jvm/optInOverrideMessageFir.kt:18:18: error: base declaration of supertype 'Base' needs opt-in. The declaration override must be annotated with '@EmptyMarker' or '@OptIn(EmptyMarker::class)'
override fun bar() {}
^
COMPILATION_ERROR
@@ -1,17 +1,17 @@
warning: language version 1.4 is deprecated and its support will be removed in a future version of Kotlin
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:2:13: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:2:13: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
fun test(p: ULong) {
^
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:3:12: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:3:12: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
val z: ULong = p
^
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:3:20: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:3:20: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
val z: ULong = p
^
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:4:5: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:4:5: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
z.inv()
^
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:4:7: warning: this declaration needs OptIn. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutMarker2.kt:4:7: warning: this declaration needs opt-in. Its usage should be marked with '@kotlin.ExperimentalUnsignedTypes' or '@OptIn(kotlin.ExperimentalUnsignedTypes::class)'
z.inv()
^
OK
@@ -39,18 +39,18 @@ object OptInNames {
@Suppress("unused")
val USE_EXPERIMENTAL_FQ_NAMES = OPT_IN_FQ_NAMES
fun buildDefaultDiagnosticMessage(prefix: String, fqName: FqName): String {
return "$prefix with '@${fqName.asString()}' or '@OptIn(${fqName.asString()}::class)'"
fun buildDefaultDiagnosticMessage(prefix: String, markerName: String): String {
return "$prefix with '@$markerName' or '@OptIn($markerName::class)'"
}
fun buildMessagePrefix(verb: String): String =
"This declaration needs OptIn. Its usage $verb be marked"
"This declaration needs opt-in. Its usage $verb be marked"
fun buildOverrideMessage(supertypeName: String, markerMessage: String?, verb: String, markerName: String): String {
val basePrefix = "Base declaration of supertype '$supertypeName' needs OptIn. "
val basePrefix = "Base declaration of supertype '$supertypeName' needs opt-in. "
val markerMessageOrStub = markerMessage
?.takeIf { it.isNotBlank() }?.let { if (it.endsWith(".")) "$it " else "$it. " } ?: ""
val baseSuffix = "The declaration override $verb be annotated with '@$markerName'"
val baseSuffix = buildDefaultDiagnosticMessage("The declaration override $verb be annotated", markerName)
return basePrefix + markerMessageOrStub + baseSuffix
}
}