From f6178ad7dd2cb02e2c3dfa828fdbfba85de5a70d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 13 Apr 2015 18:26:38 +0300 Subject: [PATCH] Introduce Function, KFunction interfaces and 'extension' annotation --- compiler/testData/builtin-classes.txt | 4 ++ core/builtins/src/kotlin/Annotations.kt | 5 ++ .../builtins/src/kotlin/ExtensionFunctions.kt | 46 +++++++++---------- core/builtins/src/kotlin/Function.kt | 22 +++++++++ core/builtins/src/kotlin/Functions.kt | 46 +++++++++---------- .../src/kotlin/reflect/KExtensionFunction.kt | 27 +++++++++++ core/builtins/src/kotlin/reflect/KFunction.kt | 22 +++++++++ .../src/kotlin/reflect/KMemberFunction.kt | 26 +++++++++++ .../reflect/KTopLevelExtensionFunction.kt | 25 ++++++++++ .../src/kotlin/reflect/KTopLevelFunction.kt | 22 +++++++++ .../kotlin/generators/builtins/functions.kt | 17 +++++-- j2k/src/org/jetbrains/kotlin/j2k/Converter.kt | 1 + jslib_files.xml | 1 + 13 files changed, 215 insertions(+), 49 deletions(-) create mode 100644 core/builtins/src/kotlin/Function.kt create mode 100644 core/builtins/src/kotlin/reflect/KExtensionFunction.kt create mode 100644 core/builtins/src/kotlin/reflect/KFunction.kt create mode 100644 core/builtins/src/kotlin/reflect/KMemberFunction.kt create mode 100644 core/builtins/src/kotlin/reflect/KTopLevelExtensionFunction.kt create mode 100644 core/builtins/src/kotlin/reflect/KTopLevelFunction.kt diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index de962a23b15..ed56381ec68 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -1522,6 +1522,10 @@ public final annotation class deprecated : kotlin.Annotation { internal final fun (): kotlin.String } +public final annotation class extension : kotlin.Annotation { + /*primary*/ public constructor extension() +} + public final annotation class inline : kotlin.Annotation { /*primary*/ public constructor inline(/*0*/ strategy: kotlin.InlineStrategy = ...) public final val strategy: kotlin.InlineStrategy diff --git a/core/builtins/src/kotlin/Annotations.kt b/core/builtins/src/kotlin/Annotations.kt index 4ae8756cd5a..4136eb529b9 100644 --- a/core/builtins/src/kotlin/Annotations.kt +++ b/core/builtins/src/kotlin/Annotations.kt @@ -30,6 +30,11 @@ public annotation class data */ public annotation class deprecated(val value: String) +/** + * Signifies that the annotated functional type represents an extension function. + */ +public annotation class extension + /** * Suppresses the given compilation warnings in the annotated element. * @property names names of the compiler diagnostics to suppress. diff --git a/core/builtins/src/kotlin/ExtensionFunctions.kt b/core/builtins/src/kotlin/ExtensionFunctions.kt index 1b4f7edb90e..7621541f9e5 100644 --- a/core/builtins/src/kotlin/ExtensionFunctions.kt +++ b/core/builtins/src/kotlin/ExtensionFunctions.kt @@ -19,117 +19,117 @@ package kotlin /** An extension function that takes 0 arguments. */ -public interface ExtensionFunction0 { +public interface ExtensionFunction0 : Function { /** Invokes the function. */ public fun T.invoke(): R } /** An extension function that takes 1 argument. */ -public interface ExtensionFunction1 { +public interface ExtensionFunction1 : Function { /** Invokes the function with the specified argument. */ public fun T.invoke(p1: P1): R } /** An extension function that takes 2 arguments. */ -public interface ExtensionFunction2 { +public interface ExtensionFunction2 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2): R } /** An extension function that takes 3 arguments. */ -public interface ExtensionFunction3 { +public interface ExtensionFunction3 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3): R } /** An extension function that takes 4 arguments. */ -public interface ExtensionFunction4 { +public interface ExtensionFunction4 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4): R } /** An extension function that takes 5 arguments. */ -public interface ExtensionFunction5 { +public interface ExtensionFunction5 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R } /** An extension function that takes 6 arguments. */ -public interface ExtensionFunction6 { +public interface ExtensionFunction6 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R } /** An extension function that takes 7 arguments. */ -public interface ExtensionFunction7 { +public interface ExtensionFunction7 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R } /** An extension function that takes 8 arguments. */ -public interface ExtensionFunction8 { +public interface ExtensionFunction8 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R } /** An extension function that takes 9 arguments. */ -public interface ExtensionFunction9 { +public interface ExtensionFunction9 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R } /** An extension function that takes 10 arguments. */ -public interface ExtensionFunction10 { +public interface ExtensionFunction10 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R } /** An extension function that takes 11 arguments. */ -public interface ExtensionFunction11 { +public interface ExtensionFunction11 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R } /** An extension function that takes 12 arguments. */ -public interface ExtensionFunction12 { +public interface ExtensionFunction12 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R } /** An extension function that takes 13 arguments. */ -public interface ExtensionFunction13 { +public interface ExtensionFunction13 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R } /** An extension function that takes 14 arguments. */ -public interface ExtensionFunction14 { +public interface ExtensionFunction14 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R } /** An extension function that takes 15 arguments. */ -public interface ExtensionFunction15 { +public interface ExtensionFunction15 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R } /** An extension function that takes 16 arguments. */ -public interface ExtensionFunction16 { +public interface ExtensionFunction16 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R } /** An extension function that takes 17 arguments. */ -public interface ExtensionFunction17 { +public interface ExtensionFunction17 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R } /** An extension function that takes 18 arguments. */ -public interface ExtensionFunction18 { +public interface ExtensionFunction18 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R } /** An extension function that takes 19 arguments. */ -public interface ExtensionFunction19 { +public interface ExtensionFunction19 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R } /** An extension function that takes 20 arguments. */ -public interface ExtensionFunction20 { +public interface ExtensionFunction20 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R } /** An extension function that takes 21 arguments. */ -public interface ExtensionFunction21 { +public interface ExtensionFunction21 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R } /** An extension function that takes 22 arguments. */ -public interface ExtensionFunction22 { +public interface ExtensionFunction22 : Function { /** Invokes the function with the specified arguments. */ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R } diff --git a/core/builtins/src/kotlin/Function.kt b/core/builtins/src/kotlin/Function.kt new file mode 100644 index 00000000000..4002a56dabb --- /dev/null +++ b/core/builtins/src/kotlin/Function.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin + +/** + * Represents a value of a functional type, such as a lambda, a function expression or a function reference. + */ +public interface Function diff --git a/core/builtins/src/kotlin/Functions.kt b/core/builtins/src/kotlin/Functions.kt index 81ac8c558bc..5fbbf8e60ff 100644 --- a/core/builtins/src/kotlin/Functions.kt +++ b/core/builtins/src/kotlin/Functions.kt @@ -19,117 +19,117 @@ package kotlin /** A function that takes 0 arguments. */ -public interface Function0 { +public interface Function0 : Function { /** Invokes the function. */ public fun invoke(): R } /** A function that takes 1 argument. */ -public interface Function1 { +public interface Function1 : Function { /** Invokes the function with the specified argument. */ public fun invoke(p1: P1): R } /** A function that takes 2 arguments. */ -public interface Function2 { +public interface Function2 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2): R } /** A function that takes 3 arguments. */ -public interface Function3 { +public interface Function3 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3): R } /** A function that takes 4 arguments. */ -public interface Function4 { +public interface Function4 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4): R } /** A function that takes 5 arguments. */ -public interface Function5 { +public interface Function5 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R } /** A function that takes 6 arguments. */ -public interface Function6 { +public interface Function6 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R } /** A function that takes 7 arguments. */ -public interface Function7 { +public interface Function7 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R } /** A function that takes 8 arguments. */ -public interface Function8 { +public interface Function8 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R } /** A function that takes 9 arguments. */ -public interface Function9 { +public interface Function9 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R } /** A function that takes 10 arguments. */ -public interface Function10 { +public interface Function10 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R } /** A function that takes 11 arguments. */ -public interface Function11 { +public interface Function11 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R } /** A function that takes 12 arguments. */ -public interface Function12 { +public interface Function12 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R } /** A function that takes 13 arguments. */ -public interface Function13 { +public interface Function13 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R } /** A function that takes 14 arguments. */ -public interface Function14 { +public interface Function14 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R } /** A function that takes 15 arguments. */ -public interface Function15 { +public interface Function15 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R } /** A function that takes 16 arguments. */ -public interface Function16 { +public interface Function16 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R } /** A function that takes 17 arguments. */ -public interface Function17 { +public interface Function17 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R } /** A function that takes 18 arguments. */ -public interface Function18 { +public interface Function18 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R } /** A function that takes 19 arguments. */ -public interface Function19 { +public interface Function19 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R } /** A function that takes 20 arguments. */ -public interface Function20 { +public interface Function20 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R } /** A function that takes 21 arguments. */ -public interface Function21 { +public interface Function21 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R } /** A function that takes 22 arguments. */ -public interface Function22 { +public interface Function22 : Function { /** Invokes the function with the specified arguments. */ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R } diff --git a/core/builtins/src/kotlin/reflect/KExtensionFunction.kt b/core/builtins/src/kotlin/reflect/KExtensionFunction.kt new file mode 100644 index 00000000000..d2b861e14e7 --- /dev/null +++ b/core/builtins/src/kotlin/reflect/KExtensionFunction.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.reflect + +/** + * Represents an extension function. + * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/extensions.html#extension-functions) + * for more information. + * + * @param E the type of the extension receiver. + * @param R the return type of the function. + */ +public interface KExtensionFunction : KFunction diff --git a/core/builtins/src/kotlin/reflect/KFunction.kt b/core/builtins/src/kotlin/reflect/KFunction.kt new file mode 100644 index 00000000000..127496163cc --- /dev/null +++ b/core/builtins/src/kotlin/reflect/KFunction.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.reflect + +/** + * Represents a function with introspection capabilities. + */ +public interface KFunction : Function diff --git a/core/builtins/src/kotlin/reflect/KMemberFunction.kt b/core/builtins/src/kotlin/reflect/KMemberFunction.kt new file mode 100644 index 00000000000..70a1c36faef --- /dev/null +++ b/core/builtins/src/kotlin/reflect/KMemberFunction.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.reflect + +/** + * Represents a member function. + * + * @param T the type of the instance which should be used to call the function. + * Must be derived either from a class declaring this function, or any subclass of that class. + * @param R the return type of the function. + */ +public interface KMemberFunction : KFunction diff --git a/core/builtins/src/kotlin/reflect/KTopLevelExtensionFunction.kt b/core/builtins/src/kotlin/reflect/KTopLevelExtensionFunction.kt new file mode 100644 index 00000000000..133b1bb61d8 --- /dev/null +++ b/core/builtins/src/kotlin/reflect/KTopLevelExtensionFunction.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.reflect + +/** + * Represents an extension function declared in a package. + * + * @param E the type of the extension receiver. + * @param R the return type of the function. + */ +public interface KTopLevelExtensionFunction : KExtensionFunction diff --git a/core/builtins/src/kotlin/reflect/KTopLevelFunction.kt b/core/builtins/src/kotlin/reflect/KTopLevelFunction.kt new file mode 100644 index 00000000000..2f0d18f09bf --- /dev/null +++ b/core/builtins/src/kotlin/reflect/KTopLevelFunction.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.reflect + +/** + * Represents a function declared in a package. + */ +public interface KTopLevelFunction : KFunction diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/functions.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/functions.kt index 17f74502ddf..1b33a42da90 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/functions.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/functions.kt @@ -58,15 +58,21 @@ class GenerateFunctions(out: PrintWriter, val kind: FunctionKind) : BuiltInsSour out.print("P$j, ") } + generateReturnTypeParameter(variance) + + out.print(">") + } + + fun generateReturnTypeParameter(variance: Boolean) { if (variance) out.print("out ") - out.print("R>") + out.print("R") } override fun generateBody() { for (i in 0..MAX_PARAM_COUNT) { generateDocumentation(i) out.print("public interface " + kind.getClassName(i)) - generateTypeParameters(i, true) + generateTypeParameters(i, variance = true) generateSuperClass(i) generateFunctionClassBody(i) } @@ -81,7 +87,12 @@ class GenerateFunctions(out: PrintWriter, val kind: FunctionKind) : BuiltInsSour val superClass = kind.getSuperClassName(i) if (superClass != null) { out.print(" : $superClass") - generateTypeParameters(i, false) + generateTypeParameters(i, variance = false) + } + else { + out.print(" : Function<") + generateReturnTypeParameter(variance = false) + out.print(">") } } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/Converter.kt b/j2k/src/org/jetbrains/kotlin/j2k/Converter.kt index 87ee72d3cf7..d8cb5ce16ff 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/Converter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/Converter.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.j2k.ast.* import org.jetbrains.kotlin.j2k.ast.Annotation import org.jetbrains.kotlin.j2k.ast.Class import org.jetbrains.kotlin.j2k.ast.Enum +import org.jetbrains.kotlin.j2k.ast.Function import org.jetbrains.kotlin.j2k.ast.Object import org.jetbrains.kotlin.j2k.usageProcessing.FieldToPropertyProcessing import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessing diff --git a/jslib_files.xml b/jslib_files.xml index 6a05d54f78d..32baa630167 100644 --- a/jslib_files.xml +++ b/jslib_files.xml @@ -3,6 +3,7 @@ +