Skip to content

Commit 483281e

Browse files
authored
Merge pull request #9554 from smowton/smowton/fix/rename-removeat
Kotlin: Add more Kotlin <-> Java special method name mappings
2 parents c478287 + efbe264 commit 483281e

File tree

16 files changed

+221
-66
lines changed

16 files changed

+221
-66
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,33 @@ open class KotlinUsesExtractor(
8383
makeDescription(StandardNames.FqNames.map, "<get-values>") to "values",
8484
makeDescription(FqName("java.util.Map"), "<get-values>") to "values",
8585
makeDescription(StandardNames.FqNames.map, "<get-entries>") to "entrySet",
86-
makeDescription(FqName("java.util.Map"), "<get-entries>") to "entrySet"
86+
makeDescription(FqName("java.util.Map"), "<get-entries>") to "entrySet",
87+
makeDescription(StandardNames.FqNames.mutableList, "removeAt") to "remove",
88+
makeDescription(FqName("java.util.List"), "removeAt") to "remove",
89+
makeDescription(StandardNames.FqNames._enum.toSafe(), "<get-ordinal>") to "ordinal",
90+
makeDescription(FqName("java.lang.Enum"), "<get-ordinal>") to "ordinal",
91+
makeDescription(StandardNames.FqNames._enum.toSafe(), "<get-name>") to "name",
92+
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",
87105
)
88106

89107
private val specialFunctionShortNames = specialFunctions.keys.map { it.functionName }.toSet()
90108

