FE1.0/FIR: slightly fix diagnostic messages about OptIn
This commit is contained in:
+1
-1
@@ -238,7 +238,7 @@ object FirOptInUsageBaseChecker {
|
|||||||
}
|
}
|
||||||
val fqName = annotationClassId.asSingleFqName()
|
val fqName = annotationClassId.asSingleFqName()
|
||||||
val reportedMessage = message?.takeIf { it.isNotBlank() }
|
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)
|
reporter.reportOn(element.source, diagnostic, fqName, reportedMessage, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -119,7 +119,7 @@ class ExperimentalUsageChecker(project: Project) : CallChecker {
|
|||||||
private val ERROR_LEVEL = Name.identifier("ERROR")
|
private val ERROR_LEVEL = Name.identifier("ERROR")
|
||||||
|
|
||||||
internal fun getDefaultDiagnosticMessage(prefix: String): (FqName) -> String = { fqName: FqName ->
|
internal fun getDefaultDiagnosticMessage(prefix: String): (FqName) -> String = { fqName: FqName ->
|
||||||
OptInNames.buildDefaultDiagnosticMessage(prefix, fqName)
|
OptInNames.buildDefaultDiagnosticMessage(prefix, fqName.asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
private val USAGE_DIAGNOSTICS = ExperimentalityDiagnostics(
|
private val USAGE_DIAGNOSTICS = ExperimentalityDiagnostics(
|
||||||
|
|||||||
+1
-1
@@ -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()
|
foo()
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
warning: ATTENTION!
|
warning: ATTENTION!
|
||||||
This build uses in-dev FIR:
|
This build uses in-dev FIR:
|
||||||
-Xuse-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()
|
foo()
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
+2
-2
@@ -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() {}
|
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() {}
|
override fun bar() {}
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
warning: ATTENTION!
|
warning: ATTENTION!
|
||||||
This build uses in-dev FIR:
|
This build uses in-dev FIR:
|
||||||
-Xuse-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() {}
|
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() {}
|
override fun bar() {}
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
+5
-5
@@ -1,17 +1,17 @@
|
|||||||
warning: language version 1.4 is deprecated and its support will be removed in a future version of Kotlin
|
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) {
|
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
|
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
|
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()
|
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()
|
z.inv()
|
||||||
^
|
^
|
||||||
OK
|
OK
|
||||||
|
|||||||
@@ -39,18 +39,18 @@ object OptInNames {
|
|||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
val USE_EXPERIMENTAL_FQ_NAMES = OPT_IN_FQ_NAMES
|
val USE_EXPERIMENTAL_FQ_NAMES = OPT_IN_FQ_NAMES
|
||||||
|
|
||||||
fun buildDefaultDiagnosticMessage(prefix: String, fqName: FqName): String {
|
fun buildDefaultDiagnosticMessage(prefix: String, markerName: String): String {
|
||||||
return "$prefix with '@${fqName.asString()}' or '@OptIn(${fqName.asString()}::class)'"
|
return "$prefix with '@$markerName' or '@OptIn($markerName::class)'"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildMessagePrefix(verb: String): String =
|
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 {
|
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
|
val markerMessageOrStub = markerMessage
|
||||||
?.takeIf { it.isNotBlank() }?.let { if (it.endsWith(".")) "$it " else "$it. " } ?: ""
|
?.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
|
return basePrefix + markerMessageOrStub + baseSuffix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user