KT-17689: Fix TypeAliasQualifier to provide enum entries descriptors
- this adds enum entries to the completion on the typealiases - we cannot use `unsubstitutedInnerClassesScope` instead of `EnumEntriesScope` because it allows to complete things that are not allowed to be resolved by the Kotlin compiler; see `EnumEntriesScope` doc for details - ^KT-17689 Fixed
This commit is contained in:
committed by
Roman Golyshev
parent
f419d2eb30
commit
9a938b07ba
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getTopmostParentQualifiedExpressionForSe
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classValueType
|
||||
import org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -107,7 +108,23 @@ class TypeAliasQualifier(
|
||||
classDescriptor.staticScope
|
||||
}
|
||||
|
||||
/**
|
||||
* We cannot use [org.jetbrains.kotlin.descriptors.ClassDescriptor.getUnsubstitutedMemberScope] directly,
|
||||
* because we do not allow complete resolve through type aliases yet (see KT-15298).
|
||||
*
|
||||
* However, we want to allow to resolve and autocomplete enum constants even through type aliases;
|
||||
* that's why we use [org.jetbrains.kotlin.descriptors.ClassDescriptor.getUnsubstitutedMemberScope],
|
||||
* but filter only enum entries.
|
||||
*/
|
||||
private inner class EnumEntriesScope : MemberScopeImpl() {
|
||||
override fun getContributedDescriptors(
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> =
|
||||
classDescriptor.unsubstitutedInnerClassesScope
|
||||
.getContributedDescriptors(kindFilter, nameFilter)
|
||||
.filter { DescriptorUtils.isEnumEntry(it) }
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? =
|
||||
classDescriptor.unsubstitutedInnerClassesScope
|
||||
.getContributedClassifier(name, location)
|
||||
|
||||
Reference in New Issue
Block a user