Add missing definitelyDoesNotContainName methods

This commit is contained in:
Ilya Muradyan
2020-06-17 15:33:48 +03:00
committed by Ilya Chernikov
parent 573c60ed6b
commit 8c2baf0704
8 changed files with 97 additions and 2 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProv
import org.jetbrains.kotlin.resolve.lazy.declarations.PackageMemberDeclarationProvider
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
import org.jetbrains.kotlin.utils.addToStdlib.flatMapToNullable
import java.util.*
//----------------------------------------------------------------
@@ -43,6 +44,13 @@ interface SyntheticResolveExtension {
override fun getSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name> =
instances.flatMap { withLinkageErrorLogger(it) { getSyntheticNestedClassNames(thisDescriptor) } }
override fun getPossibleSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name>? =
instances.flatMapToNullable(ArrayList<Name>()) {
withLinkageErrorLogger(it) {
getPossibleSyntheticNestedClassNames(thisDescriptor)
}
}
override fun getSyntheticFunctionNames(thisDescriptor: ClassDescriptor): List<Name> =
instances.flatMap { withLinkageErrorLogger(it) { getSyntheticFunctionNames(thisDescriptor) } }
@@ -136,6 +144,13 @@ interface SyntheticResolveExtension {
fun getSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name> = emptyList()
/**
* This method should return either superset of what [getSyntheticNestedClassNames] returns,
* or null in case it needs to run resolution and inference and/or it is very costly.
* Override this method if resolution started to fail with recursion.
*/
fun getPossibleSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name>? = getSyntheticNestedClassNames(thisDescriptor)
fun addSyntheticSupertypes(thisDescriptor: ClassDescriptor, supertypes: MutableList<KotlinType>) {}
fun generateSyntheticClasses(
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.refinement.TypeRefinement
import org.jetbrains.kotlin.utils.addToStdlib.flatMapToNullable
import java.util.*
open class LazyClassMemberScope(
@@ -102,7 +103,7 @@ open class LazyClassMemberScope(
}
private val _variableNames: MutableSet<Name>
by lazy(LazyThreadSafetyMode.PUBLICATION) {
by storageManager.createLazyValue {
mutableSetOf<Name>().apply {
addAll(declarationProvider.getDeclarationNames())
supertypes.flatMapTo(this) {
@@ -112,9 +113,10 @@ open class LazyClassMemberScope(
}
private val _functionNames: MutableSet<Name>
by lazy(LazyThreadSafetyMode.PUBLICATION) {
by storageManager.createLazyValue {
mutableSetOf<Name>().apply {
addAll(declarationProvider.getDeclarationNames())
addAll(c.syntheticResolveExtension.getSyntheticFunctionNames(thisDescriptor))
supertypes.flatMapTo(this) {
it.memberScope.getFunctionNames()
}
@@ -123,6 +125,32 @@ open class LazyClassMemberScope(
}
}
private val _classifierNames: Set<Name>?
by storageManager.createNullableLazyValue {
mutableSetOf<Name>().apply {
supertypes.flatMapToNullable(this) {
it.memberScope.getClassifierNames()
} ?: return@createNullableLazyValue null
addAll(declarationProvider.getDeclarationNames())
with(c.syntheticResolveExtension) {
getPossibleSyntheticNestedClassNames(thisDescriptor)?.let { addAll(it) } ?: return@createNullableLazyValue null
getSyntheticCompanionObjectNameIfNeeded(thisDescriptor)?.let { add(it) }
}
}
}
private val _allNames: Set<Name>?
by storageManager.createNullableLazyValue {
val classifiers = getClassifierNames() ?: return@createNullableLazyValue null
mutableSetOf<Name>().apply {
addAll(getVariableNames())
addAll(getFunctionNames())
addAll(classifiers)
}
}
private fun getDataClassRelatedFunctionNames(): Collection<Name> {
val declarations = mutableListOf<DeclarationDescriptor>()
addDataClassMethods(declarations, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS)
@@ -131,6 +159,11 @@ open class LazyClassMemberScope(
override fun getVariableNames() = _variableNames
override fun getFunctionNames() = _functionNames
override fun getClassifierNames() = _classifierNames
override fun definitelyDoesNotContainName(name: Name): Boolean {
return _allNames?.let { name !in it } ?: false
}
private interface MemberExtractor<out T : CallableMemberDescriptor> {
fun extract(extractFrom: KotlinType, name: Name): Collection<T>