Move SuspendFunction{N} interfaces to kotlin.coroutines package
#KT-25824: Fixed
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.coroutines
|
||||
|
||||
/**
|
||||
* This is neccesary to force generation of coroutines.kotlin_builtins file, thus providing builtin package fragment for kotlin.coroutines
|
||||
* package. This way we can use kotlin.coroutines.SuspendFunction{N} interfaces in code.
|
||||
*/
|
||||
private fun hackToForceKotlinBuiltinsForKotlinCoroutinesPackage() {}
|
||||
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.builtins;
|
||||
@@ -50,6 +39,7 @@ import java.util.*;
|
||||
|
||||
import static kotlin.collections.SetsKt.setOf;
|
||||
import static org.jetbrains.kotlin.builtins.PrimitiveType.*;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName;
|
||||
import static org.jetbrains.kotlin.utils.CollectionsKt.newHashMapWithExpectedSize;
|
||||
import static org.jetbrains.kotlin.utils.CollectionsKt.newHashSetWithExpectedSize;
|
||||
@@ -85,7 +75,7 @@ public abstract class KotlinBuiltIns {
|
||||
public static final FqNames FQ_NAMES = new FqNames();
|
||||
public static final Name BUILTINS_MODULE_NAME = Name.special("<built-ins module>");
|
||||
|
||||
protected KotlinBuiltIns(@NotNull StorageManager storageManager) {
|
||||
protected KotlinBuiltIns(@NotNull final StorageManager storageManager) {
|
||||
this.storageManager = storageManager;
|
||||
|
||||
this.packageFragments = storageManager.createLazyValue(new Function0<PackageFragments>() {
|
||||
@@ -95,12 +85,13 @@ public abstract class KotlinBuiltIns {
|
||||
|
||||
Map<FqName, PackageFragmentDescriptor> nameToFragment = new LinkedHashMap<FqName, PackageFragmentDescriptor>();
|
||||
PackageFragmentDescriptor kotlin = createPackage(provider, nameToFragment, BUILT_INS_PACKAGE_FQ_NAME);
|
||||
PackageFragmentDescriptor kotlinCoroutines = createPackage(provider, null, COROUTINES_PACKAGE_FQ_NAME_RELEASE);
|
||||
PackageFragmentDescriptor kotlinCollections = createPackage(provider, nameToFragment, COLLECTIONS_PACKAGE_FQ_NAME);
|
||||
createPackage(provider, nameToFragment, RANGES_PACKAGE_FQ_NAME);
|
||||
PackageFragmentDescriptor kotlinAnnotation = createPackage(provider, nameToFragment, ANNOTATION_PACKAGE_FQ_NAME);
|
||||
Set<PackageFragmentDescriptor> allImportedByDefault = new LinkedHashSet<PackageFragmentDescriptor>(nameToFragment.values());
|
||||
|
||||
return new PackageFragments(kotlin, kotlinCollections, kotlinAnnotation, allImportedByDefault);
|
||||
return new PackageFragments(kotlin, kotlinCoroutines, kotlinCollections, kotlinAnnotation, allImportedByDefault);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -152,7 +143,7 @@ public abstract class KotlinBuiltIns {
|
||||
public ClassDescriptor invoke(Integer arity) {
|
||||
return new FunctionClassDescriptor(
|
||||
getStorageManager(),
|
||||
packageFragments.invoke().builtInsPackageFragment,
|
||||
packageFragments.invoke().coroutinesPackageFragment,
|
||||
FunctionClassDescriptor.Kind.SuspendFunction,
|
||||
arity
|
||||
);
|
||||
@@ -278,17 +269,20 @@ public abstract class KotlinBuiltIns {
|
||||
|
||||
private static class PackageFragments {
|
||||
public final PackageFragmentDescriptor builtInsPackageFragment;
|
||||
public final PackageFragmentDescriptor coroutinesPackageFragment;
|
||||
public final PackageFragmentDescriptor collectionsPackageFragment;
|
||||
public final PackageFragmentDescriptor annotationPackageFragment;
|
||||
public final Set<PackageFragmentDescriptor> allImportedByDefaultBuiltInsPackageFragments;
|
||||
|
||||
private PackageFragments(
|
||||
@NotNull PackageFragmentDescriptor builtInsPackageFragment,
|
||||
@NotNull PackageFragmentDescriptor coroutinesPackageFragment,
|
||||
@NotNull PackageFragmentDescriptor collectionsPackageFragment,
|
||||
@NotNull PackageFragmentDescriptor annotationPackageFragment,
|
||||
@NotNull Set<PackageFragmentDescriptor> allImportedByDefaultBuiltInsPackageFragments
|
||||
) {
|
||||
this.builtInsPackageFragment = builtInsPackageFragment;
|
||||
this.coroutinesPackageFragment = coroutinesPackageFragment;
|
||||
this.collectionsPackageFragment = collectionsPackageFragment;
|
||||
this.annotationPackageFragment = annotationPackageFragment;
|
||||
this.allImportedByDefaultBuiltInsPackageFragments = allImportedByDefaultBuiltInsPackageFragments;
|
||||
|
||||
+17
-14
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.*
|
||||
@@ -38,7 +38,7 @@ class FunctionClassDescriptor(
|
||||
|
||||
enum class Kind(val packageFqName: FqName, val classNamePrefix: String) {
|
||||
Function(BUILT_INS_PACKAGE_FQ_NAME, "Function"),
|
||||
SuspendFunction(BUILT_INS_PACKAGE_FQ_NAME, "SuspendFunction"),
|
||||
SuspendFunction(COROUTINES_PACKAGE_FQ_NAME_RELEASE, "SuspendFunction"),
|
||||
KFunction(KOTLIN_REFLECT_FQ_NAME, "KFunction"),
|
||||
KSuspendFunction(KOTLIN_REFLECT_FQ_NAME, "KSuspendFunction");
|
||||
|
||||
@@ -110,7 +110,7 @@ class FunctionClassDescriptor(
|
||||
|
||||
fun add(packageFragment: PackageFragmentDescriptor, name: Name) {
|
||||
val descriptor = packageFragment.getMemberScope().getContributedClassifier(name, NoLookupLocation.FROM_BUILTINS) as? ClassDescriptor
|
||||
?: error("Class $name not found in $packageFragment")
|
||||
?: error("Class $name not found in $packageFragment")
|
||||
|
||||
val typeConstructor = descriptor.typeConstructor
|
||||
|
||||
@@ -124,7 +124,7 @@ class FunctionClassDescriptor(
|
||||
|
||||
when (functionKind) {
|
||||
Kind.SuspendFunction -> // SuspendFunction$N<...> <: Function
|
||||
add(containingDeclaration, Name.identifier("Function"))
|
||||
add(getBuiltInPackage(BUILT_INS_PACKAGE_FQ_NAME), Name.identifier("Function"))
|
||||
Kind.KSuspendFunction -> // KSuspendFunction$N<...> <: KFunction
|
||||
add(containingDeclaration, Name.identifier("KFunction"))
|
||||
else -> // Add unnumbered base class, e.g. Function for Function{n}, KFunction for KFunction{n}
|
||||
@@ -132,21 +132,24 @@ class FunctionClassDescriptor(
|
||||
}
|
||||
|
||||
// For K{Suspend}Function{n}, add corresponding numbered {Suspend}Function{n} class, e.g. {Suspend}Function2 for K{Suspend}Function2
|
||||
val numberedSupertypeKind = when (functionKind) {
|
||||
Kind.KFunction -> Kind.Function
|
||||
Kind.KSuspendFunction -> Kind.SuspendFunction
|
||||
else -> null
|
||||
}
|
||||
if (numberedSupertypeKind != null) {
|
||||
val packageView = containingDeclaration.containingDeclaration.getPackage(BUILT_INS_PACKAGE_FQ_NAME)
|
||||
val kotlinPackageFragment = packageView.fragments.filterIsInstance<BuiltInsPackageFragment>().first()
|
||||
|
||||
add(kotlinPackageFragment, numberedSupertypeKind.numberedClassName(arity))
|
||||
when (functionKind) {
|
||||
Kind.KFunction -> add(getBuiltInPackage(BUILT_INS_PACKAGE_FQ_NAME), Kind.Function.numberedClassName(arity))
|
||||
Kind.KSuspendFunction -> add(
|
||||
getBuiltInPackage(COROUTINES_PACKAGE_FQ_NAME_RELEASE),
|
||||
Kind.SuspendFunction.numberedClassName(arity)
|
||||
)
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
|
||||
return result.toList()
|
||||
}
|
||||
|
||||
private fun getBuiltInPackage(fqName: FqName): BuiltInsPackageFragment {
|
||||
val packageView = containingDeclaration.containingDeclaration.getPackage(fqName)
|
||||
return packageView.fragments.filterIsInstance<BuiltInsPackageFragment>().first()
|
||||
}
|
||||
|
||||
override fun getParameters() = this@FunctionClassDescriptor.parameters
|
||||
|
||||
override fun getDeclarationDescriptor() = this@FunctionClassDescriptor
|
||||
|
||||
Reference in New Issue
Block a user