Skip to content

Commit 0d1380c

Browse files
committed
Fix warnings in generator modules
1 parent 2ca3adb commit 0d1380c

File tree

15 files changed

+57
-41
lines changed

15 files changed

+57
-41
lines changed

generators/builtins/arrays.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GenerateArrays(out: PrintWriter) : BuiltInsSourceGenerator(out) {
2525

2626
override fun generateBody() {
2727
for (kind in PrimitiveType.values()) {
28-
val typeLower = kind.name.toLowerCase()
28+
val typeLower = kind.name.lowercase()
2929
val s = kind.capitalized
3030
val defaultValue = when (kind) {
3131
PrimitiveType.CHAR -> "null char (`\\u0000')"

generators/builtins/common.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package org.jetbrains.kotlin.generators.builtins
77

8-
import org.jetbrains.kotlin.generators.builtins.ProgressionKind.*
8+
import org.jetbrains.kotlin.generators.builtins.ProgressionKind.CHAR
99
import java.io.PrintWriter
1010

1111
enum class PrimitiveType(val byteSize: Int) {
@@ -18,7 +18,7 @@ enum class PrimitiveType(val byteSize: Int) {
1818
DOUBLE(8),
1919
BOOLEAN(1);
2020

21-
val capitalized: String get() = name.toLowerCase().capitalize()
21+
val capitalized: String get() = name.lowercase().replaceFirstChar(Char::uppercase)
2222
val bitSize = byteSize * 8
2323

2424
val isFloatingPoint: Boolean get() = this in floatingPoint
@@ -38,7 +38,7 @@ enum class UnsignedType {
3838
UINT,
3939
ULONG;
4040

41-
val capitalized: String get() = name.substring(0, 2) + name.substring(2).toLowerCase()
41+
val capitalized: String get() = name.substring(0, 2) + name.substring(2).lowercase()
4242
val asSigned: PrimitiveType = PrimitiveType.valueOf(name.substring(1))
4343

4444
val byteSize = (1 shl ordinal)
@@ -51,7 +51,7 @@ enum class ProgressionKind {
5151
INT,
5252
LONG;
5353

54-
val capitalized: String get() = name.toLowerCase().capitalize()
54+
val capitalized: String get() = name.lowercase().replaceFirstChar(Char::uppercase)
5555
}
5656

5757
fun progressionIncrementType(kind: ProgressionKind) = when (kind) {
@@ -77,4 +77,4 @@ fun PrintWriter.printDoc(documentation: String, indent: String) {
7777
docLines.forEach { this.println("$indent * $it") }
7878
this.println("$indent */")
7979
}
80-
}
80+
}

generators/builtins/primitives.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
195195
private fun generateDoc(kind: PrimitiveType) {
196196
out.println("/**")
197197
out.println(" * Represents a ${typeDescriptions[kind]}.")
198-
out.println(" * On the JVM, non-nullable values of this type are represented as values of the primitive type `${kind.name.toLowerCase()}`.")
198+
out.println(" * On the JVM, non-nullable values of this type are represented as values of the primitive type `${kind.name.lowercase()}`.")
199199
out.println(" */")
200200
}
201201

generators/builtins/unsignedTypes.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
package org.jetbrains.kotlin.generators.builtins.unsigned
77

8-
9-
import org.jetbrains.kotlin.generators.builtins.*
8+
import org.jetbrains.kotlin.generators.builtins.PrimitiveType
9+
import org.jetbrains.kotlin.generators.builtins.UnsignedType
10+
import org.jetbrains.kotlin.generators.builtins.convert
1011
import org.jetbrains.kotlin.generators.builtins.generateBuiltIns.BuiltInsSourceGenerator
1112
import org.jetbrains.kotlin.generators.builtins.numbers.GeneratePrimitives
13+
import org.jetbrains.kotlin.generators.builtins.printDoc
1214
import java.io.File
1315
import java.io.PrintWriter
1416

15-
1617
fun generateUnsignedTypes(
1718
targetDir: File,
1819
generate: (File, (PrintWriter) -> BuiltInsSourceGenerator) -> Unit
@@ -134,7 +135,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
134135
if (otherType == type) out.print("override ")
135136
out.print("inline operator fun compareTo(other: ${otherType.capitalized}): Int = ")
136137
if (otherType == type && maxByDomainCapacity(type, UnsignedType.UINT) == type) {
137-
out.println("${className.toLowerCase()}Compare(this.data, other.data)")
138+
out.println("${className.lowercase()}Compare(this.data, other.data)")
138139
} else {
139140
if (maxOf(type, otherType) < UnsignedType.UINT) {
140141
out.println("this.toInt().compareTo(other.toInt())")
@@ -165,8 +166,8 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
165166
if (type == otherType && type == returnType) {
166167
when (name) {
167168
"plus", "minus", "times" -> out.println("$className(this.data.$name(other.data))")
168-
"div" -> out.println("${type.capitalized.toLowerCase()}Divide(this, other)")
169-
"rem" -> out.println("${type.capitalized.toLowerCase()}Remainder(this, other)")
169+
"div" -> out.println("${type.capitalized.lowercase()}Divide(this, other)")
170+
"rem" -> out.println("${type.capitalized.lowercase()}Remainder(this, other)")
170171
else -> error(name)
171172
}
172173
} else {
@@ -348,7 +349,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
348349
out.print(" public inline fun to$otherName(): $otherName = ")
349350
when (type) {
350351
UnsignedType.UINT, UnsignedType.ULONG ->
351-
out.println(if (otherType == PrimitiveType.FLOAT) "this.toDouble().toFloat()" else className.toLowerCase() + "ToDouble(data)")
352+
out.println(if (otherType == PrimitiveType.FLOAT) "this.toDouble().toFloat()" else className.lowercase() + "ToDouble(data)")
352353
else ->
353354
out.println("this.toInt().to$otherName()")
354355
}
@@ -466,7 +467,7 @@ class UnsignedIteratorsGenerator(out: PrintWriter) : BuiltInsSourceGenerator(out
466467
class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltInsSourceGenerator(out) {
467468
val elementType = type.capitalized
468469
val arrayType = elementType + "Array"
469-
val arrayTypeOf = elementType.toLowerCase() + "ArrayOf"
470+
val arrayTypeOf = elementType.lowercase() + "ArrayOf"
470471
val storageElementType = type.asSigned.capitalized
471472
val storageArrayType = storageElementType + "Array"
472473
override fun generateBody() {

generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ import org.jetbrains.kotlinx.serialization.AbstractSerializationPluginDiagnostic
4444
fun main(args: Array<String>) {
4545
System.setProperty("java.awt.headless", "true")
4646
generateTestGroupSuite(args) {
47-
val excludedFirTestdataPattern = "^(.+)\\.fir\\.kts?\$"
48-
4947
testGroup("compiler/incremental-compilation-impl/test", "jps-plugin/testData") {
5048
fun incrementalJvmTestData(targetBackend: TargetBackend): TestGroup.TestClass.() -> Unit = {
5149
model("incremental/pureKotlin", extension = null, recursive = false, targetBackend = targetBackend)

libraries/tools/kotlin-stdlib-gen/src/generators/GenerateStandardLib.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ fun main(args: Array<String>) {
3535
ComparableOps
3636
)
3737

38-
COPYRIGHT_NOTICE = readCopyrightNoticeFromProfile { Thread.currentThread().contextClassLoader.getResourceAsStream("apache.xml").reader() }
38+
COPYRIGHT_NOTICE =
39+
readCopyrightNoticeFromProfile { Thread.currentThread().contextClassLoader.getResourceAsStream("apache.xml")!!.reader() }
3940

4041
val targetBaseDirs = mutableMapOf<KotlinTarget, File>()
4142

@@ -62,7 +63,7 @@ fun main(args: Array<String>) {
6263
val platformSuffix = when (val platform = target.platform) {
6364
Platform.Common -> ""
6465
Platform.Native -> if (target.backend == Backend.Wasm) "Wasm" else "Native"
65-
else -> platform.name.toLowerCase().capitalize()
66+
else -> platform.name.lowercase().capitalize()
6667
}
6768
targetDir.resolve("_${source.name.capitalize()}$platformSuffix.kt")
6869
}
@@ -71,5 +72,5 @@ fun main(args: Array<String>) {
7172
fun File.resolveExistingDir(subpath: String) = resolve(subpath).also { it.requireExistingDir() }
7273

7374
fun File.requireExistingDir() {
74-
require(isDirectory) { "Directory $this doesn't exist"}
75+
require(isDirectory) { "Directory $this doesn't exist" }
7576
}

libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToMany/builders/OneToManyMappingsBuilder.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal abstract class OneToManyMappingsBuilder(bmpUnicodeDataLines: List<Unico
1919

2020
val charCode = line.char.hexToInt()
2121

22-
check(charCode <= Char.MAX_VALUE.toInt()) { "Handle special casing for the supplementary code point: $line" }
22+
check(charCode <= Char.MAX_VALUE.code) { "Handle special casing for the supplementary code point: $line" }
2323

2424
val mapping = mapping(charCode, line) ?: return
2525

@@ -55,4 +55,4 @@ internal abstract class OneToManyMappingsBuilder(bmpUnicodeDataLines: List<Unico
5555

5656
abstract fun SpecialCasingLine.mapping(): List<String>?
5757
abstract fun UnicodeDataLine.mapping(): String
58-
}
58+
}

libraries/tools/kotlin-stdlib-gen/src/generators/unicode/mappings/oneToOne/builders/MappingsBuilder.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal abstract class MappingsBuilder {
2424
val equivalent = mappingEquivalent(line)?.hexToInt() ?: return
2525
val mapping = equivalent - charCode
2626

27-
check((charCode > Char.MAX_VALUE.toInt()) == (equivalent > Char.MAX_VALUE.toInt())) { "Handle when equivalent mapping is out of BMP." }
27+
check((charCode > Char.MAX_VALUE.code) == (equivalent > Char.MAX_VALUE.code)) { "Handle when equivalent mapping is out of BMP." }
2828

2929
if (patterns.isEmpty()) {
3030
patterns.add(createPattern(charCode, line.categoryCode, mapping))
@@ -69,4 +69,4 @@ internal abstract class MappingsBuilder {
6969
private fun createPattern(charCode: Int, categoryCode: String, mapping: Int): MappingPattern {
7070
return EqualDistanceMappingPattern.from(charCode, categoryCode, mapping)
7171
}
72-
}
72+
}

libraries/tools/kotlin-stdlib-gen/src/generators/unicode/ranges/builders/LetterPatternBuilder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private fun periodPatternCategory(categoryIds: Array<String>): Int {
7373
return pattern
7474
}
7575

76-
private fun gapPatternCategory(start: Int, end: Int, gaps: List<GapRangePattern.Companion.Gap>): Int {
76+
private fun gapPatternCategory(start: Int, @Suppress("UNUSED_PARAMETER") end: Int, gaps: List<GapRangePattern.Companion.Gap>): Int {
7777
var pattern = 0
7878
var shift = 2
7979
for (i in gaps.indices) {

libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
@@ -680,7 +680,7 @@ object ArrayOps : TemplateGroupBase() {
680680
if (primitive == null)
681681
"return this.asDynamic().concat(arrayOf(element))"
682682
else
683-
"return plus(${primitive.name.toLowerCase()}ArrayOf(element))"
683+
"return plus(${primitive.name.lowercase()}ArrayOf(element))"
684684
}
685685
}
686686
on(Platform.Native) {
@@ -946,7 +946,7 @@ object ArrayOps : TemplateGroupBase() {
946946
val f_copyOfRangeJvmImpl = fn("copyOfRangeImpl(fromIndex: Int, toIndex: Int)") {
947947
include(InvariantArraysOfObjects, ArraysOfPrimitives)
948948
platforms(Platform.JVM)
949-
} builderWith { primitive ->
949+
} builderWith { _ ->
950950
since("1.3")
951951
visibility("internal")
952952
annotation("@PublishedApi")

libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ object Mapping : TemplateGroupBase() {
409409
when (containerFamily) {
410410
Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
411411
Sequences -> include(Sequences, Iterables, ArraysOfObjects)
412+
else -> {}
412413
}
413414
} builder {
414415
inlineOnly()
@@ -447,6 +448,7 @@ object Mapping : TemplateGroupBase() {
447448
when (containerFamily) {
448449
Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
449450
Sequences -> include(Sequences, Iterables, ArraysOfObjects)
451+
else -> {}
450452
}
451453
} builder {
452454
inlineOnly()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
package templates
7+
8+
fun String.capitalize(): String =
9+
replaceFirstChar(Char::uppercaseChar)
10+
11+
fun String.decapitalize(): String =
12+
replaceFirstChar(Char::lowercaseChar)

libraries/tools/kotlin-stdlib-gen/src/templates/dsl/MemberBuilder.kt

+1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ class MemberBuilder(
361361
when (inline) {
362362
Inline.Only -> builder.append("@kotlin.internal.InlineOnly").append('\n')
363363
Inline.YesSuppressWarning -> suppressions.add("NOTHING_TO_INLINE")
364+
else -> {}
364365
}
365366

366367
if (suppressions.isNotEmpty()) {

libraries/tools/kotlin-stdlib-gen/src/templates/dsl/Templates.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class PairPrimitiveMemberDefinition : MemberTemplateDefinition<Pair<PrimitiveTyp
213213
}
214214

215215
init {
216-
builderWith { (p1, p2) -> primitive = p1 }
216+
builderWith { (p1, _) -> primitive = p1 }
217217
}
218218
}
219219

libraries/tools/kotlin-stdlib-gen/src/templates/dsl/Writers.kt

+13-12
Original file line numberDiff line numberDiff line change
@@ -75,40 +75,41 @@ fun List<MemberBuilder>.writeTo(file: File, targetedSource: TargetedSourceFile)
7575
println("Generating file: $file")
7676
file.parentFile.mkdirs()
7777
FileWriter(file).use { writer ->
78-
writer.appendln(COPYRIGHT_NOTICE)
78+
writer.appendLine(COPYRIGHT_NOTICE)
7979

8080
when (target.platform) {
8181
Platform.Common, Platform.JVM -> {
8282
if (sourceFile.multifile) {
83-
writer.appendln("@file:kotlin.jvm.JvmMultifileClass")
83+
writer.appendLine("@file:kotlin.jvm.JvmMultifileClass")
8484
}
8585

86-
writer.appendln("@file:kotlin.jvm.JvmName(\"${sourceFile.jvmClassName}\")")
86+
writer.appendLine("@file:kotlin.jvm.JvmName(\"${sourceFile.jvmClassName}\")")
8787
sourceFile.jvmPackageName?.let {
88-
writer.appendln("@file:kotlin.jvm.JvmPackageName(\"$it\")")
88+
writer.appendLine("@file:kotlin.jvm.JvmPackageName(\"$it\")")
8989
}
90-
writer.appendln()
90+
writer.appendLine()
9191
}
92+
else -> {}
9293
}
9394

9495
writer.append("package ${sourceFile.packageName ?: "kotlin"}\n\n")
9596
writer.append("${autoGeneratedWarning("GenerateStandardLib.kt")}\n\n")
9697
if (target.platform == Platform.JS) {
97-
writer.appendln("import kotlin.js.*")
98+
writer.appendLine("import kotlin.js.*")
9899
if (sourceFile == SourceFile.Arrays) {
99-
writer.appendln("import primitiveArrayConcat")
100-
writer.appendln("import withType")
100+
writer.appendLine("import primitiveArrayConcat")
101+
writer.appendLine("import withType")
101102
}
102103
}
103104
if (target.platform == Platform.Common) {
104-
writer.appendln("import kotlin.random.*")
105+
writer.appendLine("import kotlin.random.*")
105106
}
106107
if (sourceFile.packageName == "kotlin.collections") {
107-
writer.appendln("import kotlin.ranges.contains")
108-
writer.appendln("import kotlin.ranges.reversed")
108+
writer.appendLine("import kotlin.ranges.contains")
109+
writer.appendLine("import kotlin.ranges.reversed")
109110
}
110111

111-
writer.appendln()
112+
writer.appendLine()
112113

113114
for (f in this) {
114115
f.build(writer)

0 commit comments

Comments
 (0)