KT-41346 Refactor computeNonDeclared*
Change the signature of the `computeNonDeclared*` methods so they expect mutable lists - it better suits their contracts. Also, add a little documentations about the contract Also, change `Collection` to `List` for incoming protos to `emphasize` that their order might be used
This commit is contained in:
+3
-3
@@ -250,7 +250,7 @@ class DeserializedClassDescriptor(
|
|||||||
return c.components.platformDependentDeclarationFilter.isFunctionAvailable(this@DeserializedClassDescriptor, function)
|
return c.components.platformDependentDeclarationFilter.isFunctionAvailable(this@DeserializedClassDescriptor, function)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
override fun computeNonDeclaredFunctions(name: Name, functions: MutableList<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))
|
||||||
@@ -260,7 +260,7 @@ class DeserializedClassDescriptor(
|
|||||||
generateFakeOverrides(name, fromSupertypes, functions)
|
generateFakeOverrides(name, fromSupertypes, functions)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun computeNonDeclaredProperties(name: Name, descriptors: MutableCollection<PropertyDescriptor>) {
|
override fun computeNonDeclaredProperties(name: Name, descriptors: MutableList<PropertyDescriptor>) {
|
||||||
val fromSupertypes = ArrayList<PropertyDescriptor>()
|
val fromSupertypes = ArrayList<PropertyDescriptor>()
|
||||||
for (supertype in refinedSupertypes()) {
|
for (supertype in refinedSupertypes()) {
|
||||||
fromSupertypes.addAll(supertype.memberScope.getContributedVariables(name, NoLookupLocation.FOR_ALREADY_TRACKED))
|
fromSupertypes.addAll(supertype.memberScope.getContributedVariables(name, NoLookupLocation.FOR_ALREADY_TRACKED))
|
||||||
@@ -271,7 +271,7 @@ class DeserializedClassDescriptor(
|
|||||||
private fun <D : CallableMemberDescriptor> generateFakeOverrides(
|
private fun <D : CallableMemberDescriptor> generateFakeOverrides(
|
||||||
name: Name,
|
name: Name,
|
||||||
fromSupertypes: Collection<D>,
|
fromSupertypes: Collection<D>,
|
||||||
result: MutableCollection<D>
|
result: MutableList<D>
|
||||||
) {
|
) {
|
||||||
val fromCurrent = ArrayList<CallableMemberDescriptor>(result)
|
val fromCurrent = ArrayList<CallableMemberDescriptor>(result)
|
||||||
c.components.kotlinTypeChecker.overridingUtil.generateOverridesInFunctionGroup(
|
c.components.kotlinTypeChecker.overridingUtil.generateOverridesInFunctionGroup(
|
||||||
|
|||||||
+22
-10
@@ -39,9 +39,9 @@ import kotlin.collections.ArrayList
|
|||||||
|
|
||||||
abstract class DeserializedMemberScope protected constructor(
|
abstract class DeserializedMemberScope protected constructor(
|
||||||
protected val c: DeserializationContext,
|
protected val c: DeserializationContext,
|
||||||
functionList: Collection<ProtoBuf.Function>,
|
functionList: List<ProtoBuf.Function>,
|
||||||
propertyList: Collection<ProtoBuf.Property>,
|
propertyList: List<ProtoBuf.Property>,
|
||||||
typeAliasList: Collection<ProtoBuf.TypeAlias>,
|
typeAliasList: List<ProtoBuf.TypeAlias>,
|
||||||
classNames: () -> Collection<Name>
|
classNames: () -> Collection<Name>
|
||||||
) : MemberScopeImpl() {
|
) : MemberScopeImpl() {
|
||||||
|
|
||||||
@@ -68,14 +68,26 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
*/
|
*/
|
||||||
protected open fun isDeclaredFunctionAvailable(function: SimpleFunctionDescriptor): Boolean = true
|
protected open fun isDeclaredFunctionAvailable(function: SimpleFunctionDescriptor): Boolean = true
|
||||||
|
|
||||||
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
|
/**
|
||||||
|
* This function has the next contract:
|
||||||
|
*
|
||||||
|
* * It can only add to the end of the [functions] list and shall not modify it otherwise (e.g. remove from it).
|
||||||
|
* * Before the call, [functions] should already contain all declared functions with the [name] name.
|
||||||
|
*/
|
||||||
|
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableList<SimpleFunctionDescriptor>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
|
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
|
||||||
return impl.getContributedFunctions(name, location)
|
return impl.getContributedFunctions(name, location)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun computeNonDeclaredProperties(name: Name, descriptors: MutableCollection<PropertyDescriptor>) {
|
/**
|
||||||
|
* This function has the next contract:
|
||||||
|
*
|
||||||
|
* * It can only add to the end of the [descriptors] list and shall not modify it otherwise (e.g. remove from it).
|
||||||
|
* * Before the call, [descriptors] should already contain all declared properties with the [name] name.
|
||||||
|
*/
|
||||||
|
protected open fun computeNonDeclaredProperties(name: Name, descriptors: MutableList<PropertyDescriptor>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTypeAliasByName(name: Name): TypeAliasDescriptor? {
|
private fun getTypeAliasByName(name: Name): TypeAliasDescriptor? {
|
||||||
@@ -169,9 +181,9 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inner class OptimizedImplementation(
|
private inner class OptimizedImplementation(
|
||||||
functionList: Collection<ProtoBuf.Function>,
|
functionList: List<ProtoBuf.Function>,
|
||||||
propertyList: Collection<ProtoBuf.Property>,
|
propertyList: List<ProtoBuf.Property>,
|
||||||
typeAliasList: Collection<ProtoBuf.TypeAlias>
|
typeAliasList: List<ProtoBuf.TypeAlias>
|
||||||
) : Implementation {
|
) : Implementation {
|
||||||
private val functionProtosBytes = functionList.groupByName { it.name }.packToByteArray()
|
private val functionProtosBytes = functionList.groupByName { it.name }.packToByteArray()
|
||||||
|
|
||||||
@@ -225,7 +237,7 @@ abstract class DeserializedMemberScope protected constructor(
|
|||||||
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: (MutableList<D>) -> Unit
|
||||||
): Collection<D> =
|
): Collection<D> =
|
||||||
computeDescriptors(
|
computeDescriptors(
|
||||||
bytesByName[name]?.let {
|
bytesByName[name]?.let {
|
||||||
@@ -241,7 +253,7 @@ 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: (MutableList<D>) -> Unit
|
||||||
): Collection<D> {
|
): Collection<D> {
|
||||||
val descriptors = protos.mapNotNullTo(ArrayList(protos.size), factory)
|
val descriptors = protos.mapNotNullTo(ArrayList(protos.size), factory)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user