kotlin-stdlib-gen: add dsl option for multiple suppressed diagnostics

This commit is contained in:
Ilya Gorbunov
2018-01-25 18:03:37 +03:00
parent bd7ad8c9d5
commit bb04198f7e
2 changed files with 16 additions and 3 deletions
@@ -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
@@ -73,6 +73,7 @@ class MemberBuilder(
var returns: String? = null; private set
var body: String? = null; private set
val annotations: MutableList<String> = mutableListOf()
val suppressions: MutableList<String> = 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(