@@ -120,11 +120,7 @@ open class KotlinFileExtractor(
120120 }
121121
122122 private fun shouldExtractDecl (declaration : IrDeclaration , extractPrivateMembers : Boolean ) =
123- extractPrivateMembers ||
124- when (declaration) {
125- is IrDeclarationWithVisibility -> declaration.visibility.let { it != DescriptorVisibilities .PRIVATE && it != DescriptorVisibilities .PRIVATE_TO_THIS }
126- else -> true
127- }
123+ extractPrivateMembers || ! isPrivate(declaration)
128124
129125 fun extractDeclaration (declaration : IrDeclaration , extractPrivateMembers : Boolean , extractFunctionBodies : Boolean ) {
130126 with (" declaration" , declaration) {
@@ -357,23 +353,37 @@ open class KotlinFileExtractor(
357353 }
358354 }
359355
356+ private fun makeTypeParamSubstitution (c : IrClass , argsIncludingOuterClasses : List <IrTypeArgument >? ) =
357+ when (argsIncludingOuterClasses) {
358+ null -> { x: IrType , _: TypeContext , _: IrPluginContext -> x.toRawType() }
359+ else -> makeGenericSubstitutionFunction(c, argsIncludingOuterClasses)
360+ }
361+
362+ fun extractDeclarationPrototype (d : IrDeclaration , parentId : Label <out DbReftype >, argsIncludingOuterClasses : List <IrTypeArgument >? , typeParamSubstitutionQ : TypeSubstitution ? = null) {
363+ val typeParamSubstitution = typeParamSubstitutionQ ? :
364+ when (val parent = d.parent) {
365+ is IrClass -> makeTypeParamSubstitution(parent, argsIncludingOuterClasses)
366+ else -> {
367+ logger.warnElement(" Unable to extract prototype of local declaration" , d)
368+ return
369+ }
370+ }
371+ when (d) {
372+ is IrFunction -> extractFunction(d, parentId, extractBody = false , extractMethodAndParameterTypeAccesses = false , typeParamSubstitution, argsIncludingOuterClasses)
373+ is IrProperty -> extractProperty(d, parentId, extractBackingField = false , extractFunctionBodies = false , extractPrivateMembers = false , typeParamSubstitution, argsIncludingOuterClasses)
374+ else -> {}
375+ }
376+ }
377+
360378 // `argsIncludingOuterClasses` can be null to describe a raw generic type.
361379 // For non-generic types it will be zero-length list.
362380 private fun extractNonPrivateMemberPrototypes (c : IrClass , argsIncludingOuterClasses : List <IrTypeArgument >? , id : Label <out DbClassorinterface >) {
363381 with (" member prototypes" , c) {
364- val typeParamSubstitution =
365- when (argsIncludingOuterClasses) {
366- null -> { x: IrType , _: TypeContext , _: IrPluginContext -> x.toRawType() }
367- else -> makeGenericSubstitutionFunction(c, argsIncludingOuterClasses)
368- }
382+ val typeParamSubstitution = makeTypeParamSubstitution(c, argsIncludingOuterClasses)
369383
370384 c.declarations.map {
371385 if (shouldExtractDecl(it, false )) {
372- when (it) {
373- is IrFunction -> extractFunction(it, id, extractBody = false , extractMethodAndParameterTypeAccesses = false , typeParamSubstitution, argsIncludingOuterClasses)
374- is IrProperty -> extractProperty(it, id, extractBackingField = false , extractFunctionBodies = false , extractPrivateMembers = false , typeParamSubstitution, argsIncludingOuterClasses)
375- else -> {}
376- }
386+ extractDeclarationPrototype(it, id, argsIncludingOuterClasses, typeParamSubstitution)
377387 }
378388 }
379389 }
0 commit comments