KT-41346 Move removing non-available functions to protected method
This would allow to stricten contract on `computeNonDeclaredFunctions`
This commit is contained in:
+4
-4
@@ -246,16 +246,16 @@ class DeserializedClassDescriptor(
|
||||
return super.getContributedVariables(name, location)
|
||||
}
|
||||
|
||||
override fun isDeclaredFunctionAvailable(function: SimpleFunctionDescriptor): Boolean {
|
||||
return c.components.platformDependentDeclarationFilter.isFunctionAvailable(this@DeserializedClassDescriptor, function)
|
||||
}
|
||||
|
||||
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
||||
val fromSupertypes = ArrayList<SimpleFunctionDescriptor>()
|
||||
for (supertype in refinedSupertypes()) {
|
||||
fromSupertypes.addAll(supertype.memberScope.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED))
|
||||
}
|
||||
|
||||
functions.retainAll {
|
||||
c.components.platformDependentDeclarationFilter.isFunctionAvailable(this@DeserializedClassDescriptor, it)
|
||||
}
|
||||
|
||||
functions.addAll(c.components.additionalClassPartsProvider.getFunctions(name, this@DeserializedClassDescriptor))
|
||||
generateFakeOverrides(name, fromSupertypes, functions)
|
||||
}
|
||||
|
||||
+10
-5
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.compact
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
abstract class DeserializedMemberScope protected constructor(
|
||||
protected val c: DeserializationContext,
|
||||
@@ -104,7 +104,7 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
name,
|
||||
functionProtosBytes,
|
||||
ProtoBuf.Function.PARSER,
|
||||
{ c.memberDeserializer.loadFunction(it) },
|
||||
{ c.memberDeserializer.loadFunction(it).takeIf(::isDeclaredFunctionAvailable) },
|
||||
{ computeNonDeclaredFunctions(name, it) }
|
||||
)
|
||||
|
||||
@@ -112,7 +112,7 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
name: Name,
|
||||
bytesByName: Map<Name, ByteArray>,
|
||||
parser: Parser<M>,
|
||||
factory: (M) -> D,
|
||||
factory: (M) -> D?,
|
||||
computeNonDeclared: (MutableCollection<D>) -> Unit
|
||||
): Collection<D> =
|
||||
computeDescriptors(
|
||||
@@ -128,15 +128,20 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
|
||||
private inline fun <M : MessageLite, D : DeclarationDescriptor> computeDescriptors(
|
||||
protos: Collection<M>,
|
||||
factory: (M) -> D,
|
||||
factory: (M) -> D?,
|
||||
computeNonDeclared: (MutableCollection<D>) -> Unit
|
||||
): Collection<D> {
|
||||
val descriptors = protos.mapTo(arrayListOf(), factory)
|
||||
val descriptors = protos.mapNotNullTo(ArrayList(protos.size), factory)
|
||||
|
||||
computeNonDeclared(descriptors)
|
||||
return descriptors.compact()
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be overridden to filter specific declared functions. Not called on non-declared functions.
|
||||
*/
|
||||
protected open fun isDeclaredFunctionAvailable(function: SimpleFunctionDescriptor): Boolean = true
|
||||
|
||||
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user