Map java.lang.Number methods to their Java equivalents

This commit is contained in:
Chris Smowton
2022-06-14 20:33:08 +01:00
parent d3fa4951f6
commit d390dc0316
5 changed files with 95 additions and 0 deletions

View File

@@ -90,6 +90,18 @@ open class KotlinUsesExtractor(
makeDescription(FqName("java.lang.Enum"), "<get-ordinal>") to "ordinal",
makeDescription(StandardNames.FqNames._enum.toSafe(), "<get-name>") to "name",
makeDescription(FqName("java.lang.Enum"), "<get-name>") to "name",
makeDescription(StandardNames.FqNames.number.toSafe(), "toByte") to "byteValue",
makeDescription(FqName("java.lang.Number"), "toByte") to "byteValue",
makeDescription(StandardNames.FqNames.number.toSafe(), "toShort") to "shortValue",
makeDescription(FqName("java.lang.Number"), "toShort") to "shortValue",
makeDescription(StandardNames.FqNames.number.toSafe(), "toInt") to "intValue",
makeDescription(FqName("java.lang.Number"), "toInt") to "intValue",
makeDescription(StandardNames.FqNames.number.toSafe(), "toLong") to "longValue",
makeDescription(FqName("java.lang.Number"), "toLong") to "longValue",
makeDescription(StandardNames.FqNames.number.toSafe(), "toFloat") to "floatValue",
makeDescription(FqName("java.lang.Number"), "toFloat") to "floatValue",
makeDescription(StandardNames.FqNames.number.toSafe(), "toDouble") to "doubleValue",
makeDescription(FqName("java.lang.Number"), "toDouble") to "doubleValue",
)
private val specialFunctionShortNames = specialFunctions.keys.map { it.functionName }.toSet()

View File

@@ -0,0 +1,27 @@
public class Test {
byte b;
short s;
int i;
long l;
float f;
double d;
public void test(Number n, Byte b2) {
b = n.byteValue();
s = n.shortValue();
i = n.intValue();
l = n.longValue();
f = n.floatValue();
d = n.doubleValue();
b = b2.byteValue();
s = b2.shortValue();
i = b2.intValue();
l = b2.longValue();
f = b2.floatValue();
d = b2.doubleValue();
}
}

View File

@@ -0,0 +1,50 @@
| java.lang.Byte | byteValue |
| java.lang.Byte | compare |
| java.lang.Byte | compareTo |
| java.lang.Byte | compareUnsigned |
| java.lang.Byte | decode |
| java.lang.Byte | describeConstable |
| java.lang.Byte | doubleValue |
| java.lang.Byte | equals |
| java.lang.Byte | floatValue |
| java.lang.Byte | hashCode |
| java.lang.Byte | intValue |
| java.lang.Byte | longValue |
| java.lang.Byte | parseByte |
| java.lang.Byte | shortValue |
| java.lang.Byte | toString |
| java.lang.Byte | toUnsignedInt |
| java.lang.Byte | toUnsignedLong |
| java.lang.Byte | valueOf |
| java.lang.Number | byteValue |
| java.lang.Number | doubleValue |
| java.lang.Number | floatValue |
| java.lang.Number | intValue |
| java.lang.Number | longValue |
| java.lang.Number | shortValue |
| kotlin.Byte | byteValue |
| kotlin.Byte | compareTo |
| kotlin.Byte | dec |
| kotlin.Byte | describeConstable |
| kotlin.Byte | div |
| kotlin.Byte | doubleValue |
| kotlin.Byte | floatValue |
| kotlin.Byte | inc |
| kotlin.Byte | intValue |
| kotlin.Byte | longValue |
| kotlin.Byte | minus |
| kotlin.Byte | plus |
| kotlin.Byte | rangeTo |
| kotlin.Byte | rem |
| kotlin.Byte | shortValue |
| kotlin.Byte | times |
| kotlin.Byte | toChar |
| kotlin.Byte | unaryMinus |
| kotlin.Byte | unaryPlus |
| kotlin.Number | byteValue |
| kotlin.Number | doubleValue |
| kotlin.Number | floatValue |
| kotlin.Number | intValue |
| kotlin.Number | longValue |
| kotlin.Number | shortValue |
| kotlin.Number | toChar |

View File

@@ -0,0 +1 @@
fun f(n: Number, b: Byte) = n.toByte() + n.toShort() + n.toInt() + n.toLong() + n.toFloat() + n.toDouble() + b.toByte() + b.toShort() + b.toInt() + b.toLong() + b.toFloat() + b.toDouble()

View File

@@ -0,0 +1,5 @@
import java
from Method m
where m.getDeclaringType().getName() = ["Number", "Byte"]
select m.getDeclaringType().getQualifiedName(), m.toString()