Skip to content

Commit d390dc0

Browse files
committed
Map java.lang.Number methods to their Java equivalents
1 parent d3fa495 commit d390dc0

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ open class KotlinUsesExtractor(
9090
makeDescription(FqName("java.lang.Enum"), "<get-ordinal>") to "ordinal",
9191
makeDescription(StandardNames.FqNames._enum.toSafe(), "<get-name>") to "name",
9292
makeDescription(FqName("java.lang.Enum"), "<get-name>") to "name",
93+
makeDescription(StandardNames.FqNames.number.toSafe(), "toByte") to "byteValue",
94+
makeDescription(FqName("java.lang.Number"), "toByte") to "byteValue",
95+
makeDescription(StandardNames.FqNames.number.toSafe(), "toShort") to "shortValue",
96+
makeDescription(FqName("java.lang.Number"), "toShort") to "shortValue",
97+
makeDescription(StandardNames.FqNames.number.toSafe(), "toInt") to "intValue",
98+
makeDescription(FqName("java.lang.Number"), "toInt") to "intValue",
99+
makeDescription(StandardNames.FqNames.number.toSafe(), "toLong") to "longValue",
100+
makeDescription(FqName("java.lang.Number"), "toLong") to "longValue",
101+
makeDescription(StandardNames.FqNames.number.toSafe(), "toFloat") to "floatValue",
102+
makeDescription(FqName("java.lang.Number"), "toFloat") to "floatValue",
103+
makeDescription(StandardNames.FqNames.number.toSafe(), "toDouble") to "doubleValue",
104+
makeDescription(FqName("java.lang.Number"), "toDouble") to "doubleValue",
93105
)
94106

95107
private val specialFunctionShortNames = specialFunctions.keys.map { it.functionName }.toSet()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
public class Test {
2+
3+
byte b;
4+
short s;
5+
int i;
6+
long l;
7+
float f;
8+
double d;
9+
10+
public void test(Number n, Byte b2) {
11+
12+
b = n.byteValue();
13+
s = n.shortValue();
14+
i = n.intValue();
15+
l = n.longValue();
16+
f = n.floatValue();
17+
d = n.doubleValue();
18+
b = b2.byteValue();
19+
s = b2.shortValue();
20+
i = b2.intValue();
21+
l = b2.longValue();
22+
f = b2.floatValue();
23+
d = b2.doubleValue();
24+
25+
}
26+
27+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
| java.lang.Byte | byteValue |
2+
| java.lang.Byte | compare |
3+
| java.lang.Byte | compareTo |
4+
| java.lang.Byte | compareUnsigned |
5+
| java.lang.Byte | decode |
6+
| java.lang.Byte | describeConstable |
7+
| java.lang.Byte | doubleValue |
8+
| java.lang.Byte | equals |
9+
| java.lang.Byte | floatValue |
10+
| java.lang.Byte | hashCode |
11+
| java.lang.Byte | intValue |
12+
| java.lang.Byte | longValue |
13+
| java.lang.Byte | parseByte |
14+
| java.lang.Byte | shortValue |
15+
| java.lang.Byte | toString |
16+
| java.lang.Byte | toUnsignedInt |
17+
| java.lang.Byte | toUnsignedLong |
18+
| java.lang.Byte | valueOf |
19+
| java.lang.Number | byteValue |
20+
| java.lang.Number | doubleValue |
21+
| java.lang.Number | floatValue |
22+
| java.lang.Number | intValue |
23+
| java.lang.Number | longValue |
24+
| java.lang.Number | shortValue |
25+
| kotlin.Byte | byteValue |
26+
| kotlin.Byte | compareTo |
27+
| kotlin.Byte | dec |
28+
| kotlin.Byte | describeConstable |
29+
| kotlin.Byte | div |
30+
| kotlin.Byte | doubleValue |
31+
| kotlin.Byte | floatValue |
32+
| kotlin.Byte | inc |
33+
| kotlin.Byte | intValue |
34+
| kotlin.Byte | longValue |
35+
| kotlin.Byte | minus |
36+
| kotlin.Byte | plus |
37+
| kotlin.Byte | rangeTo |
38+
| kotlin.Byte | rem |
39+
| kotlin.Byte | shortValue |
40+
| kotlin.Byte | times |
41+
| kotlin.Byte | toChar |
42+
| kotlin.Byte | unaryMinus |
43+
| kotlin.Byte | unaryPlus |
44+
| kotlin.Number | byteValue |
45+
| kotlin.Number | doubleValue |
46+
| kotlin.Number | floatValue |
47+
| kotlin.Number | intValue |
48+
| kotlin.Number | longValue |
49+
| kotlin.Number | shortValue |
50+
| kotlin.Number | toChar |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java
2+
3+
from Method m
4+
where m.getDeclaringType().getName() = ["Number", "Byte"]
5+
select m.getDeclaringType().getQualifiedName(), m.toString()

0 commit comments

Comments
 (0)