From d5da130d4bce6ce246cef4e3d48c06728fcbdadf Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 1 Dec 2021 17:28:28 +0300 Subject: [PATCH] KT-47939 FunInterfaceConstructorReference --- .../FunInterfaceConstructorReference.java | 57 +++++++++++++++++++ .../kotlin-stdlib-runtime-merged.txt | 9 +++ 2 files changed, 66 insertions(+) create mode 100644 libraries/stdlib/jvm/runtime/kotlin/jvm/internal/FunInterfaceConstructorReference.java diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/FunInterfaceConstructorReference.java b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/FunInterfaceConstructorReference.java new file mode 100644 index 00000000000..33ddabfdba4 --- /dev/null +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/FunInterfaceConstructorReference.java @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin.jvm.internal; + +import kotlin.SinceKotlin; +import kotlin.reflect.KFunction; + +import java.io.Serializable; + +/** + * Superclass for instances of functional interface constructor references: + *
+ *     fun interface IFoo {
+ *         fun foo()
+ *     }
+ *     val iFoo = IFoo { println("Hello!") }    // calling fun interface constructor
+ *     val iFooCtor = ::IFoo                    // callable reference to fun interface constructor
+ * 
+ * + * Doesn't support reflection yet. + */ +@SuppressWarnings({"rawtypes", "WeakerAccess", "unused"}) +@SinceKotlin(version = "1.7") +public class FunInterfaceConstructorReference extends FunctionReference implements Serializable { + private final Class funInterface; + + public FunInterfaceConstructorReference(Class funInterface) { + super(1); + this.funInterface = funInterface; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FunInterfaceConstructorReference)) return false; + FunInterfaceConstructorReference other = (FunInterfaceConstructorReference) o; + return funInterface.equals(other.funInterface); + } + + @Override + public int hashCode() { + return funInterface.hashCode(); + } + + @Override + public String toString() { + return "fun interface " + funInterface.getName(); + } + + @Override + protected KFunction getReflected() { + throw new UnsupportedOperationException("Functional interface constructor does not support reflection"); + } +} diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt index df019f8d72e..8eb86926e6a 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt @@ -3583,6 +3583,15 @@ public final class kotlin/jvm/internal/FloatSpreadBuilder : kotlin/jvm/internal/ public final fun toArray ()[F } +public class kotlin/jvm/internal/FunInterfaceConstructorReference : kotlin/jvm/internal/FunctionReference, java/io/Serializable { + public fun (Ljava/lang/Class;)V + public fun equals (Ljava/lang/Object;)Z + protected synthetic fun getReflected ()Lkotlin/reflect/KCallable; + protected fun getReflected ()Lkotlin/reflect/KFunction; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public abstract interface class kotlin/jvm/internal/FunctionAdapter { public abstract fun getFunctionDelegate ()Lkotlin/Function; }