Kotlin: Special-case String.charAt naming

In the Kotlin universe this is called `get` so that Kotlin programmers can use the `[]` operator on `String`s.
This commit is contained in:
Chris Smowton
2022-07-19 14:48:00 +01:00
parent 4d0f6a0b96
commit 9593ceeda5
5 changed files with 15 additions and 0 deletions

View File

@@ -51,6 +51,8 @@ private val specialFunctions = mapOf(
makeDescription(FqName("java.lang.Number"), "toFloat") to "floatValue", makeDescription(FqName("java.lang.Number"), "toFloat") to "floatValue",
makeDescription(StandardNames.FqNames.number.toSafe(), "toDouble") to "doubleValue", makeDescription(StandardNames.FqNames.number.toSafe(), "toDouble") to "doubleValue",
makeDescription(FqName("java.lang.Number"), "toDouble") to "doubleValue", makeDescription(FqName("java.lang.Number"), "toDouble") to "doubleValue",
makeDescription(StandardNames.FqNames.string.toSafe(), "get") to "charAt",
makeDescription(FqName("java.lang.String"), "get") to "charAt",
) )
private val specialFunctionShortNames = specialFunctions.keys.map { it.functionName }.toSet() private val specialFunctionShortNames = specialFunctions.keys.map { it.functionName }.toSet()

View File

@@ -0,0 +1,5 @@
public class Test {
public char f(String s) { return s.charAt(0); }
}

View File

@@ -0,0 +1,2 @@
| Test.java:3:36:3:46 | charAt(...) |
| test.kt:2:20:2:23 | charAt(...) |

View File

@@ -0,0 +1,2 @@
fun f(x: String) = x[0]

View File

@@ -0,0 +1,4 @@
import java
from MethodAccess ma
select ma