Move FunctionImpl classes from package "jet" to "kotlin"
This commit is contained in:
@@ -22,6 +22,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutablePackageFragmentDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
||||
@@ -30,6 +34,7 @@ import org.jetbrains.jet.lang.types.TypeProjectionImpl;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class FunctionTypesUtil {
|
||||
@@ -49,22 +54,18 @@ public class FunctionTypesUtil {
|
||||
K_MEMBER_FUNCTIONS = new ArrayList<ClassDescriptor>(n);
|
||||
K_EXTENSION_FUNCTIONS = new ArrayList<ClassDescriptor>(n);
|
||||
|
||||
ModuleDescriptor module = new ModuleDescriptorImpl(Name.special("<fake module for functions impl>"),
|
||||
Collections.<ImportPath>emptyList(), JavaToKotlinClassMap.getInstance());
|
||||
MutablePackageFragmentDescriptor kotlin = new MutablePackageFragmentDescriptor(module, new FqName("kotlin"));
|
||||
MutablePackageFragmentDescriptor reflect = new MutablePackageFragmentDescriptor(module, new FqName("kotlin.reflect"));
|
||||
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
for (int i = 0; i < n; i++) {
|
||||
Name functionImpl = Name.identifier("FunctionImpl" + i);
|
||||
FUNCTIONS.add(createFunctionImplDescriptor(functionImpl, builtIns.getFunction(i)));
|
||||
|
||||
Name extensionFunctionImpl = Name.identifier("ExtensionFunctionImpl" + i);
|
||||
EXTENSION_FUNCTIONS.add(createFunctionImplDescriptor(extensionFunctionImpl, builtIns.getExtensionFunction(i)));
|
||||
|
||||
Name kFunctionImpl = Name.identifier("KFunctionImpl" + i);
|
||||
K_FUNCTIONS.add(createFunctionImplDescriptor(kFunctionImpl, builtIns.getKFunction(i)));
|
||||
|
||||
Name kMemberFunctionImpl = Name.identifier("KMemberFunctionImpl" + i);
|
||||
K_MEMBER_FUNCTIONS.add(createFunctionImplDescriptor(kMemberFunctionImpl, builtIns.getKMemberFunction(i)));
|
||||
|
||||
Name kExtensionFunctionImpl = Name.identifier("KExtensionFunctionImpl" + i);
|
||||
K_EXTENSION_FUNCTIONS.add(createFunctionImplDescriptor(kExtensionFunctionImpl, builtIns.getKExtensionFunction(i)));
|
||||
createFunctionImpl(FUNCTIONS, kotlin, "FunctionImpl" + i, builtIns.getFunction(i));
|
||||
createFunctionImpl(EXTENSION_FUNCTIONS, kotlin, "ExtensionFunctionImpl" + i, builtIns.getExtensionFunction(i));
|
||||
createFunctionImpl(K_FUNCTIONS, reflect, "KFunctionImpl" + i, builtIns.getKFunction(i));
|
||||
createFunctionImpl(K_MEMBER_FUNCTIONS, reflect, "KMemberFunctionImpl" + i, builtIns.getKMemberFunction(i));
|
||||
createFunctionImpl(K_EXTENSION_FUNCTIONS, reflect, "KExtensionFunctionImpl" + i, builtIns.getKExtensionFunction(i));
|
||||
}
|
||||
|
||||
ImmutableMap.Builder<ClassDescriptor, ClassDescriptor> builder = ImmutableMap.builder();
|
||||
@@ -137,22 +138,25 @@ public class FunctionTypesUtil {
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ClassDescriptor createFunctionImplDescriptor(@NotNull Name name, @NotNull ClassDescriptor functionInterface) {
|
||||
PackageFragmentDescriptor builtinsFragment = KotlinBuiltIns.getInstance().getBuiltInsPackageFragment();
|
||||
private static void createFunctionImpl(
|
||||
@NotNull List<ClassDescriptor> result,
|
||||
@NotNull PackageFragmentDescriptor containingDeclaration,
|
||||
@NotNull String name,
|
||||
@NotNull ClassDescriptor functionInterface
|
||||
) {
|
||||
MutableClassDescriptor functionImpl = new MutableClassDescriptor(
|
||||
builtinsFragment,
|
||||
builtinsFragment.getMemberScope(),
|
||||
containingDeclaration,
|
||||
containingDeclaration.getMemberScope(),
|
||||
ClassKind.CLASS,
|
||||
false,
|
||||
name
|
||||
Name.identifier(name)
|
||||
);
|
||||
functionImpl.setModality(Modality.FINAL);
|
||||
functionImpl.setVisibility(Visibilities.PUBLIC);
|
||||
functionImpl.setTypeParameterDescriptors(functionInterface.getDefaultType().getConstructor().getParameters());
|
||||
functionImpl.createTypeConstructor();
|
||||
|
||||
return functionImpl;
|
||||
result.add(functionImpl);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -170,10 +174,10 @@ public class FunctionTypesUtil {
|
||||
public static Type getFunctionImplType(@NotNull FunctionDescriptor descriptor) {
|
||||
int paramCount = descriptor.getValueParameters().size();
|
||||
if (descriptor.getReceiverParameter() != null) {
|
||||
return Type.getObjectType("jet/ExtensionFunctionImpl" + paramCount);
|
||||
return Type.getObjectType("kotlin/ExtensionFunctionImpl" + paramCount);
|
||||
}
|
||||
else {
|
||||
return Type.getObjectType("jet/FunctionImpl" + paramCount);
|
||||
return Type.getObjectType("kotlin/FunctionImpl" + paramCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@ fun A.baz() {}
|
||||
|
||||
fun box(): String {
|
||||
val f = "${::foo}"
|
||||
if (f != "jet.KFunctionImpl1<java.lang.String, jet.Unit>") return "Fail foo: $f"
|
||||
if (f != "kotlin.reflect.KFunctionImpl1<java.lang.String, jet.Unit>") return "Fail foo: $f"
|
||||
|
||||
val nameOfA = (A() as java.lang.Object).getClass().getName()
|
||||
|
||||
val g = "${A::bar}"
|
||||
if (g != "jet.KMemberFunctionImpl0<$nameOfA, java.lang.String>") return "Fail bar: $g"
|
||||
if (g != "kotlin.reflect.KMemberFunctionImpl0<$nameOfA, java.lang.String>") return "Fail bar: $g"
|
||||
|
||||
val h = "${A::baz}"
|
||||
if (h != "jet.KExtensionFunctionImpl0<$nameOfA, jet.Unit>") return "Fail baz: $h"
|
||||
if (h != "kotlin.reflect.KExtensionFunctionImpl0<$nameOfA, jet.Unit>") return "Fail baz: $h"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -6,22 +6,22 @@ fun check(expected: String, obj: Any?) {
|
||||
|
||||
|
||||
fun box(): String {
|
||||
check("jet.FunctionImpl0<jet.Unit>")
|
||||
check("kotlin.FunctionImpl0<jet.Unit>")
|
||||
{ () : Unit -> }
|
||||
check("jet.FunctionImpl0<java.lang.Integer>")
|
||||
check("kotlin.FunctionImpl0<java.lang.Integer>")
|
||||
{ () : Int -> 42 }
|
||||
check("jet.FunctionImpl1<java.lang.String, java.lang.Long>")
|
||||
check("kotlin.FunctionImpl1<java.lang.String, java.lang.Long>")
|
||||
{ (s: String) : Long -> 42.toLong() }
|
||||
check("jet.FunctionImpl2<java.lang.Integer, java.lang.Integer, jet.Unit>")
|
||||
check("kotlin.FunctionImpl2<java.lang.Integer, java.lang.Integer, jet.Unit>")
|
||||
{ (x: Int, y: Int) : Unit -> }
|
||||
|
||||
check("jet.ExtensionFunctionImpl0<java.lang.Integer, jet.Unit>")
|
||||
check("kotlin.ExtensionFunctionImpl0<java.lang.Integer, jet.Unit>")
|
||||
{ Int.() : Unit -> }
|
||||
check("jet.ExtensionFunctionImpl0<jet.Unit, java.lang.Integer>")
|
||||
check("kotlin.ExtensionFunctionImpl0<jet.Unit, java.lang.Integer>")
|
||||
{ Unit.() : Int -> 42 }
|
||||
check("jet.ExtensionFunctionImpl1<java.lang.String, java.lang.String, java.lang.Long>")
|
||||
check("kotlin.ExtensionFunctionImpl1<java.lang.String, java.lang.String, java.lang.Long>")
|
||||
{ String.(s: String) : Long -> 42.toLong() }
|
||||
check("jet.ExtensionFunctionImpl2<java.lang.Integer, java.lang.Integer, java.lang.Integer, jet.Unit>")
|
||||
check("kotlin.ExtensionFunctionImpl2<java.lang.Integer, java.lang.Integer, java.lang.Integer, jet.Unit>")
|
||||
{ Int.(x: Int, y: Int) : Unit -> }
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -19,15 +19,15 @@ val extensionFun = { Any.() : Unit -> }
|
||||
val extensionWithArgFun = { Long.(x: Any) : Date -> Date() }
|
||||
|
||||
fun box(): String {
|
||||
assertGenericSuper("jet.FunctionImpl0<jet.Unit>", unitFun)
|
||||
assertGenericSuper("jet.FunctionImpl0<java.lang.Integer>", intFun)
|
||||
assertGenericSuper("jet.FunctionImpl1<java.lang.String, jet.Unit>", stringParamFun)
|
||||
assertGenericSuper("jet.FunctionImpl1<java.util.List<? extends java.lang.String>, java.util.List<? extends java.lang.String>>", listFun)
|
||||
assertGenericSuper("jet.FunctionImpl1<java.util.List<java.lang.Double>, java.util.List<java.lang.Integer>>", mutableListFun)
|
||||
assertGenericSuper("jet.FunctionImpl1<java.lang.Comparable<? super java.lang.String>, jet.Unit>", funWithIn)
|
||||
assertGenericSuper("kotlin.FunctionImpl0<jet.Unit>", unitFun)
|
||||
assertGenericSuper("kotlin.FunctionImpl0<java.lang.Integer>", intFun)
|
||||
assertGenericSuper("kotlin.FunctionImpl1<java.lang.String, jet.Unit>", stringParamFun)
|
||||
assertGenericSuper("kotlin.FunctionImpl1<java.util.List<? extends java.lang.String>, java.util.List<? extends java.lang.String>>", listFun)
|
||||
assertGenericSuper("kotlin.FunctionImpl1<java.util.List<java.lang.Double>, java.util.List<java.lang.Integer>>", mutableListFun)
|
||||
assertGenericSuper("kotlin.FunctionImpl1<java.lang.Comparable<? super java.lang.String>, jet.Unit>", funWithIn)
|
||||
|
||||
assertGenericSuper("jet.ExtensionFunctionImpl0<java.lang.Object, jet.Unit>", extensionFun)
|
||||
assertGenericSuper("jet.ExtensionFunctionImpl1<java.lang.Long, java.lang.Object, java.util.Date>", extensionWithArgFun)
|
||||
assertGenericSuper("kotlin.ExtensionFunctionImpl0<java.lang.Object, jet.Unit>", extensionFun)
|
||||
assertGenericSuper("kotlin.ExtensionFunctionImpl1<java.lang.Long, java.lang.Object, java.util.Date>", extensionWithArgFun)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
// Auto-generated file. DO NOT EDIT!
|
||||
|
||||
package jet
|
||||
package kotlin
|
||||
|
||||
public abstract class ExtensionFunctionImpl0<in T, out R> : ExtensionFunction0<T, R>, DefaultJetObject() {
|
||||
override fun toString() = "${getClass().getGenericSuperclass()}"
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
// Auto-generated file. DO NOT EDIT!
|
||||
|
||||
package jet
|
||||
package kotlin
|
||||
|
||||
public abstract class FunctionImpl0<out R> : Function0<R>, DefaultJetObject() {
|
||||
override fun toString() = "${getClass().getGenericSuperclass()}"
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
// Auto-generated file. DO NOT EDIT!
|
||||
|
||||
package jet
|
||||
package kotlin.reflect
|
||||
|
||||
public abstract class KExtensionFunctionImpl0<in T, out R> : KExtensionFunction0<T, R>, DefaultJetObject() {
|
||||
override fun toString() = "${getClass().getGenericSuperclass()}"
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
// Auto-generated file. DO NOT EDIT!
|
||||
|
||||
package jet
|
||||
package kotlin.reflect
|
||||
|
||||
public abstract class KFunctionImpl0<out R> : KFunction0<R>, DefaultJetObject() {
|
||||
override fun toString() = "${getClass().getGenericSuperclass()}"
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
// Auto-generated file. DO NOT EDIT!
|
||||
|
||||
package jet
|
||||
package kotlin.reflect
|
||||
|
||||
public abstract class KMemberFunctionImpl0<in T, out R> : KMemberFunction0<T, R>, DefaultJetObject() {
|
||||
override fun toString() = "${getClass().getGenericSuperclass()}"
|
||||
@@ -34,10 +34,12 @@ enum class FunctionKind(
|
||||
K_EXTENSION_FUNCTION : FunctionKind("KExtensionFunction", true, "ExtensionFunction")
|
||||
|
||||
fun getFileName() = classNamePrefix + "s.kt"
|
||||
fun getImplFileName() = classNamePrefix + "sImpl.kt"
|
||||
fun getImplFileName() = (if (isReflection()) "reflect/" else "") + classNamePrefix + "sImpl.kt"
|
||||
fun getClassName(i: Int) = classNamePrefix + i
|
||||
fun getImplClassName(i: Int) = classNamePrefix + "Impl" + i
|
||||
fun getSuperClassName(i: Int) = superClassNamePrefix?.plus(i)
|
||||
|
||||
private fun isReflection() = superClassNamePrefix != null
|
||||
}
|
||||
|
||||
abstract class GenerateFunctionsBase(out: PrintWriter, val kind: FunctionKind): BuiltInsSourceGenerator(out) {
|
||||
@@ -85,9 +87,6 @@ class GenerateFunctions(out: PrintWriter, kind: FunctionKind) : GenerateFunction
|
||||
K_FUNCTION, K_MEMBER_FUNCTION, K_EXTENSION_FUNCTION -> {
|
||||
out.println()
|
||||
}
|
||||
else -> {
|
||||
throw IllegalStateException("Unknown kind: " + kind)
|
||||
}
|
||||
}
|
||||
|
||||
fun generateInvokeSignature(i: Int) {
|
||||
@@ -103,6 +102,11 @@ class GenerateFunctions(out: PrintWriter, kind: FunctionKind) : GenerateFunction
|
||||
}
|
||||
|
||||
class GenerateFunctionsImpl(out: PrintWriter, kind: FunctionKind) : GenerateFunctionsBase(out, kind) {
|
||||
override fun getPackage() = when (kind) {
|
||||
FUNCTION, EXTENSION_FUNCTION -> "kotlin"
|
||||
K_FUNCTION, K_MEMBER_FUNCTION, K_EXTENSION_FUNCTION -> "kotlin.reflect"
|
||||
}
|
||||
|
||||
override fun generateBody() {
|
||||
for (i in 0..MAX_PARAM_COUNT) {
|
||||
out.print("public abstract class " + kind.getImplClassName(i))
|
||||
|
||||
@@ -28,18 +28,20 @@ fun assertExists(file: File): Unit =
|
||||
if (!file.exists()) error("Output dir does not exist: ${file.getAbsolutePath()}")
|
||||
|
||||
val BUILT_INS_DIR = File("core/builtins/src/jet/")
|
||||
val RUNTIME_JVM_DIR = File("core/runtime.jvm/src/jet/")
|
||||
val RUNTIME_JVM_DIR = File("core/runtime.jvm/src/kotlin/")
|
||||
|
||||
abstract class BuiltInsSourceGenerator(val out: PrintWriter) {
|
||||
protected abstract fun generateBody(): Unit
|
||||
|
||||
protected open fun getPackage(): String = "jet"
|
||||
|
||||
final fun generate() {
|
||||
out.println(File("injector-generator/copyright.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.println("package jet")
|
||||
out.println("package ${getPackage()}")
|
||||
out.println()
|
||||
|
||||
generateBody()
|
||||
@@ -64,6 +66,7 @@ fun generateBuiltIns(generate: (File, (PrintWriter) -> BuiltInsSourceGenerator)
|
||||
fun main(args: Array<String>) {
|
||||
generateBuiltIns { file, generator ->
|
||||
println("generating $file")
|
||||
file.getParentFile()?.mkdirs()
|
||||
PrintWriter(file) use {
|
||||
generator(it).generate()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user