Fix warnings in generator modules

This commit is contained in:
Alexander Udalov
2021-07-25 14:23:23 +02:00
parent 2ca3adbcb2
commit 0d1380c232
15 changed files with 57 additions and 41 deletions
@@ -1,4 +1,4 @@
/*
/*
* 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.
*/
@@ -680,7 +680,7 @@ object ArrayOps : TemplateGroupBase() {
if (primitive == null)
"return this.asDynamic().concat(arrayOf(element))"
else
"return plus(${primitive.name.toLowerCase()}ArrayOf(element))"
"return plus(${primitive.name.lowercase()}ArrayOf(element))"
}
}
on(Platform.Native) {
@@ -946,7 +946,7 @@ object ArrayOps : TemplateGroupBase() {
val f_copyOfRangeJvmImpl = fn("copyOfRangeImpl(fromIndex: Int, toIndex: Int)") {
include(InvariantArraysOfObjects, ArraysOfPrimitives)
platforms(Platform.JVM)
} builderWith { primitive ->
} builderWith { _ ->
since("1.3")
visibility("internal")
annotation("@PublishedApi")
@@ -409,6 +409,7 @@ object Mapping : TemplateGroupBase() {
when (containerFamily) {
Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
Sequences -> include(Sequences, Iterables, ArraysOfObjects)
else -> {}
}
} builder {
inlineOnly()
@@ -447,6 +448,7 @@ object Mapping : TemplateGroupBase() {
when (containerFamily) {
Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
Sequences -> include(Sequences, Iterables, ArraysOfObjects)
else -> {}
}
} builder {
inlineOnly()
@@ -0,0 +1,12 @@
/*
* 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 templates
fun String.capitalize(): String =
replaceFirstChar(Char::uppercaseChar)
fun String.decapitalize(): String =
replaceFirstChar(Char::lowercaseChar)
@@ -361,6 +361,7 @@ class MemberBuilder(
when (inline) {
Inline.Only -> builder.append("@kotlin.internal.InlineOnly").append('\n')
Inline.YesSuppressWarning -> suppressions.add("NOTHING_TO_INLINE")
else -> {}
}
if (suppressions.isNotEmpty()) {
@@ -213,7 +213,7 @@ class PairPrimitiveMemberDefinition : MemberTemplateDefinition<Pair<PrimitiveTyp
}
init {
builderWith { (p1, p2) -> primitive = p1 }
builderWith { (p1, _) -> primitive = p1 }
}
}
@@ -75,40 +75,41 @@ fun List<MemberBuilder>.writeTo(file: File, targetedSource: TargetedSourceFile)
println("Generating file: $file")
file.parentFile.mkdirs()
FileWriter(file).use { writer ->
writer.appendln(COPYRIGHT_NOTICE)
writer.appendLine(COPYRIGHT_NOTICE)
when (target.platform) {
Platform.Common, Platform.JVM -> {
if (sourceFile.multifile) {
writer.appendln("@file:kotlin.jvm.JvmMultifileClass")
writer.appendLine("@file:kotlin.jvm.JvmMultifileClass")
}
writer.appendln("@file:kotlin.jvm.JvmName(\"${sourceFile.jvmClassName}\")")
writer.appendLine("@file:kotlin.jvm.JvmName(\"${sourceFile.jvmClassName}\")")
sourceFile.jvmPackageName?.let {
writer.appendln("@file:kotlin.jvm.JvmPackageName(\"$it\")")
writer.appendLine("@file:kotlin.jvm.JvmPackageName(\"$it\")")
}
writer.appendln()
writer.appendLine()
}
else -> {}
}
writer.append("package ${sourceFile.packageName ?: "kotlin"}\n\n")
writer.append("${autoGeneratedWarning("GenerateStandardLib.kt")}\n\n")
if (target.platform == Platform.JS) {
writer.appendln("import kotlin.js.*")
writer.appendLine("import kotlin.js.*")
if (sourceFile == SourceFile.Arrays) {
writer.appendln("import primitiveArrayConcat")
writer.appendln("import withType")
writer.appendLine("import primitiveArrayConcat")
writer.appendLine("import withType")
}
}
if (target.platform == Platform.Common) {
writer.appendln("import kotlin.random.*")
writer.appendLine("import kotlin.random.*")
}
if (sourceFile.packageName == "kotlin.collections") {
writer.appendln("import kotlin.ranges.contains")
writer.appendln("import kotlin.ranges.reversed")
writer.appendLine("import kotlin.ranges.contains")
writer.appendLine("import kotlin.ranges.reversed")
}
writer.appendln()
writer.appendLine()
for (f in this) {
f.build(writer)