Skip to content

Commit 3f6925e

Browse files
authored
Merge pull request #9875 from smowton/smowton/fix/charat-naming
Kotlin: Special-case String.charAt naming
2 parents 3af2e71 + 715b0b3 commit 3f6925e

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

java/kotlin-extractor/src/main/kotlin/utils/JvmNames.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ private val specialFunctions = mapOf(
5151
makeDescription(FqName("java.lang.Number"), "toFloat") to "floatValue",
5252
makeDescription(StandardNames.FqNames.number.toSafe(), "toDouble") to "doubleValue",
5353
makeDescription(FqName("java.lang.Number"), "toDouble") to "doubleValue",
54+
makeDescription(StandardNames.FqNames.string.toSafe(), "get") to "charAt",
55+
makeDescription(FqName("java.lang.String"), "get") to "charAt",
5456
)
5557

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ reflection.kt:
88
# 46| 0: [TypeAccess] String
99
# 47| 5: [BlockStmt] { ... }
1010
# 47| 0: [ReturnStmt] return ...
11-
# 47| 0: [MethodAccess] get(...)
11+
# 47| 0: [MethodAccess] charAt(...)
1212
# 47| -1: [ExtensionReceiverAccess] this
1313
# 47| 0: [SubExpr] ... - ...
1414
# 47| 0: [MethodAccess] length(...)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Test {
2+
3+
public char f(String s) { return s.charAt(0); }
4+
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| Test.java:3:36:3:46 | charAt(...) |
2+
| test.kt:2:20:2:23 | charAt(...) |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
fun f(x: String) = x[0]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import java
2+
3+
from MethodAccess ma
4+
select ma

0 commit comments

Comments
 (0)