J2K JvmRuntimeTypes: prettify
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen
|
package org.jetbrains.kotlin.codegen
|
||||||
|
|
||||||
import org.jetbrains.kotlin.coroutines.*
|
import org.jetbrains.kotlin.coroutines.controllerTypeIfCoroutine
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||||
@@ -25,14 +25,14 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.*
|
import org.jetbrains.kotlin.resolve.calls.util.createFunctionType
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.*
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeConstructorSubstitution
|
import org.jetbrains.kotlin.types.TypeConstructorSubstitution
|
||||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class JvmRuntimeTypes(module: ModuleDescriptor) {
|
class JvmRuntimeTypes(module: ModuleDescriptor) {
|
||||||
@@ -55,93 +55,75 @@ class JvmRuntimeTypes(module: ModuleDescriptor) {
|
|||||||
this.mutablePropertyReferences = ArrayList<ClassDescriptor>(3)
|
this.mutablePropertyReferences = ArrayList<ClassDescriptor>(3)
|
||||||
|
|
||||||
for (i in 0..2) {
|
for (i in 0..2) {
|
||||||
propertyReferences.add(createClass(kotlinJvmInternal, "PropertyReference" + i))
|
propertyReferences.add(createClass(kotlinJvmInternal, "PropertyReference$i"))
|
||||||
mutablePropertyReferences.add(createClass(kotlinJvmInternal, "MutablePropertyReference" + i))
|
mutablePropertyReferences.add(createClass(kotlinJvmInternal, "MutablePropertyReference$i"))
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultContinuationSupertype = createNullableAnyContinuation(module)
|
defaultContinuationSupertype = createNullableAnyContinuation(module)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param module
|
* @return `Continuation<Any?>` type
|
||||||
* *
|
|
||||||
* @return Continuation<Any></Any>?> type
|
|
||||||
*/
|
*/
|
||||||
private fun createNullableAnyContinuation(module: ModuleDescriptor): KotlinType {
|
private fun createNullableAnyContinuation(module: ModuleDescriptor): KotlinType {
|
||||||
val classDescriptor = module.resolveTopLevelClass(DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME, NoLookupLocation.FROM_BACKEND) ?: error(DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME + " was not found in built-ins")
|
val classDescriptor = module.resolveTopLevelClass(
|
||||||
|
DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME, NoLookupLocation.FROM_BACKEND
|
||||||
|
) ?: error("${DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME} was not found in built-ins")
|
||||||
|
|
||||||
|
return TypeConstructorSubstitution.createByParametersMap(
|
||||||
return TypeConstructorSubstitution
|
mapOf(classDescriptor.declaredTypeParameters.single() to TypeProjectionImpl(module.builtIns.nullableAnyType))
|
||||||
.createByParametersMap(Collections.singletonMap(classDescriptor.declaredTypeParameters[0],
|
).buildSubstitutor().substitute(classDescriptor.defaultType, Variance.INVARIANT)!!
|
||||||
TypeProjectionImpl(module.builtIns.nullableAnyType)))
|
|
||||||
.buildSubstitutor().substitute(classDescriptor.defaultType, Variance.INVARIANT)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createClass(packageFragment: PackageFragmentDescriptor, name: String): ClassDescriptor {
|
private fun createClass(packageFragment: PackageFragmentDescriptor, name: String): ClassDescriptor =
|
||||||
val descriptor = MutableClassDescriptor(
|
MutableClassDescriptor(packageFragment, ClassKind.CLASS, false, Name.identifier(name), SourceElement.NO_SOURCE).apply {
|
||||||
packageFragment, ClassKind.CLASS, false, Name.identifier(name), SourceElement.NO_SOURCE
|
modality = Modality.FINAL
|
||||||
)
|
visibility = Visibilities.PUBLIC
|
||||||
|
setTypeParameterDescriptors(emptyList())
|
||||||
descriptor.modality = Modality.FINAL
|
createTypeConstructor()
|
||||||
descriptor.visibility = Visibilities.PUBLIC
|
}
|
||||||
descriptor.setTypeParameterDescriptors(emptyList<TypeParameterDescriptor>())
|
|
||||||
descriptor.createTypeConstructor()
|
|
||||||
|
|
||||||
return descriptor
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getSupertypesForClosure(descriptor: FunctionDescriptor): Collection<KotlinType> {
|
fun getSupertypesForClosure(descriptor: FunctionDescriptor): Collection<KotlinType> {
|
||||||
val receiverParameter = descriptor.extensionReceiverParameter
|
|
||||||
|
|
||||||
|
|
||||||
val parameters = descriptor.valueParameters
|
|
||||||
val functionType = createFunctionType(
|
val functionType = createFunctionType(
|
||||||
descriptor.builtIns,
|
descriptor.builtIns,
|
||||||
Annotations.EMPTY,
|
Annotations.EMPTY,
|
||||||
receiverParameter?.type,
|
descriptor.extensionReceiverParameter?.type,
|
||||||
ExpressionTypingUtils.getValueParametersTypes(parameters),
|
ExpressionTypingUtils.getValueParametersTypes(descriptor.valueParameters),
|
||||||
null,
|
null,
|
||||||
descriptor.returnType!!
|
descriptor.returnType!!
|
||||||
)
|
)
|
||||||
|
|
||||||
val coroutineControllerType = descriptor.controllerTypeIfCoroutine
|
val coroutineControllerType = descriptor.controllerTypeIfCoroutine
|
||||||
|
|
||||||
if (coroutineControllerType != null) {
|
if (coroutineControllerType != null) {
|
||||||
return Arrays.asList(
|
return listOf(lambda.defaultType, functionType, /*coroutineType,*/ defaultContinuationSupertype)
|
||||||
lambda.defaultType, functionType, /*coroutineType,*/ defaultContinuationSupertype)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Arrays.asList<KotlinType>(lambda.defaultType, functionType)
|
return listOf(lambda.defaultType, functionType)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSupertypesForFunctionReference(descriptor: FunctionDescriptor, isBound: Boolean): Collection<KotlinType> {
|
fun getSupertypesForFunctionReference(descriptor: FunctionDescriptor, isBound: Boolean): Collection<KotlinType> {
|
||||||
val extensionReceiver = descriptor.extensionReceiverParameter
|
|
||||||
val dispatchReceiver = descriptor.dispatchReceiverParameter
|
|
||||||
|
|
||||||
val receiverType = if (extensionReceiver != null) extensionReceiver.type else dispatchReceiver?.type
|
|
||||||
|
|
||||||
|
|
||||||
val parameters = descriptor.valueParameters
|
|
||||||
val functionType = createFunctionType(
|
val functionType = createFunctionType(
|
||||||
descriptor.builtIns,
|
descriptor.builtIns,
|
||||||
Annotations.EMPTY,
|
Annotations.EMPTY,
|
||||||
if (isBound) null else receiverType,
|
if (isBound) null else descriptor.extensionReceiverParameter?.type ?: descriptor.dispatchReceiverParameter?.type,
|
||||||
ExpressionTypingUtils.getValueParametersTypes(parameters),
|
ExpressionTypingUtils.getValueParametersTypes(descriptor.valueParameters),
|
||||||
null,
|
null,
|
||||||
descriptor.returnType!!
|
descriptor.returnType!!
|
||||||
)
|
)
|
||||||
|
|
||||||
return Arrays.asList<KotlinType>(functionReference.defaultType, functionType)
|
return listOf(functionReference.defaultType, functionType)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSupertypeForPropertyReference(
|
fun getSupertypeForPropertyReference(descriptor: VariableDescriptorWithAccessors, isMutable: Boolean, isBound: Boolean): KotlinType {
|
||||||
descriptor: VariableDescriptorWithAccessors, isMutable: Boolean, isBound: Boolean
|
|
||||||
): KotlinType {
|
|
||||||
if (descriptor is LocalVariableDescriptor) {
|
if (descriptor is LocalVariableDescriptor) {
|
||||||
return (if (isMutable) mutableLocalVariableReference else localVariableReference).defaultType
|
return (if (isMutable) mutableLocalVariableReference else localVariableReference).defaultType
|
||||||
}
|
}
|
||||||
|
|
||||||
val arity = (if (descriptor.extensionReceiverParameter != null) 1 else 0) + (if (descriptor.dispatchReceiverParameter != null) 1 else 0) - if (isBound) 1 else 0
|
val arity =
|
||||||
|
(if (descriptor.extensionReceiverParameter != null) 1 else 0) +
|
||||||
|
(if (descriptor.dispatchReceiverParameter != null) 1 else 0) -
|
||||||
|
if (isBound) 1 else 0
|
||||||
|
|
||||||
return (if (isMutable) mutablePropertyReferences else propertyReferences)[arity].defaultType
|
return (if (isMutable) mutablePropertyReferences else propertyReferences)[arity].defaultType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user