Minor: fix warnings and reformat
This commit is contained in:
committed by
Ilya Gorbunov
parent
c7a5a7ebd5
commit
ff9ba97d66
@@ -37,12 +37,11 @@ fun patchTypeParametersForDefaultImplMethod(function: CallableMemberDescriptor):
|
|||||||
|
|
||||||
val existingNames = (functionTypeParameterNames + interfaceTypeParameters.map { it.name.asString() }).toMutableSet()
|
val existingNames = (functionTypeParameterNames + interfaceTypeParameters.map { it.name.asString() }).toMutableSet()
|
||||||
|
|
||||||
val mappingForInterfaceTypeParameters = conflictedTypeParameters.associateBy ({ it }) {
|
val mappingForInterfaceTypeParameters = conflictedTypeParameters.associateBy({ it }) { typeParameter ->
|
||||||
typeParameter ->
|
|
||||||
|
|
||||||
val newNamePrefix = typeParameter.name.asString() + "_I"
|
val newNamePrefix = typeParameter.name.asString() + "_I"
|
||||||
val newName = newNamePrefix + generateSequence(1) { x -> x + 1 }.first {
|
val newName = newNamePrefix + generateSequence(1) { x -> x + 1 }.first { index ->
|
||||||
index -> (newNamePrefix + index) !in existingNames
|
(newNamePrefix + index) !in existingNames
|
||||||
}
|
}
|
||||||
|
|
||||||
existingNames.add(newName)
|
existingNames.add(newName)
|
||||||
@@ -58,13 +57,16 @@ fun patchTypeParametersForDefaultImplMethod(function: CallableMemberDescriptor):
|
|||||||
val additionalTypeParameters = interfaceTypeParameters.map { typeParameter ->
|
val additionalTypeParameters = interfaceTypeParameters.map { typeParameter ->
|
||||||
mappingForInterfaceTypeParameters[typeParameter] ?: typeParameter
|
mappingForInterfaceTypeParameters[typeParameter] ?: typeParameter
|
||||||
}
|
}
|
||||||
var resultTypeParameters = mutableListOf<TypeParameterDescriptor>()
|
val resultTypeParameters = mutableListOf<TypeParameterDescriptor>()
|
||||||
DescriptorSubstitutor.substituteTypeParameters(additionalTypeParameters, substitution, classDescriptor, resultTypeParameters)
|
DescriptorSubstitutor.substituteTypeParameters(additionalTypeParameters, substitution, classDescriptor, resultTypeParameters)
|
||||||
|
|
||||||
return ReceiverTypeAndTypeParameters(substitutor.substitute(classDescriptor.defaultType, Variance.INVARIANT)!!, resultTypeParameters)
|
return ReceiverTypeAndTypeParameters(substitutor.substitute(classDescriptor.defaultType, Variance.INVARIANT)!!, resultTypeParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun CallableMemberDescriptor.createTypeParameterWithNewName(descriptor: TypeParameterDescriptor, newName: String): TypeParameterDescriptorImpl {
|
fun CallableMemberDescriptor.createTypeParameterWithNewName(
|
||||||
|
descriptor: TypeParameterDescriptor,
|
||||||
|
newName: String
|
||||||
|
): TypeParameterDescriptorImpl {
|
||||||
val newDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
val newDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
||||||
this,
|
this,
|
||||||
descriptor.annotations,
|
descriptor.annotations,
|
||||||
@@ -72,7 +74,8 @@ fun CallableMemberDescriptor.createTypeParameterWithNewName(descriptor: TypePara
|
|||||||
descriptor.variance,
|
descriptor.variance,
|
||||||
Name.identifier(newName),
|
Name.identifier(newName),
|
||||||
descriptor.index,
|
descriptor.index,
|
||||||
descriptor.source)
|
descriptor.source
|
||||||
|
)
|
||||||
descriptor.upperBounds.forEach {
|
descriptor.upperBounds.forEach {
|
||||||
newDescriptor.addUpperBound(it)
|
newDescriptor.addUpperBound(it)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ fun <T : Any> mapType(
|
|||||||
|
|
||||||
val descriptor =
|
val descriptor =
|
||||||
constructor.declarationDescriptor
|
constructor.declarationDescriptor
|
||||||
?: throw UnsupportedOperationException("no descriptor for type constructor of " + kotlinType)
|
?: throw UnsupportedOperationException("no descriptor for type constructor of $kotlinType")
|
||||||
|
|
||||||
when {
|
when {
|
||||||
ErrorUtils.isError(descriptor) -> {
|
ErrorUtils.isError(descriptor) -> {
|
||||||
@@ -150,9 +150,11 @@ fun <T : Any> mapType(
|
|||||||
typeMappingConfiguration.getPredefinedTypeForClass(descriptor.original)
|
typeMappingConfiguration.getPredefinedTypeForClass(descriptor.original)
|
||||||
?: run {
|
?: run {
|
||||||
// refer to enum entries by enum type in bytecode unless ASM_TYPE is written
|
// refer to enum entries by enum type in bytecode unless ASM_TYPE is written
|
||||||
val enumClassIfEnumEntry = if (descriptor.kind == ClassKind.ENUM_ENTRY)
|
val enumClassIfEnumEntry =
|
||||||
|
if (descriptor.kind == ClassKind.ENUM_ENTRY)
|
||||||
descriptor.containingDeclaration as ClassDescriptor
|
descriptor.containingDeclaration as ClassDescriptor
|
||||||
else descriptor
|
else
|
||||||
|
descriptor
|
||||||
factory.createObjectType(
|
factory.createObjectType(
|
||||||
computeInternalName(
|
computeInternalName(
|
||||||
enumClassIfEnumEntry.original,
|
enumClassIfEnumEntry.original,
|
||||||
@@ -182,7 +184,7 @@ fun <T : Any> mapType(
|
|||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> throw UnsupportedOperationException("Unknown type " + kotlinType)
|
else -> throw UnsupportedOperationException("Unknown type $kotlinType")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +231,8 @@ private fun <T : Any> mapBuiltInType(
|
|||||||
val classId = JavaToKotlinClassMap.mapKotlinToJava(descriptor.fqNameUnsafe)
|
val classId = JavaToKotlinClassMap.mapKotlinToJava(descriptor.fqNameUnsafe)
|
||||||
if (classId != null) {
|
if (classId != null) {
|
||||||
if (!mode.kotlinCollectionsToJavaCollections &&
|
if (!mode.kotlinCollectionsToJavaCollections &&
|
||||||
JavaToKotlinClassMap.mutabilityMappings.any { it.javaClass == classId }) return null
|
JavaToKotlinClassMap.mutabilityMappings.any { it.javaClass == classId }
|
||||||
|
) return null
|
||||||
|
|
||||||
return typeFactory.createObjectType(JvmClassName.byClassId(classId).internalName)
|
return typeFactory.createObjectType(JvmClassName.byClassId(classId).internalName)
|
||||||
}
|
}
|
||||||
@@ -277,16 +280,15 @@ fun computeInternalName(
|
|||||||
typeMappingConfiguration,
|
typeMappingConfiguration,
|
||||||
isIrBackend
|
isIrBackend
|
||||||
)
|
)
|
||||||
return containerInternalName + "$" + name
|
return "$containerInternalName$$name"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getContainer(container: DeclarationDescriptor?): DeclarationDescriptor? =
|
private fun getContainer(container: DeclarationDescriptor?): DeclarationDescriptor? =
|
||||||
container as? ClassDescriptor ?: container as? PackageFragmentDescriptor ?:
|
container as? ClassDescriptor ?: container as? PackageFragmentDescriptor ?: container?.let { getContainer(it.containingDeclaration) }
|
||||||
container?.let { getContainer(it.containingDeclaration) }
|
|
||||||
|
|
||||||
private fun getRepresentativeUpperBound(descriptor: TypeParameterDescriptor): KotlinType {
|
private fun getRepresentativeUpperBound(descriptor: TypeParameterDescriptor): KotlinType {
|
||||||
val upperBounds = descriptor.upperBounds
|
val upperBounds = descriptor.upperBounds
|
||||||
assert(!upperBounds.isEmpty()) { "Upper bounds should not be empty: " + descriptor }
|
assert(!upperBounds.isEmpty()) { "Upper bounds should not be empty: $descriptor" }
|
||||||
|
|
||||||
return upperBounds.firstOrNull {
|
return upperBounds.firstOrNull {
|
||||||
val classDescriptor = it.constructor.declarationDescriptor as? ClassDescriptor ?: return@firstOrNull false
|
val classDescriptor = it.constructor.declarationDescriptor as? ClassDescriptor ?: return@firstOrNull false
|
||||||
|
|||||||
Reference in New Issue
Block a user