Minor: reformat AbstractTypeConstructor.kt
This commit is contained in:
@@ -25,48 +25,46 @@ abstract class AbstractTypeConstructor(storageManager: StorageManager) : TypeCon
|
|||||||
// In current version diagnostic about loops in supertypes is reported on each vertex (supertype reference) that lies on the cycle.
|
// In current version diagnostic about loops in supertypes is reported on each vertex (supertype reference) that lies on the cycle.
|
||||||
// To achieve that we store both versions of supertypes --- before and after loops disconnection.
|
// To achieve that we store both versions of supertypes --- before and after loops disconnection.
|
||||||
// The first one is used for computation of neighbours in supertypes graph (see Companion.computeNeighbours)
|
// The first one is used for computation of neighbours in supertypes graph (see Companion.computeNeighbours)
|
||||||
private class Supertypes(
|
private class Supertypes(val allSupertypes: Collection<KotlinType>) {
|
||||||
val allSupertypes: Collection<KotlinType>) {
|
// initializer is only needed as a stub for case when 'getSupertypes' is called while 'supertypes' are being calculated
|
||||||
// initializer is only needed as a stub for case when 'getSupertypes' is called while 'supertypes' are being calculated
|
var supertypesWithoutCycles: List<KotlinType> = listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES)
|
||||||
var supertypesWithoutCycles: List<KotlinType> = listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val supertypes = storageManager.createLazyValueWithPostCompute(
|
private val supertypes = storageManager.createLazyValueWithPostCompute(
|
||||||
{ Supertypes(computeSupertypes()) },
|
{ Supertypes(computeSupertypes()) },
|
||||||
{ Supertypes(listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES)) },
|
{ Supertypes(listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES)) },
|
||||||
{ supertypes ->
|
{ supertypes ->
|
||||||
// It's important that loops disconnection begins in post-compute phase, because it guarantees that
|
// It's important that loops disconnection begins in post-compute phase, because it guarantees that
|
||||||
// when we start calculation supertypes of supertypes (for computing neighbours), they start their disconnection loop process
|
// when we start calculation supertypes of supertypes (for computing neighbours), they start their disconnection loop process
|
||||||
// either, and as we want to report diagnostic about loops on all declarations they should see consistent version of 'allSupertypes'
|
// either, and as we want to report diagnostic about loops on all declarations they should see consistent version of 'allSupertypes'
|
||||||
var resultWithoutCycles =
|
var resultWithoutCycles =
|
||||||
supertypeLoopChecker.findLoopsInSupertypesAndDisconnect(
|
|
||||||
this, supertypes.allSupertypes,
|
|
||||||
{ it.computeNeighbours(useCompanions = false) },
|
|
||||||
{ reportSupertypeLoopError(it) }
|
|
||||||
)
|
|
||||||
|
|
||||||
if (resultWithoutCycles.isEmpty()) {
|
|
||||||
resultWithoutCycles = defaultSupertypeIfEmpty()?.let { listOf(it) }.orEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
// We also check if there are a loop with additional edges going from owner of companion to
|
|
||||||
// the companion itself.
|
|
||||||
// Note that we use already disconnected types to not report two diagnostics on cyclic supertypes
|
|
||||||
supertypeLoopChecker.findLoopsInSupertypesAndDisconnect(
|
supertypeLoopChecker.findLoopsInSupertypesAndDisconnect(
|
||||||
this, resultWithoutCycles,
|
this, supertypes.allSupertypes,
|
||||||
{ it.computeNeighbours(useCompanions = true) },
|
{ it.computeNeighbours(useCompanions = false) },
|
||||||
{ reportScopesLoopError(it) }
|
{ reportSupertypeLoopError(it) }
|
||||||
)
|
)
|
||||||
|
|
||||||
supertypes.supertypesWithoutCycles = (resultWithoutCycles as? List<KotlinType>) ?: resultWithoutCycles.toList()
|
if (resultWithoutCycles.isEmpty()) {
|
||||||
})
|
resultWithoutCycles = defaultSupertypeIfEmpty()?.let { listOf(it) }.orEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
// We also check if there are a loop with additional edges going from owner of companion to
|
||||||
|
// the companion itself.
|
||||||
|
// Note that we use already disconnected types to not report two diagnostics on cyclic supertypes
|
||||||
|
supertypeLoopChecker.findLoopsInSupertypesAndDisconnect(
|
||||||
|
this, resultWithoutCycles,
|
||||||
|
{ it.computeNeighbours(useCompanions = true) },
|
||||||
|
{ reportScopesLoopError(it) }
|
||||||
|
)
|
||||||
|
|
||||||
|
supertypes.supertypesWithoutCycles = (resultWithoutCycles as? List<KotlinType>) ?: resultWithoutCycles.toList()
|
||||||
|
})
|
||||||
|
|
||||||
private fun TypeConstructor.computeNeighbours(useCompanions: Boolean): Collection<KotlinType> =
|
private fun TypeConstructor.computeNeighbours(useCompanions: Boolean): Collection<KotlinType> =
|
||||||
(this as? AbstractTypeConstructor)?.let {
|
(this as? AbstractTypeConstructor)?.let { abstractClassifierDescriptor ->
|
||||||
abstractClassifierDescriptor ->
|
abstractClassifierDescriptor.supertypes().allSupertypes +
|
||||||
abstractClassifierDescriptor.supertypes().allSupertypes +
|
abstractClassifierDescriptor.getAdditionalNeighboursInSupertypeGraph(useCompanions)
|
||||||
abstractClassifierDescriptor.getAdditionalNeighboursInSupertypeGraph(useCompanions)
|
} ?: supertypes
|
||||||
} ?: supertypes
|
|
||||||
|
|
||||||
protected abstract fun computeSupertypes(): Collection<KotlinType>
|
protected abstract fun computeSupertypes(): Collection<KotlinType>
|
||||||
protected abstract val supertypeLoopChecker: SupertypeLoopChecker
|
protected abstract val supertypeLoopChecker: SupertypeLoopChecker
|
||||||
|
|||||||
Reference in New Issue
Block a user