Improve toString() for lambdas and function expressions
#KT-9952 Fixed
This commit is contained in:
@@ -19,6 +19,5 @@ package kotlin.jvm.internal
|
||||
abstract class Lambda(private val arity: Int) : FunctionImpl() {
|
||||
override fun getArity() = arity
|
||||
|
||||
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
override fun toString() = "${(this as Object).`class`.genericInterfaces[0]}"
|
||||
override fun toString() = Reflection.renderLambdaToString(this)
|
||||
}
|
||||
|
||||
@@ -74,6 +74,10 @@ public class Reflection {
|
||||
return kClasses;
|
||||
}
|
||||
|
||||
public static String renderLambdaToString(Lambda lambda) {
|
||||
return factory.renderLambdaToString(lambda);
|
||||
}
|
||||
|
||||
// Functions
|
||||
|
||||
public static KFunction function(FunctionReference f) {
|
||||
|
||||
@@ -19,6 +19,8 @@ package kotlin.jvm.internal;
|
||||
import kotlin.reflect.*;
|
||||
|
||||
public class ReflectionFactory {
|
||||
private static final String KOTLIN_JVM_FUNCTIONS = "kotlin.jvm.functions.";
|
||||
|
||||
public KClass createKotlinClass(Class javaClass) {
|
||||
return new ClassReference(javaClass);
|
||||
}
|
||||
@@ -39,6 +41,11 @@ public class ReflectionFactory {
|
||||
return new ClassReference(javaClass);
|
||||
}
|
||||
|
||||
public String renderLambdaToString(Lambda lambda) {
|
||||
String result = lambda.getClass().getGenericInterfaces()[0].toString();
|
||||
return result.startsWith(KOTLIN_JVM_FUNCTIONS) ? result.substring(KOTLIN_JVM_FUNCTIONS.length()) : result;
|
||||
}
|
||||
|
||||
// Functions
|
||||
|
||||
public KFunction function(FunctionReference f) {
|
||||
|
||||
Reference in New Issue
Block a user