Expand KDoc of inc() and dec() operators #KT-43701
This commit is contained in:
@@ -20,9 +20,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
"div",
|
||||
"rem",
|
||||
)
|
||||
internal val unaryOperators: Map<String, String> = mapOf(
|
||||
"inc" to "Increments this value.",
|
||||
"dec" to "Decrements this value.",
|
||||
internal val unaryPlusMinusOperators: Map<String, String> = mapOf(
|
||||
"unaryPlus" to "Returns this value.",
|
||||
"unaryMinus" to "Returns the negative of this value.")
|
||||
internal val shiftOperators: Map<String, String> = mapOf(
|
||||
@@ -47,6 +45,18 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
"""
|
||||
}
|
||||
|
||||
internal fun incDecOperatorsDoc(name: String): String {
|
||||
val diff = if (name == "inc") "incremented" else "decremented"
|
||||
|
||||
return """
|
||||
/**
|
||||
* Returns this value $diff by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.$name
|
||||
*/
|
||||
"""
|
||||
}
|
||||
|
||||
internal fun binaryOperatorDoc(operator: String, operand1: PrimitiveType, operand2: PrimitiveType): String = when (operator) {
|
||||
"plus" -> "Adds the other value to this value."
|
||||
"minus" -> "Subtracts the other value from this value."
|
||||
@@ -239,9 +249,14 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
}
|
||||
|
||||
private fun generateUnaryOperators(kind: PrimitiveType) {
|
||||
for ((name, doc) in unaryOperators) {
|
||||
val returnType = if (kind in listOf(PrimitiveType.SHORT, PrimitiveType.BYTE, PrimitiveType.CHAR) &&
|
||||
name in listOf("unaryPlus", "unaryMinus")) "Int" else kind.capitalized
|
||||
for (name in listOf("inc", "dec")) {
|
||||
out.println(incDecOperatorsDoc(name).replaceIndent(" "))
|
||||
out.println(" public operator fun $name(): ${kind.capitalized}")
|
||||
out.println()
|
||||
}
|
||||
|
||||
for ((name, doc) in unaryPlusMinusOperators) {
|
||||
val returnType = if (kind in listOf(PrimitiveType.SHORT, PrimitiveType.BYTE, PrimitiveType.CHAR)) "Int" else kind.capitalized
|
||||
out.println(" /** $doc */")
|
||||
out.println(" public operator fun $name(): $returnType")
|
||||
}
|
||||
|
||||
@@ -204,14 +204,12 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
|
||||
|
||||
|
||||
private fun generateUnaryOperators() {
|
||||
for ((name, doc) in GeneratePrimitives.unaryOperators) {
|
||||
if (name in listOf("unaryPlus", "unaryMinus")) continue
|
||||
out.println(" /** $doc */")
|
||||
for (name in listOf("inc", "dec")) {
|
||||
out.println(GeneratePrimitives.incDecOperatorsDoc(name).replaceIndent(" "))
|
||||
out.println(" @kotlin.internal.InlineOnly")
|
||||
out.println(" public inline operator fun $name(): $className = $className(data.$name())")
|
||||
|
||||
out.println()
|
||||
}
|
||||
out.println()
|
||||
}
|
||||
|
||||
private fun generateRangeTo() {
|
||||
|
||||
Reference in New Issue
Block a user