Changes on code review

This commit is contained in:
Valentin Kipyatkov
2016-09-14 15:53:44 +03:00
parent c0ea237ba4
commit 6527ada775
6 changed files with 13 additions and 39 deletions
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.codegen;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.coroutines.CoroutineUtilKt;
import org.jetbrains.kotlin.descriptors.*;
@@ -109,12 +107,7 @@ public class JvmRuntimeTypes {
Annotations.Companion.getEMPTY(),
receiverParameter == null ? null : receiverParameter.getType(),
ExpressionTypingUtils.getValueParametersTypes(parameters),
CollectionsKt.map(parameters, new Function1<ValueParameterDescriptor, Name>() {
@Override
public Name invoke(ValueParameterDescriptor descriptor) {
return descriptor.getName();
}
}),
null,
descriptor.getReturnType()
);
@@ -143,12 +136,7 @@ public class JvmRuntimeTypes {
Annotations.Companion.getEMPTY(),
isBound ? null : receiverType,
ExpressionTypingUtils.getValueParametersTypes(parameters),
CollectionsKt.map(parameters, new Function1<ValueParameterDescriptor, Name>() {
@Override
public Name invoke(ValueParameterDescriptor descriptor) {
return descriptor.getName();
}
}),
null,
descriptor.getReturnType()
);
@@ -176,9 +176,8 @@ class DynamicCallableDescriptors(builtIns: KotlinBuiltIns) {
val receiverType = funLiteral.receiverTypeReference?.let { dynamicType }
val parameterTypes = funLiteral.valueParameters.map { dynamicType }
val parameterNames = funLiteral.valueParameters.map { it.nameAsName ?: SpecialNames.NO_NAME_PROVIDED }
return createFunctionType(owner.builtIns, Annotations.EMPTY, receiverType, parameterTypes, parameterNames, dynamicType)
return createFunctionType(owner.builtIns, Annotations.EMPTY, receiverType, parameterTypes, null, dynamicType)
}
for (arg in call.valueArguments) {
@@ -28,10 +28,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.SimpleType
import org.jetbrains.kotlin.types.TypeProjection
import org.jetbrains.kotlin.types.*
fun createValueParametersForInvokeInFunctionType(
functionDescriptor: FunctionDescriptor, parameterTypes: List<TypeProjection>
@@ -75,7 +72,13 @@ fun createFunctionType(
AnnotationsImpl(annotations + extensionFunctionAnnotation)
}
return KotlinTypeFactory.functionType(typeAnnotations, classDescriptor, arguments, parameterNames)
val simpleType = KotlinTypeFactory.simpleNotNullType(typeAnnotations, classDescriptor, arguments)
if (parameterNames == null || parameterNames.all { it.isSpecial }) {
return simpleType
}
else {
return FunctionType(simpleType, parameterNames)
}
}
fun getValueParametersCountFromFunctionType(type: KotlinType): Int {
@@ -311,7 +311,7 @@ internal class DescriptorRendererImpl(
append("(")
val parameterTypes = getValueParameterTypesFromFunctionType(type)
val parameterNames = type.getParameterNamesFromFunctionType() ?: parameterTypes.map { SpecialNames.NO_NAME_PROVIDED }
assert(parameterNames.size == parameterTypes.size)
assert(parameterNames.size == parameterTypes.size) { "Number of names does not match number of types for $type"}
for (index in parameterTypes.indices) {
val typeProjection = parameterTypes[index]
@@ -51,22 +51,6 @@ object KotlinTypeFactory {
arguments: List<TypeProjection>
): SimpleType = SimpleTypeImpl(annotations, descriptor.typeConstructor, arguments, false, descriptor.getMemberScope(arguments))
@JvmStatic
fun functionType(
annotations: Annotations,
descriptor: ClassDescriptor,
arguments: List<TypeProjection>,
parameterNames: List<Name>?
): SimpleType {
val simpleType = simpleNotNullType(annotations, descriptor, arguments)
if (parameterNames == null || parameterNames.all { it.isSpecial }) {
return simpleType
}
else {
return FunctionType(simpleType, parameterNames)
}
}
@JvmStatic
fun simpleType(
baseType: SimpleType,
@@ -151,6 +151,6 @@ private fun buildTemplate(lambdaType: KotlinType, explicitParameterTypes: Boolea
private fun functionParameterTypesAndNames(functionType: KotlinType): Pair<List<KotlinType>, List<Name>> {
val types = getValueParameterTypesFromFunctionType(functionType).map(TypeProjection::getType)
val names = functionType.getParameterNamesFromFunctionType() ?: types.map { SpecialNames.NO_NAME_PROVIDED }
assert(names.size == types.size)
assert(names.size == types.size) { "Number of names does not match number of types for $functionType"}
return types to names
}