Minor, reformat and slightly refactor JvmRuntimeTypes.kt

This commit is contained in:
Alexander Udalov
2020-02-14 16:25:32 +01:00
parent 8588f96ec8
commit 058c6bc578
@@ -30,34 +30,24 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
private val kotlinCoroutinesJvmInternalPackage = private val kotlinCoroutinesJvmInternalPackage =
MutablePackageFragmentDescriptor(module, languageVersionSettings.coroutinesJvmInternalPackageFqName()) MutablePackageFragmentDescriptor(module, languageVersionSettings.coroutinesJvmInternalPackageFqName())
private fun klass(name: String) = lazy { createClass(kotlinJvmInternalPackage, name) } private fun internal(className: String, packageFragment: PackageFragmentDescriptor = kotlinJvmInternalPackage): Lazy<ClassDescriptor> =
lazy { createClass(packageFragment, className) }
private val lambda: ClassDescriptor by klass("Lambda") private fun coroutinesInternal(name: String): Lazy<ClassDescriptor> =
val functionReference: ClassDescriptor by klass("FunctionReference") lazy { createCoroutineSuperClass(name) }
private val localVariableReference: ClassDescriptor by klass("LocalVariableReference")
private val mutableLocalVariableReference: ClassDescriptor by klass("MutableLocalVariableReference")
private val coroutineImpl: ClassDescriptor by lazy { private val lambda: ClassDescriptor by internal("Lambda")
createClass(kotlinCoroutinesJvmInternalPackage, "CoroutineImpl") private val functionReference: ClassDescriptor by internal("FunctionReference")
} private val localVariableReference: ClassDescriptor by internal("LocalVariableReference")
private val mutableLocalVariableReference: ClassDescriptor by internal("MutableLocalVariableReference")
private val continuationImpl by lazy { private val coroutineImpl: ClassDescriptor by internal("CoroutineImpl", kotlinCoroutinesJvmInternalPackage)
createCoroutineSuperClass("ContinuationImpl") private val continuationImpl: ClassDescriptor by coroutinesInternal("ContinuationImpl")
} private val restrictedContinuationImpl: ClassDescriptor by coroutinesInternal("RestrictedContinuationImpl")
private val suspendLambda: ClassDescriptor by coroutinesInternal("SuspendLambda")
private val restrictedSuspendLambda: ClassDescriptor by coroutinesInternal("RestrictedSuspendLambda")
private val restrictedContinuationImpl by lazy { private val suspendFunctionInterface: ClassDescriptor? by lazy {
createCoroutineSuperClass("RestrictedContinuationImpl")
}
private val suspendLambda by lazy {
createCoroutineSuperClass("SuspendLambda")
}
private val restrictedSuspendLambda by lazy {
createCoroutineSuperClass("RestrictedSuspendLambda")
}
private val suspendFunctionInterface by lazy {
if (languageVersionSettings.isReleaseCoroutines()) if (languageVersionSettings.isReleaseCoroutines())
createClass(kotlinCoroutinesJvmInternalPackage, "SuspendFunction", ClassKind.INTERFACE) createClass(kotlinCoroutinesJvmInternalPackage, "SuspendFunction", ClassKind.INTERFACE)
else null else null
@@ -83,8 +73,9 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
name: String, name: String,
classKind: ClassKind = ClassKind.CLASS classKind: ClassKind = ClassKind.CLASS
): ClassDescriptor = ): ClassDescriptor =
MutableClassDescriptor(packageFragment, classKind, /* isInner = */ false, /* isExternal = */ false, MutableClassDescriptor(
Name.identifier(name), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS).apply { packageFragment, classKind, false, false, Name.identifier(name), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS
).apply {
modality = Modality.FINAL modality = Modality.FINAL
visibility = Visibilities.PUBLIC visibility = Visibilities.PUBLIC
setTypeParameterDescriptors(emptyList()) setTypeParameterDescriptors(emptyList())
@@ -92,7 +83,6 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
} }
fun getSupertypesForClosure(descriptor: FunctionDescriptor): Collection<KotlinType> { fun getSupertypesForClosure(descriptor: FunctionDescriptor): Collection<KotlinType> {
val actualFunctionDescriptor = val actualFunctionDescriptor =
if (descriptor.isSuspend) if (descriptor.isSuspend)
getOrCreateJvmSuspendFunctionView(descriptor, languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)) getOrCreateJvmSuspendFunctionView(descriptor, languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines))
@@ -110,7 +100,9 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
if (descriptor.isSuspend) { if (descriptor.isSuspend) {
return mutableListOf<KotlinType>().apply { return mutableListOf<KotlinType>().apply {
if (actualFunctionDescriptor.extensionReceiverParameter?.type?.isRestrictsSuspensionReceiver(languageVersionSettings) == true) { if (actualFunctionDescriptor.extensionReceiverParameter?.type
?.isRestrictsSuspensionReceiver(languageVersionSettings) == true
) {
if (descriptor.isSuspendLambdaOrLocalFunction()) { if (descriptor.isSuspendLambdaOrLocalFunction()) {
add(restrictedSuspendLambda.defaultType) add(restrictedSuspendLambda.defaultType)
} else { } else {