Deprecate floating point to integral types lesser than Int #KT-30360

This commit is contained in:
Abduqodiri Qurbonzoda
2020-01-17 06:07:49 +03:00
parent e459542e6f
commit 1203df7405
14 changed files with 255 additions and 32 deletions
+9
View File
@@ -344,6 +344,10 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
}
private fun generateConversions(kind: PrimitiveType) {
fun isConversionDeprecated(otherKind: PrimitiveType): Boolean {
return kind in PrimitiveType.floatingPoint && otherKind in listOf(PrimitiveType.BYTE, PrimitiveType.SHORT)
}
val thisName = kind.capitalized
for (otherKind in PrimitiveType.exceptBoolean) {
val otherName = otherKind.capitalized
@@ -367,6 +371,11 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
" /**\n * Converts this [$thisName] value to [$otherName].\n *\n" + detail.replaceIndent(" ")
}
out.println(doc)
if (isConversionDeprecated(otherKind)) {
out.println(" @Deprecated(\"Unclear conversion. To achieve the same result convert to Int explicitly and then to $otherName.\", ReplaceWith(\"toInt().to$otherName()\"))")
}
out.println(" public override fun to$otherName(): $otherName")
}
}
+2 -1
View File
@@ -27,7 +27,8 @@ fun generate(): String {
val sb = StringBuilder()
val p = Printer(sb)
p.println(File("license/COPYRIGHT.txt").readText())
p.println("@file:Suppress(\"DEPRECATION_ERROR\")")
p.println("@file:Suppress(\"DEPRECATION\", \"DEPRECATION_ERROR\")")
p.println()
p.println("package org.jetbrains.kotlin.resolve.constants.evaluate")
p.println()