diff --git a/js/js.libraries/src/core/generated/_RangesJs.kt b/js/js.libraries/src/core/generated/_RangesJs.kt index 9ece065e5e9..efa4361e292 100644 --- a/js/js.libraries/src/core/generated/_RangesJs.kt +++ b/js/js.libraries/src/core/generated/_RangesJs.kt @@ -652,6 +652,7 @@ public infix fun Short.until(to: Short): IntRange { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun > T.coerceAtLeast(minimumValue: T): T { return if (this < minimumValue) minimumValue else this @@ -661,6 +662,7 @@ public fun > T.coerceAtLeast(minimumValue: T): T { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Byte.coerceAtLeast(minimumValue: Byte): Byte { return if (this < minimumValue) minimumValue else this @@ -670,6 +672,7 @@ public fun Byte.coerceAtLeast(minimumValue: Byte): Byte { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Short.coerceAtLeast(minimumValue: Short): Short { return if (this < minimumValue) minimumValue else this @@ -679,6 +682,7 @@ public fun Short.coerceAtLeast(minimumValue: Short): Short { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Int.coerceAtLeast(minimumValue: Int): Int { return if (this < minimumValue) minimumValue else this @@ -688,6 +692,7 @@ public fun Int.coerceAtLeast(minimumValue: Int): Int { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Long.coerceAtLeast(minimumValue: Long): Long { return if (this < minimumValue) minimumValue else this @@ -697,6 +702,7 @@ public fun Long.coerceAtLeast(minimumValue: Long): Long { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Float.coerceAtLeast(minimumValue: Float): Float { return if (this < minimumValue) minimumValue else this @@ -706,6 +712,7 @@ public fun Float.coerceAtLeast(minimumValue: Float): Float { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Double.coerceAtLeast(minimumValue: Double): Double { return if (this < minimumValue) minimumValue else this diff --git a/libraries/stdlib/common/src/generated/_Ranges.kt b/libraries/stdlib/common/src/generated/_Ranges.kt index d791999d478..ac23056bf72 100644 --- a/libraries/stdlib/common/src/generated/_Ranges.kt +++ b/libraries/stdlib/common/src/generated/_Ranges.kt @@ -472,6 +472,7 @@ public expect infix fun Short.until(to: Short): IntRange * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public expect fun > T.coerceAtLeast(minimumValue: T): T @@ -479,6 +480,7 @@ public expect fun > T.coerceAtLeast(minimumValue: T): T * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public expect fun Byte.coerceAtLeast(minimumValue: Byte): Byte @@ -486,6 +488,7 @@ public expect fun Byte.coerceAtLeast(minimumValue: Byte): Byte * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public expect fun Short.coerceAtLeast(minimumValue: Short): Short @@ -493,6 +496,7 @@ public expect fun Short.coerceAtLeast(minimumValue: Short): Short * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public expect fun Int.coerceAtLeast(minimumValue: Int): Int @@ -500,6 +504,7 @@ public expect fun Int.coerceAtLeast(minimumValue: Int): Int * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public expect fun Long.coerceAtLeast(minimumValue: Long): Long @@ -507,6 +512,7 @@ public expect fun Long.coerceAtLeast(minimumValue: Long): Long * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public expect fun Float.coerceAtLeast(minimumValue: Float): Float @@ -514,6 +520,7 @@ public expect fun Float.coerceAtLeast(minimumValue: Float): Float * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public expect fun Double.coerceAtLeast(minimumValue: Double): Double diff --git a/libraries/stdlib/samples/test/samples/comparisons/comparableOps.kt b/libraries/stdlib/samples/test/samples/comparisons/comparableOps.kt new file mode 100644 index 00000000000..f4b13a1b8e3 --- /dev/null +++ b/libraries/stdlib/samples/test/samples/comparisons/comparableOps.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package samples.comparisons + +import samples.* + +class ComparableOps { + + @Sample + fun coerceAtLeast() { + assertPrints(10.coerceAtLeast(5), "10") + assertPrints(10.coerceAtLeast(20), "20") + } + +} \ No newline at end of file diff --git a/libraries/stdlib/src/generated/_Ranges.kt b/libraries/stdlib/src/generated/_Ranges.kt index ed896042870..ece90d70739 100644 --- a/libraries/stdlib/src/generated/_Ranges.kt +++ b/libraries/stdlib/src/generated/_Ranges.kt @@ -652,6 +652,7 @@ public infix fun Short.until(to: Short): IntRange { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun > T.coerceAtLeast(minimumValue: T): T { return if (this < minimumValue) minimumValue else this @@ -661,6 +662,7 @@ public fun > T.coerceAtLeast(minimumValue: T): T { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Byte.coerceAtLeast(minimumValue: Byte): Byte { return if (this < minimumValue) minimumValue else this @@ -670,6 +672,7 @@ public fun Byte.coerceAtLeast(minimumValue: Byte): Byte { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Short.coerceAtLeast(minimumValue: Short): Short { return if (this < minimumValue) minimumValue else this @@ -679,6 +682,7 @@ public fun Short.coerceAtLeast(minimumValue: Short): Short { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Int.coerceAtLeast(minimumValue: Int): Int { return if (this < minimumValue) minimumValue else this @@ -688,6 +692,7 @@ public fun Int.coerceAtLeast(minimumValue: Int): Int { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Long.coerceAtLeast(minimumValue: Long): Long { return if (this < minimumValue) minimumValue else this @@ -697,6 +702,7 @@ public fun Long.coerceAtLeast(minimumValue: Long): Long { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Float.coerceAtLeast(minimumValue: Float): Float { return if (this < minimumValue) minimumValue else this @@ -706,6 +712,7 @@ public fun Float.coerceAtLeast(minimumValue: Float): Float { * Ensures that this value is not less than the specified [minimumValue]. * * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + * @sample samples.comparisons.ComparableOps.coerceAtLeast */ public fun Double.coerceAtLeast(minimumValue: Double): Double { return if (this < minimumValue) minimumValue else this diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt index af53cc5de70..fd53ba89bb1 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt @@ -36,6 +36,7 @@ object ComparableOps : TemplateGroupBase() { Ensures that this value is not less than the specified [minimumValue]. @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise. + @sample samples.comparisons.ComparableOps.coerceAtLeast """ } body {