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:
Alexander Udalov
2017-04-12 15:11:47 +03:00
parent 9f037c3c62
commit bbdff8c7ce
24 changed files with 53 additions and 83 deletions
@@ -91,7 +91,7 @@ class OverloadResolver(
collectModulePackageMembersWithSameName(
packageMembersByName,
c.functions.values + c.declaredClasses.values + c.typeAliases.values,
(c.functions.values as Collection<DeclarationDescriptor>) + c.declaredClasses.values + c.typeAliases.values,
overloadFilter
) {
scope, name ->
@@ -31,7 +31,7 @@ object UnderscoreUsageChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
if (resolvedCall is VariableAsFunctionResolvedCall) return
val descriptor = resolvedCall.resultingDescriptor
val namedDescriptor = if (descriptor is ConstructorDescriptor) descriptor.containingDeclaration else descriptor
val namedDescriptor: DeclarationDescriptor = (descriptor as? ConstructorDescriptor)?.containingDeclaration ?: descriptor
if (!namedDescriptor.name.asString().isUnderscoreOnlyName()) return
checkCallElement(resolvedCall.call.callElement, context)
}
@@ -38,7 +38,6 @@ import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
import org.jetbrains.kotlin.script.getScriptExternalDependencies
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.utils.Printer
data class FileScopes(val lexicalScope: LexicalScope, val importingScope: ImportingScope, val importResolver: ImportResolver)
@@ -236,7 +235,6 @@ class FileScopeFactory(
override fun getOriginal() = this
override val annotations: Annotations get() = Annotations.EMPTY
override fun substitute(substitutor: TypeSubstitutor) = this
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R {
throw UnsupportedOperationException()
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.resolve.lazy.LazyEntity
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.TypeSubstitutor
abstract class LazyAnnotationsContext(
val annotationResolver: AnnotationResolver,
@@ -172,7 +171,6 @@ class LazyAnnotationDescriptor(
override fun getName() = Name.special("< file descriptor for annotation resolution >")
private fun error(): Nothing = error("This method should not be called")
override fun substitute(substitutor: TypeSubstitutor): DeclarationDescriptor? = error()
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R = error()
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) = error()