Move DeclarationDescriptor.substitute to separate interface Substitutable
To get rid of pointless/confusing implementations in ModuleDescriptor, PackageViewDescriptor, TypeParameterDescriptor and others. Note that there are still implementations that do not make sense, for example in those subclasses of VariableDescriptor which are not also subclasses of CallableMemberDescriptor (e.g. ValueParameterDescriptor). Those can be removed by making CallableMemberDescriptor (instead of CallableDescriptor) inherit from Substitutable. However, that would require more changes in the compiler because CallableDescriptor is used rather often in places where in fact only CallableMemberDescriptor instances can appear. Explicit return types and casts are required in some places now because there's no single non-trivial supertype for ClassifierDescriptorWithTypeParameters and CallableDescriptor. Previously it was DeclarationDescriptorWithVisibility, now it's both that and Substitutable<...>
This commit is contained in:
+6
-5
@@ -104,11 +104,12 @@ private fun findCandidateDeclarationsInIndex(
|
||||
return KotlinFullClassNameIndex.getInstance().get(containingClass.fqNameSafe.asString(), project, scope)
|
||||
}
|
||||
|
||||
val topLevelDeclaration = DescriptorUtils.getParentOfType(referencedDescriptor, PropertyDescriptor::class.java, false)
|
||||
?: DescriptorUtils.getParentOfType(referencedDescriptor, TypeAliasConstructorDescriptor::class.java, false)?.typeAliasDescriptor
|
||||
?: DescriptorUtils.getParentOfType(referencedDescriptor, FunctionDescriptor::class.java, false)
|
||||
?: DescriptorUtils.getParentOfType(referencedDescriptor, TypeAliasDescriptor::class.java, false)
|
||||
?: return emptyList()
|
||||
val topLevelDeclaration =
|
||||
DescriptorUtils.getParentOfType(referencedDescriptor, PropertyDescriptor::class.java, false) as DeclarationDescriptor?
|
||||
?: DescriptorUtils.getParentOfType(referencedDescriptor, TypeAliasConstructorDescriptor::class.java, false)?.typeAliasDescriptor
|
||||
?: DescriptorUtils.getParentOfType(referencedDescriptor, FunctionDescriptor::class.java, false)
|
||||
?: DescriptorUtils.getParentOfType(referencedDescriptor, TypeAliasDescriptor::class.java, false)
|
||||
?: return emptyList()
|
||||
|
||||
// filter out synthetic descriptors
|
||||
if (!DescriptorUtils.isTopLevelDeclaration(topLevelDeclaration)) return emptyList()
|
||||
|
||||
@@ -208,11 +208,12 @@ fun<TDescriptor: DeclarationDescriptor?> MutableCollection<LookupElement>.addLoo
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun <T : DeclarationDescriptor?> T.substituteFixed(substitutor: TypeSubstitutor): T {
|
||||
if (this is LocalVariableDescriptor || this is ValueParameterDescriptor || this is TypeParameterDescriptor) { // TODO: it's not implemented for them
|
||||
if (this is LocalVariableDescriptor || this is ValueParameterDescriptor || this !is Substitutable<*>) {
|
||||
return this
|
||||
}
|
||||
return this?.substitute(substitutor) as T
|
||||
return this.substitute(substitutor) as T
|
||||
}
|
||||
|
||||
private fun MutableCollection<LookupElement>.addLookupElementsForNullable(factory: () -> Collection<LookupElement>, matchedInfos: Collection<ExpectedInfo>) {
|
||||
|
||||
@@ -47,7 +47,7 @@ private enum class SourceKind { NONE, PRODUCTION, TEST }
|
||||
|
||||
fun ModuleDescriptor.hasDeclarationOf(descriptor: MemberDescriptor) = declarationOf(descriptor) != null
|
||||
|
||||
private fun ModuleDescriptor.declarationOf(descriptor: MemberDescriptor) =
|
||||
private fun ModuleDescriptor.declarationOf(descriptor: MemberDescriptor): DeclarationDescriptor? =
|
||||
with (HeaderImplDeclarationChecker(this)) {
|
||||
when (descriptor) {
|
||||
is CallableMemberDescriptor ->
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.awt.event.MouseEvent
|
||||
fun ModuleDescriptor.hasImplementationsOf(descriptor: MemberDescriptor) =
|
||||
implementationsOf(descriptor).isNotEmpty()
|
||||
|
||||
private fun ModuleDescriptor.implementationsOf(descriptor: MemberDescriptor) =
|
||||
private fun ModuleDescriptor.implementationsOf(descriptor: MemberDescriptor): List<DeclarationDescriptor> =
|
||||
with (HeaderImplDeclarationChecker(this)) {
|
||||
when (descriptor) {
|
||||
is CallableMemberDescriptor -> descriptor.findNamesakesFromTheSameModule().filter { it.isImpl }
|
||||
|
||||
Reference in New Issue
Block a user