Skip to content

Commit

Permalink
Reformat code.
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipDolnik committed Oct 2, 2023
1 parent e17f263 commit 00e56fd
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ interface DescriptorProvider {

fun DescriptorProvider.getAllExposedMembers(classDescriptor: ClassDescriptor): List<CallableMemberDescriptor> =
this.getExposedClassMembers(classDescriptor) +
this.getExposedCategoryMembers(classDescriptor) +
this.getExposedConstructors(classDescriptor)
this.getExposedCategoryMembers(classDescriptor) +
this.getExposedConstructors(classDescriptor)

val DescriptorProvider.allExposedMembers: List<CallableMemberDescriptor>
get() = (this.exposedFiles.flatMap { this.getExposedStaticMembers(it) } +
this.exposedClasses.flatMap { this.getExposedClassMembers(it) + this.getExposedConstructors(it) }) +
this.exposedCategoryMembers
this.exposedClasses.flatMap { this.getExposedClassMembers(it) + this.getExposedConstructors(it) }) +
this.exposedCategoryMembers

val DescriptorProvider.modulesWithExposedDeclarations: Set<ModuleDescriptor>
get() = (exposedClasses.map { it.module } + exposedFiles.map { getFileModule(it) }).toSet()
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class NativeDescriptorProvider(
@get:JvmName("isExposedExtension")
private val CallableMemberDescriptor.isExposed: Boolean
get() = this in exposedTopLevelMembers ||
this in exposedCategoryMembers ||
(this.containingDeclaration in exposedClasses && this.isExposable)
this in exposedCategoryMembers ||
(this.containingDeclaration in exposedClasses && this.isExposable)

fun registerExposedDescriptor(descriptor: DeclarationDescriptor) {
when (descriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DeclarationBuilderImpl(
val sourceFile = existingMember.findSourceFileOrNull()

val hasOriginalPackage = existingMember.findPackage() is DeserializedPackageFragment &&
sourceFile in originalExposedFiles
sourceFile in originalExposedFiles

return when {
sourceFile == null -> getCustomNamespace(existingMember.findPackage().name.asStringStripSpecialMarkers())
Expand Down Expand Up @@ -173,7 +173,7 @@ class DeclarationBuilderImpl(

private fun SymbolTable.allExposedTypeParameters(descriptorProvider: DescriptorProvider): List<IrTypeParameter> =
(descriptorProvider.allExposedMembers.flatMap { referenceBoundTypeParameterContainer(it) } +
descriptorProvider.exposedClasses.flatMap { referenceBoundTypeParameterContainer(it) })
descriptorProvider.exposedClasses.flatMap { referenceBoundTypeParameterContainer(it) })
.flatMap { it.typeParameters }

private fun SymbolTable.referenceBoundTypeParameterContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object ApiNotesFactory {
context(SirPhase.Context)
private val DescriptorProvider.swiftModelsForClassesAndFiles: List<KotlinTypeSwiftModel>
get() = this.exposedClasses.filterNot { it.kind.isInterface }.map { it.swiftModel } +
this.exposedFiles.map { it.swiftModel }
this.exposedFiles.map { it.swiftModel }

context(SirPhase.Context)
private val DescriptorProvider.swiftModelsForInterfaces: List<KotlinTypeSwiftModel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ abstract class BaseDefaultArgumentGeneratorDelegate(
context(SkiePhase.Context)
protected val FunctionDescriptor.isInteropEnabled: Boolean
get() = this.getConfiguration(DefaultArgumentInterop.Enabled) &&
this.satisfiesMaximumDefaultArgumentCount &&
(descriptorProvider.isFromLocalModule(this) || isInteropEnabledForExternalModules)
this.satisfiesMaximumDefaultArgumentCount &&
(descriptorProvider.isFromLocalModule(this) || isInteropEnabledForExternalModules)

context(SkiePhase.Context)
private val FunctionDescriptor.satisfiesMaximumDefaultArgumentCount: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object ExhaustiveEnumsGenerator : SirPhase {
context(SkiePhase.Context)
private val KotlinClassSwiftModel.isSupported: Boolean
get() = this.classDescriptor.kind.isEnumClass &&
this.classDescriptor.isEnumInteropEnabled
this.classDescriptor.isEnumInteropEnabled

context(SkiePhase.Context)
private val ClassDescriptor.isEnumInteropEnabled: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import co.touchlab.skie.sir.element.toTypeParameterUsage
import co.touchlab.skie.sir.type.SirType
import co.touchlab.skie.sir.type.TypeParameterUsageSirType
import co.touchlab.skie.swiftmodel.SwiftModelScope
import io.outfoxx.swiftpoet.Modifier

object FlowConversionConstructorsGenerator : SirPhase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ class SealedFunctionGeneratorDelegate(
} else {
add(
"fatalError(" +
"\"Unknown subtype. " +
"This error should not happen under normal circumstances " +
"since ${swiftModel.primarySirClass} is sealed." +
"\")\n",
"\"Unknown subtype. " +
"This error should not happen under normal circumstances " +
"since ${swiftModel.primarySirClass} is sealed." +
"\")\n",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ interface SealedGeneratorExtensionContainer {

val KotlinClassSwiftModel.hasElseCase: Boolean
get() = this.hasUnexposedSealedSubclasses ||
this.exposedSealedSubclasses.size != this.visibleSealedSubclasses.size ||
this.visibleSealedSubclasses.isEmpty()
this.exposedSealedSubclasses.size != this.visibleSealedSubclasses.size ||
this.visibleSealedSubclasses.isEmpty()

val KotlinClassSwiftModel.visibleSealedSubclasses: List<KotlinClassSwiftModel>
get() = this.exposedSealedSubclasses.filter { configurationProvider.getConfiguration(it, SealedInterop.Case.Visible) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class KotlinSuspendGeneratorDelegate(
private fun ValueParameterDescriptor.configureExtensionReceiverFlowMapping(originalFunctionDescriptor: FunctionDescriptor) {
context.doInPhase(SuspendGenerator.KotlinBridgeConfigurationPhase) {
val isExtensionReceiverUsedAsSwiftReceiver = originalFunctionDescriptor.swiftModel.scope.isMember &&
originalFunctionDescriptor.dispatchReceiverParameter == null
originalFunctionDescriptor.dispatchReceiverParameter == null

if (isExtensionReceiverUsedAsSwiftReceiver) {
this@configureExtensionReceiverFlowMapping.swiftModel.flowMappingStrategy = FlowMappingStrategy.TypeArgumentsOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ object SuspendGenerator : DescriptorModificationPhase {
context(DescriptorModificationPhase.Context)
override fun isActive(): Boolean = isEnabled()

private fun SkiePhase.Context.isEnabled(): Boolean = SkieConfigurationFlag.Feature_CoroutinesInterop in skieConfiguration.enabledConfigurationFlags
private fun SkiePhase.Context.isEnabled(): Boolean =
SkieConfigurationFlag.Feature_CoroutinesInterop in skieConfiguration.enabledConfigurationFlags

context(DescriptorModificationPhase.Context)
override fun execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class AddForwardDeclarationsPhase(
val knownDeclarations = forwardDeclarations + definedDeclarations

val missingExternalReferencedDeclarations = referencedDeclarations.filterNotIn(knownDeclarations)
val definedDeclarationsWithoutForwardDeclaration = definedDeclarations.filter { it.name !in forwardDeclarationsNames }.map { it.toString() }
val definedDeclarationsWithoutForwardDeclaration =
definedDeclarations.filter { it.name !in forwardDeclarationsNames }.map { it.toString() }

return missingExternalReferencedDeclarations + definedDeclarationsWithoutForwardDeclaration
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ExtraClassExportPhase(
}

val allFlowArguments = descriptorProvider.allExposedMembers.flatMap { it.getAllFlowArgumentClasses() } +
descriptorProvider.exposedClasses.flatMap { it.getAllFlowArgumentClasses() }
descriptorProvider.exposedClasses.flatMap { it.getAllFlowArgumentClasses() }

val allExposableFlowArguments = allFlowArguments.filter { descriptorProvider.isExposable(it) }

Expand Down Expand Up @@ -136,9 +136,12 @@ private fun ClassDescriptor.getAllFlowArgumentClasses(): List<ClassDescriptor> =

private fun CallableMemberDescriptor.getAllFlowArgumentClasses(): List<ClassDescriptor> =
typeParameters.flatMap { it.getAllFlowArgumentClasses() } +
valueParameters.flatMap { it.type.getAllFlowArgumentClasses() } +
(returnType?.getAllFlowArgumentClasses() ?: emptyList()) +
(contextReceiverParameters + listOfNotNull(dispatchReceiverParameter, extensionReceiverParameter)).flatMap { it.getAllFlowArgumentClasses() }
valueParameters.flatMap { it.type.getAllFlowArgumentClasses() } +
(returnType?.getAllFlowArgumentClasses() ?: emptyList()) +
(contextReceiverParameters + listOfNotNull(
dispatchReceiverParameter,
extensionReceiverParameter
)).flatMap { it.getAllFlowArgumentClasses() }

// Sacrifices some completeness for simplicity - otherwise it would have to check all usages of the type parameter.
private fun TypeParameterDescriptor.getAllFlowArgumentClasses(): List<ClassDescriptor> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ object VerifyMinOSVersionPhase : ClassExportPhase {
if (currentMinVersion.isLowerVersionThan(minRequiredVersion)) {
error(
"Minimum OS version for ${configurables.target.name} must be at least $minRequiredVersion to support Swift Async. " +
"However, the configured minimum OS version is only $currentMinVersion. " +
"This is most likely a bug in SKIE Gradle plugin which should have set the minimum required version automatically.",
"However, the configured minimum OS version is only $currentMinVersion. " +
"This is most likely a bug in SKIE Gradle plugin which should have set the minimum required version automatically.",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ private val SirDeclaration.defaultVisibility: SirVisibility
private val SirOverridableDeclaration<*>.needsOverride: Boolean
get() = overriddenDeclarations.any { it.memberOwner?.kind == SirClass.Kind.Class }


private fun <T> T.applyIf(condition: Boolean, action: T.() -> Unit): T =
this.apply {
if (condition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ object SwiftCacheSetupPhase : SirPhase {

// Must use `or` to prevent short circuit optimization.
return framework.kotlinHeader.copyFileToIfDifferent(dummyFramework.kotlinHeader) or
framework.modulemapFile.copyFileToIfDifferent(dummyFramework.modulemapFile) or
skieBuildDirectory.swiftCompiler.apiNotes.apiNotes(framework.moduleName)
.copyFileToIfDifferent(dummyFramework.apiNotes)
framework.modulemapFile.copyFileToIfDifferent(dummyFramework.modulemapFile) or
skieBuildDirectory.swiftCompiler.apiNotes.apiNotes(framework.moduleName)
.copyFileToIfDifferent(dummyFramework.apiNotes)
}

// Solves a bug in Swift compiler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object RenameTypesConflictingWithKotlinModulePhase : SirPhase {
private fun logModuleNameCollisionWarning(moduleName: String) {
reporter.warning(
"Type '$moduleName' was renamed to '${moduleName}_' " +
"because it has the same name as the produced framework which is forbidden.",
"because it has the same name as the produced framework which is forbidden.",
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ class SwiftModelProvider(
translator.mapReferenceType(
this.defaultType,
// TODO ?: SwiftGenericExportScope.None is a hack that relies on the fact that none of the types with SwiftModel can inherit from a special type that is generic
SwiftExportScope(this.swiftModelOrNull?.swiftGenericExportScope ?: SwiftGenericExportScope.None, SwiftExportScope.Flags.ReferenceType),
SwiftExportScope(
this.swiftModelOrNull?.swiftGenericExportScope ?: SwiftGenericExportScope.None,
SwiftExportScope.Flags.ReferenceType
),
FlowMappingStrategy.TypeArgumentsOnly,
)

Expand Down Expand Up @@ -241,8 +244,8 @@ class SwiftModelProvider(
private fun DeclarationDescriptor.throwUnknownDescriptor(): Nothing {
throw IllegalArgumentException(
"Cannot find SwiftModel for descriptor: $this. Possible reasons: " +
"Descriptor is not exposed and therefore does not have a SwiftModel. " +
"Or it is exposed but as another type (for example as ConvertedProperty instead of a RegularProperty).",
"Descriptor is not exposed and therefore does not have a SwiftModel. " +
"Or it is exposed but as another type (for example as ConvertedProperty instead of a RegularProperty).",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ObjCTypeProvider(
if (!returnBridge.successMayBeZero) {
check(
successReturnType is ObjCNonNullReferenceType
|| (successReturnType is ObjCPointerType && !successReturnType.nullable),
|| (successReturnType is ObjCPointerType && !successReturnType.nullable),
) {
"Unexpected return type: $successReturnType in $method"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class SwiftModelFactoryMembersDelegate(
group: List<PropertyDescriptor>,
): Map<CallableMemberDescriptor, MutableKotlinCallableMemberSwiftModel> =
createBoundedConvertedPropertiesEnclosingModels(group) +
createBoundedConvertedPropertiesFunctions(group)
createBoundedConvertedPropertiesFunctions(group)

private fun createBoundedConvertedPropertiesEnclosingModels(
group: List<PropertyDescriptor>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class SwiftTypeTranslator(

reporter.warning(
"Exposed type '$kotlinType' is '$firstType' and '$secondType' at the same time. " +
"This most likely wouldn't work as expected.",
"This most likely wouldn't work as expected.",
)
}

Expand Down Expand Up @@ -300,7 +300,7 @@ class SwiftTypeTranslator(
}

val parameterTypes = listOfNotNull(functionType.getReceiverTypeFromFunctionType()) +
functionType.getValueParameterTypesFromFunctionType().map { it.type }
functionType.getValueParameterTypesFromFunctionType().map { it.type }

return LambdaSirType(
if (returnsVoid) {
Expand Down

0 comments on commit 00e56fd

Please sign in to comment.