Drop KFunctionFromReferenceImpl, make FunctionImpl an interface
23 invokes in KFunctionFromReferenceImpl (and consequently, in FunctionImpl) were needed before1576160390: a wrapped function reference must have had the necessary invoke to be called as an instance of a specific function type. After1576160390, this is not needed anymore because KFunctionFromReferenceImpl is now an internal implementation detail of reflection, and no invoke is ever called on it.
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* 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 org.jetbrains.kotlin.generators.builtins.functionImpl
|
||||
|
||||
import org.jetbrains.kotlin.generators.builtins.functions.MAX_PARAM_COUNT
|
||||
import org.jetbrains.kotlin.generators.builtins.generateBuiltIns.BuiltInsSourceGenerator
|
||||
import org.jetbrains.kotlin.generators.builtins.generateBuiltIns.BuiltInsSourceGenerator.Language
|
||||
import java.io.PrintWriter
|
||||
|
||||
class GenerateFunctionImpl(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
override fun getPackage() = "kotlin.jvm.internal"
|
||||
|
||||
override val language = Language.JAVA
|
||||
|
||||
override fun generateBody() {
|
||||
val n = MAX_PARAM_COUNT
|
||||
|
||||
out.print("""import kotlin.Function;
|
||||
import kotlin.jvm.functions.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class FunctionImpl
|
||||
implements Function, Serializable,""")
|
||||
|
||||
for (i in 0..n) {
|
||||
if (i % 10 == 0) {
|
||||
// Insert newline sometimes to avoid very long lines
|
||||
out.println()
|
||||
out.print(" ")
|
||||
}
|
||||
out.print("Function$i")
|
||||
if (i < n) out.print(", ")
|
||||
}
|
||||
|
||||
out.println(" {")
|
||||
|
||||
out.println("""
|
||||
public abstract int getArity();
|
||||
|
||||
public Object invokeVararg(Object... p) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private void checkArity(int expected) {
|
||||
if (getArity() != expected) {
|
||||
throwWrongArity(expected);
|
||||
}
|
||||
}
|
||||
|
||||
private void throwWrongArity(int expected) {
|
||||
throw new IllegalStateException("Wrong function arity, expected: " + expected + ", actual: " + getArity());
|
||||
}""")
|
||||
|
||||
for (i in 0..n) {
|
||||
out.println()
|
||||
out.println(" @Override")
|
||||
out.println(" public Object invoke(" + (1..i).joinToString { "Object p$it" } + ") {")
|
||||
out.println(" checkArity($i);")
|
||||
out.println(" return invokeVararg(" + (1..i).joinToString { "p$it" } + ");")
|
||||
out.println(" }")
|
||||
}
|
||||
|
||||
out.println("}")
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.generators.builtins.generateBuiltIns
|
||||
|
||||
import org.jetbrains.kotlin.generators.builtins.arrayIterators.GenerateArrayIterators
|
||||
import org.jetbrains.kotlin.generators.builtins.arrays.GenerateArrays
|
||||
import org.jetbrains.kotlin.generators.builtins.functionImpl.GenerateFunctionImpl
|
||||
import org.jetbrains.kotlin.generators.builtins.functions.GenerateFunctions
|
||||
import org.jetbrains.kotlin.generators.builtins.iterators.GenerateIterators
|
||||
import org.jetbrains.kotlin.generators.builtins.progressionIterators.GenerateProgressionIterators
|
||||
@@ -41,21 +40,19 @@ abstract class BuiltInsSourceGenerator(val out: PrintWriter) {
|
||||
|
||||
protected open fun getPackage(): String = "kotlin"
|
||||
|
||||
protected open val language: Language = Language.KOTLIN
|
||||
|
||||
enum class Language {
|
||||
KOTLIN,
|
||||
JAVA
|
||||
}
|
||||
|
||||
final fun generate() {
|
||||
fun generate() {
|
||||
out.println(File("license/LICENSE.txt").readText())
|
||||
// Don't include generator class name in the message: these are built-in sources,
|
||||
// and we don't want to scare users with any internal information about our project
|
||||
out.println("// Auto-generated file. DO NOT EDIT!")
|
||||
out.println()
|
||||
out.print("package ${getPackage()}")
|
||||
if (language == Language.KOTLIN) out.println() else out.println(";")
|
||||
out.println()
|
||||
out.println()
|
||||
|
||||
generateBody()
|
||||
@@ -68,7 +65,6 @@ fun generateBuiltIns(generate: (File, (PrintWriter) -> BuiltInsSourceGenerator)
|
||||
assertExists(RUNTIME_JVM_DIR)
|
||||
|
||||
generate(File(RUNTIME_JVM_DIR, "kotlin/jvm/functions/Functions.kt")) { GenerateFunctions(it) }
|
||||
generate(File(RUNTIME_JVM_DIR, "kotlin/jvm/internal/FunctionImpl.java")) { GenerateFunctionImpl(it) }
|
||||
generate(File(BUILT_INS_NATIVE_DIR, "kotlin/Arrays.kt")) { GenerateArrays(it) }
|
||||
generate(File(BUILT_INS_NATIVE_DIR, "kotlin/Primitives.kt")) { GeneratePrimitives(it) }
|
||||
generate(File(BUILT_INS_SRC_DIR, "kotlin/Iterators.kt")) { GenerateIterators(it) }
|
||||
|
||||
Reference in New Issue
Block a user