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)
|
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>) {
|
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
||||||
val fromSupertypes = ArrayList<SimpleFunctionDescriptor>()
|
val fromSupertypes = ArrayList<SimpleFunctionDescriptor>()
|
||||||
for (supertype in refinedSupertypes()) {
|
for (supertype in refinedSupertypes()) {
|
||||||
fromSupertypes.addAll(supertype.memberScope.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED))
|
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))
|
functions.addAll(c.components.additionalClassPartsProvider.getFunctions(name, this@DeserializedClassDescriptor))
|
||||||
generateFakeOverrides(name, fromSupertypes, functions)
|
generateFakeOverrides(name, fromSupertypes, functions)
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-5
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
import org.jetbrains.kotlin.utils.compact
|
import org.jetbrains.kotlin.utils.compact
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.util.*
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
abstract class DeserializedMemberScope protected constructor(
|
abstract class DeserializedMemberScope protected constructor(
|
||||||
protected val c: DeserializationContext,
|
protected val c: DeserializationContext,
|
||||||
@@ -104,7 +104,7 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
name,
|
name,
|
||||||
functionProtosBytes,
|
functionProtosBytes,
|
||||||
ProtoBuf.Function.PARSER,
|
ProtoBuf.Function.PARSER,
|
||||||
{ c.memberDeserializer.loadFunction(it) },
|
{ c.memberDeserializer.loadFunction(it).takeIf(::isDeclaredFunctionAvailable) },
|
||||||
{ computeNonDeclaredFunctions(name, it) }
|
{ computeNonDeclaredFunctions(name, it) }
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
name: Name,
|
name: Name,
|
||||||
bytesByName: Map<Name, ByteArray>,
|
bytesByName: Map<Name, ByteArray>,
|
||||||
parser: Parser<M>,
|
parser: Parser<M>,
|
||||||
factory: (M) -> D,
|
factory: (M) -> D?,
|
||||||
computeNonDeclared: (MutableCollection<D>) -> Unit
|
computeNonDeclared: (MutableCollection<D>) -> Unit
|
||||||
): Collection<D> =
|
): Collection<D> =
|
||||||
computeDescriptors(
|
computeDescriptors(
|
||||||
@@ -128,15 +128,20 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
|
|
||||||
private inline fun <M : MessageLite, D : DeclarationDescriptor> computeDescriptors(
|
private inline fun <M : MessageLite, D : DeclarationDescriptor> computeDescriptors(
|
||||||
protos: Collection<M>,
|
protos: Collection<M>,
|
||||||
factory: (M) -> D,
|
factory: (M) -> D?,
|
||||||
computeNonDeclared: (MutableCollection<D>) -> Unit
|
computeNonDeclared: (MutableCollection<D>) -> Unit
|
||||||
): Collection<D> {
|
): Collection<D> {
|
||||||
val descriptors = protos.mapTo(arrayListOf(), factory)
|
val descriptors = protos.mapNotNullTo(ArrayList(protos.size), factory)
|
||||||
|
|
||||||
computeNonDeclared(descriptors)
|
computeNonDeclared(descriptors)
|
||||||
return descriptors.compact()
|
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>) {
|
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user