diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/CommonTypes.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/CommonTypes.kt index 353ac6152a0..c9bac71c263 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/CommonTypes.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/CommonTypes.kt @@ -75,6 +75,7 @@ fun PrimitiveType.isNumeric(): Boolean = this in PrimitiveType.numericPrimitives enum class Inline { No, Yes, + YesSuppressWarning, // with suppressed warning about nothing to inline Only; fun isInline() = this != No diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/MemberBuilder.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/MemberBuilder.kt index 98e792206c6..a51dd4fe1b1 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/MemberBuilder.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/MemberBuilder.kt @@ -73,6 +73,7 @@ class MemberBuilder( var returns: String? = null; private set var body: String? = null; private set val annotations: MutableList = mutableListOf() + val suppressions: MutableList = mutableListOf() fun sourceFile(file: SourceFile) { sourceFile = file } @@ -89,7 +90,7 @@ class MemberBuilder( inline = value if (suppressWarning) { require(value == Inline.Yes) - annotation("""@Suppress("NOTHING_TO_INLINE")""") + inline = Inline.YesSuppressWarning } } fun inlineOnly() { inline = Inline.Only } @@ -113,6 +114,10 @@ class MemberBuilder( annotations += annotation } + fun suppress(diagnostic: String) { + suppressions += diagnostic + } + fun sequenceClassification(vararg sequenceClass: SequenceClass) { sequenceClassification += sequenceClass } @@ -324,8 +329,15 @@ class MemberBuilder( annotations.forEach { builder.append(it.trimIndent()).append('\n') } - if (inline == Inline.Only) { - builder.append("@kotlin.internal.InlineOnly").append('\n') + when (inline) { + Inline.Only -> builder.append("@kotlin.internal.InlineOnly").append('\n') + Inline.YesSuppressWarning -> suppressions.add("NOTHING_TO_INLINE") + } + + if (suppressions.isNotEmpty()) { + suppressions.joinTo(builder, separator = ", ", prefix = "@Suppress(", postfix = ")\n") { + """"$it"""" + } } listOfNotNull(