91109
fun getSpecialJvmName(f: IrFunction): String? {
92110
if (specialFunctionShortNames.contains(f.name) && f is IrSimpleFunction) {
93111
f.allOverridden(true).forEach { overriddenFunc ->
94-
overriddenFunc.parentAsClass.fqNameWhenAvailable?.let { parentFqName ->
112+
overriddenFunc.parentClassOrNull?.fqNameWhenAvailable?.let { parentFqName ->
95113
specialFunctions[MethodKey(parentFqName, f.name)]?.let {
96114
return it
97115
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fun usesEnum(e: Enum<*>) = e.ordinal.toString() + e.name
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
| addAll |
2+
| addRange |
3+
| allOf |
4+
| asIterator |
5+
| clone |
6+
| compareTo |
7+
| complement |
8+
| complementOf |
9+
| copyOf |
10+
| describeConstable |
11+
| equals |
12+
| finalize |
13+
| getDeclaringClass |
14+
| hasMoreElements |
15+
| hashCode |
16+
| name |
17+
| nextElement |
18+
| noneOf |
19+
| of |
20+
| ordinal |
21+
| range |
22+
| resolveConstantDesc |
23+
| toString |
24+
| typeCheck |
25+
| usesEnum |
26+
| valueOf |
27+
| writeReplace |
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().matches("Enum%")
5+
select m.getName()

java/ql/test/kotlin/library-tests/exprs/PrintAst.expected

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,44 +2057,44 @@ exprs.kt:
20572057
# 39| 27: [LocalVariableDeclStmt] var ...;
20582058
# 39| 1: [LocalVariableDeclExpr] by6
20592059
# 39| 0: [ValueEQExpr] ... (value equals) ...
2060-
# 39| 0: [MethodAccess] toInt(...)
2060+
# 39| 0: [MethodAccess] intValue(...)
20612061
# 39| -1: [VarAccess] byx
2062-
# 39| 1: [MethodAccess] toInt(...)
2062+
# 39| 1: [MethodAccess] intValue(...)
20632063
# 39| -1: [VarAccess] byy
20642064
# 40| 28: [LocalVariableDeclStmt] var ...;
20652065
# 40| 1: [LocalVariableDeclExpr] by7
20662066
# 40| 0: [ValueNEExpr] ... (value not-equals) ...
2067-
# 40| 0: [MethodAccess] toInt(...)
2067+
# 40| 0: [MethodAccess] intValue(...)
20682068
# 40| -1: [VarAccess] byx
2069-
# 40| 1: [MethodAccess] toInt(...)
2069+
# 40| 1: [MethodAccess] intValue(...)
20702070
# 40| -1: [VarAccess] byy
20712071
# 41| 29: [LocalVariableDeclStmt] var ...;
20722072
# 41| 1: [LocalVariableDeclExpr] by8
20732073
# 41| 0: [LTExpr] ... < ...
2074-
# 41| 0: [MethodAccess] toInt(...)
2074+
# 41| 0: [MethodAccess] intValue(...)
20752075
# 41| -1: [VarAccess] byx
2076-
# 41| 1: [MethodAccess] toInt(...)
2076+
# 41| 1: [MethodAccess] intValue(...)
20772077
# 41| -1: [VarAccess] byy
20782078
# 42| 30: [LocalVariableDeclStmt] var ...;
20792079
# 42| 1: [LocalVariableDeclExpr] by9
20802080
# 42| 0: [LEExpr] ... <= ...
2081-
# 42| 0: [MethodAccess] toInt(...)
2081+
# 42| 0: [MethodAccess] intValue(...)
20822082
# 42| -1: [VarAccess] byx
2083-
# 42| 1: [MethodAccess] toInt(...)
2083+
# 42| 1: [MethodAccess] intValue(...)
20842084
# 42| -1: [VarAccess] byy
20852085
# 43| 31: [LocalVariableDeclStmt] var ...;
20862086
# 43| 1: [LocalVariableDeclExpr] by10
20872087
# 43| 0: [GTExpr] ... > ...
2088-
# 43| 0: [MethodAccess] toInt(...)
2088+
# 43| 0: [MethodAccess] intValue(...)
20892089
# 43| -1: [VarAccess] byx
2090-
# 43| 1: [MethodAccess] toInt(...)
2090+
# 43| 1: [MethodAccess] intValue(...)
20912091
# 43| -1: [VarAccess] byy
20922092
# 44| 32: [LocalVariableDeclStmt] var ...;
20932093
# 44| 1: [LocalVariableDeclExpr] by11
20942094
# 44| 0: [GEExpr] ... >= ...
2095-
# 44| 0: [MethodAccess] toInt(...)
2095+
# 44| 0: [MethodAccess] intValue(...)
20962096
# 44| -1: [VarAccess] byx
2097-
# 44| 1: [MethodAccess] toInt(...)
2097+
# 44| 1: [MethodAccess] intValue(...)
20982098
# 44| -1: [VarAccess] byy
20992099
# 45| 33: [LocalVariableDeclStmt] var ...;
21002100
# 45| 1: [LocalVariableDeclExpr] by12
@@ -2132,44 +2132,44 @@ exprs.kt:
21322132
# 53| 40: [LocalVariableDeclStmt] var ...;
21332133
# 53| 1: [LocalVariableDeclExpr] s6
21342134
# 53| 0: [ValueEQExpr] ... (value equals) ...
2135-
# 53| 0: [MethodAccess] toInt(...)
2135+
# 53| 0: [MethodAccess] intValue(...)
21362136
# 53| -1: [VarAccess] sx
2137-
# 53| 1: [MethodAccess] toInt(...)
2137+
# 53| 1: [MethodAccess] intValue(...)
21382138
# 53| -1: [VarAccess] sy
21392139
# 54| 41: [LocalVariableDeclStmt] var ...;
21402140
# 54| 1: [LocalVariableDeclExpr] s7
21412141
# 54| 0: [ValueNEExpr] ... (value not-equals) ...
2142-
# 54| 0: [MethodAccess] toInt(...)
2142+
# 54| 0: [MethodAccess] intValue(...)
21432143
# 54| -1: [VarAccess] sx
2144-
# 54| 1: [MethodAccess] toInt(...)
2144+
# 54| 1: [MethodAccess] intValue(...)
21452145
# 54| -1: [VarAccess] sy
21462146
# 55| 42: [LocalVariableDeclStmt] var ...;
21472147
# 55| 1: [LocalVariableDeclExpr] s8
21482148
# 55| 0: [LTExpr] ... < ...
2149-
# 55| 0: [MethodAccess] toInt(...)
2149+
# 55| 0: [MethodAccess] intValue(...)
21502150
# 55| -1: [VarAccess] sx
2151-
# 55| 1: [MethodAccess] toInt(...)
2151+
# 55| 1: [MethodAccess] intValue(...)
21522152
# 55| -1: [VarAccess] sy
21532153
# 56| 43: [LocalVariableDeclStmt] var ...;
21542154
# 56| 1: [LocalVariableDeclExpr] s9
21552155
# 56| 0: [LEExpr] ... <= ...
2156-
# 56| 0: [MethodAccess] toInt(...)
2156+
# 56| 0: [MethodAccess] intValue(...)
21572157
# 56| -1: [VarAccess] sx
2158-
# 56| 1: [MethodAccess] toInt(...)
2158+
# 56| 1: [MethodAccess] intValue(...)
21592159
# 56| -1: [VarAccess] sy
21602160
# 57| 44: [LocalVariableDeclStmt] var ...;
21612161
# 57| 1: [LocalVariableDeclExpr] s10
21622162
# 57| 0: [GTExpr] ... > ...
2163-
# 57| 0: [MethodAccess] toInt(...)
2163+
# 57| 0: [MethodAccess] intValue(...)
21642164
# 57| -1: [VarAccess] sx
2165-
# 57| 1: [MethodAccess] toInt(...)
2165+
# 57| 1: [MethodAccess] intValue(...)
21662166
# 57| -1: [VarAccess] sy
21672167
# 58| 45: [LocalVariableDeclStmt] var ...;
21682168
# 58| 1: [LocalVariableDeclExpr] s11
21692169
# 58| 0: [GEExpr] ... >= ...
2170-
# 58| 0: [MethodAccess] toInt(...)
2170+
# 58| 0: [MethodAccess] intValue(...)
21712171
# 58| -1: [VarAccess] sx
2172-
# 58| 1: [MethodAccess] toInt(...)
2172+
# 58| 1: [MethodAccess] intValue(...)
21732173
# 58| -1: [VarAccess] sy
21742174
# 59| 46: [LocalVariableDeclStmt] var ...;
21752175
# 59| 1: [LocalVariableDeclExpr] s12

java/ql/test/kotlin/library-tests/exprs/binop.expected

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414
| exprs.kt:36:15:36:23 | ... - ... | exprs.kt:36:15:36:17 | byx | exprs.kt:36:21:36:23 | byy |
1515
| exprs.kt:37:15:37:23 | ... / ... | exprs.kt:37:15:37:17 | byx | exprs.kt:37:21:37:23 | byy |
1616
| exprs.kt:38:15:38:23 | ... % ... | exprs.kt:38:15:38:17 | byx | exprs.kt:38:21:38:23 | byy |
17-
| exprs.kt:39:15:39:24 | ... (value equals) ... | exprs.kt:39:15:39:17 | toInt(...) | exprs.kt:39:22:39:24 | toInt(...) |
18-
| exprs.kt:40:15:40:24 | ... (value not-equals) ... | exprs.kt:40:15:40:17 | toInt(...) | exprs.kt:40:22:40:24 | toInt(...) |
19-
| exprs.kt:41:15:41:23 | ... < ... | exprs.kt:41:15:41:17 | toInt(...) | exprs.kt:41:21:41:23 | toInt(...) |
20-
| exprs.kt:42:15:42:24 | ... <= ... | exprs.kt:42:15:42:17 | toInt(...) | exprs.kt:42:22:42:24 | toInt(...) |
21-
| exprs.kt:43:16:43:24 | ... > ... | exprs.kt:43:16:43:18 | toInt(...) | exprs.kt:43:22:43:24 | toInt(...) |
22-
| exprs.kt:44:16:44:25 | ... >= ... | exprs.kt:44:16:44:18 | toInt(...) | exprs.kt:44:23:44:25 | toInt(...) |
17+
| exprs.kt:39:15:39:24 | ... (value equals) ... | exprs.kt:39:15:39:17 | intValue(...) | exprs.kt:39:22:39:24 | intValue(...) |
18+
| exprs.kt:40:15:40:24 | ... (value not-equals) ... | exprs.kt:40:15:40:17 | intValue(...) | exprs.kt:40:22:40:24 | intValue(...) |
19+
| exprs.kt:41:15:41:23 | ... < ... | exprs.kt:41:15:41:17 | intValue(...) | exprs.kt:41:21:41:23 | intValue(...) |
20+
| exprs.kt:42:15:42:24 | ... <= ... | exprs.kt:42:15:42:17 | intValue(...) | exprs.kt:42:22:42:24 | intValue(...) |
21+
| exprs.kt:43:16:43:24 | ... > ... | exprs.kt:43:16:43:18 | intValue(...) | exprs.kt:43:22:43:24 | intValue(...) |
22+
| exprs.kt:44:16:44:25 | ... >= ... | exprs.kt:44:16:44:18 | intValue(...) | exprs.kt:44:23:44:25 | intValue(...) |
2323
| exprs.kt:45:16:45:26 | ... == ... | exprs.kt:45:16:45:18 | byx | exprs.kt:45:24:45:26 | byy |
2424
| exprs.kt:46:16:46:26 | ... != ... | exprs.kt:46:16:46:18 | byx | exprs.kt:46:24:46:26 | byy |
2525
| exprs.kt:49:14:49:20 | ... + ... | exprs.kt:49:14:49:15 | sx | exprs.kt:49:19:49:20 | sy |
2626
| exprs.kt:50:14:50:20 | ... - ... | exprs.kt:50:14:50:15 | sx | exprs.kt:50:19:50:20 | sy |
2727
| exprs.kt:51:14:51:20 | ... / ... | exprs.kt:51:14:51:15 | sx | exprs.kt:51:19:51:20 | sy |
2828
| exprs.kt:52:14:52:20 | ... % ... | exprs.kt:52:14:52:15 | sx | exprs.kt:52:19:52:20 | sy |
29-
| exprs.kt:53:14:53:21 | ... (value equals) ... | exprs.kt:53:14:53:15 | toInt(...) | exprs.kt:53:20:53:21 | toInt(...) |
30-
| exprs.kt:54:14:54:21 | ... (value not-equals) ... | exprs.kt:54:14:54:15 | toInt(...) | exprs.kt:54:20:54:21 | toInt(...) |
31-
| exprs.kt:55:14:55:20 | ... < ... | exprs.kt:55:14:55:15 | toInt(...) | exprs.kt:55:19:55:20 | toInt(...) |
32-
| exprs.kt:56:14:56:21 | ... <= ... | exprs.kt:56:14:56:15 | toInt(...) | exprs.kt:56:20:56:21 | toInt(...) |
33-
| exprs.kt:57:15:57:21 | ... > ... | exprs.kt:57:15:57:16 | toInt(...) | exprs.kt:57:20:57:21 | toInt(...) |
34-
| exprs.kt:58:15:58:22 | ... >= ... | exprs.kt:58:15:58:16 | toInt(...) | exprs.kt:58:21:58:22 | toInt(...) |
29+
| exprs.kt:53:14:53:21 | ... (value equals) ... | exprs.kt:53:14:53:15 | intValue(...) | exprs.kt:53:20:53:21 | intValue(...) |
30+
| exprs.kt:54:14:54:21 | ... (value not-equals) ... | exprs.kt:54:14:54:15 | intValue(...) | exprs.kt:54:20:54:21 | intValue(...) |
31+
| exprs.kt:55:14:55:20 | ... < ... | exprs.kt:55:14:55:15 | intValue(...) | exprs.kt:55:19:55:20 | intValue(...) |
32+
| exprs.kt:56:14:56:21 | ... <= ... | exprs.kt:56:14:56:15 | intValue(...) | exprs.kt:56:20:56:21 | intValue(...) |
33+
| exprs.kt:57:15:57:21 | ... > ... | exprs.kt:57:15:57:16 | intValue(...) | exprs.kt:57:20:57:21 | intValue(...) |
34+
| exprs.kt:58:15:58:22 | ... >= ... | exprs.kt:58:15:58:16 | intValue(...) | exprs.kt:58:21:58:22 | intValue(...) |
3535
| exprs.kt:59:15:59:23 | ... == ... | exprs.kt:59:15:59:16 | sx | exprs.kt:59:22:59:23 | sy |
3636
| exprs.kt:60:15:60:23 | ... != ... | exprs.kt:60:15:60:16 | sx | exprs.kt:60:22:60:23 | sy |
3737
| exprs.kt:63:14:63:20 | ... + ... | exprs.kt:63:14:63:15 | lx | exprs.kt:63:19:63:20 | ly |

0 commit comments

Comments
 (0)