Record special descriptor in REFERENCE_TARGET for type alias object

If a type alias is used to reference an object (companion object) as a
qualifier, record FakeCallableDescriptorForTypeAliasObject in
REFERENCE_TARGET. This tells IDE that type alias was used in the file,
thus, if it's imported, such import isn't redundant.
REFERENCE_TARGET is used mostly by IDE and by ClassifierUsageChecker,
which we also have to update to handle qualifiers with
FakeCallableDescriptorForTypeAliasObject in REFERENCE_TARGET.

Rewrite some parts of ClassifierUsageChecker for cleaner interaction.

 #KT-21863 Fixed Target versions 1.2.40
This commit is contained in:
Dmitry Petrov
2018-03-13 15:17:30 +03:00
parent 3b3cc5233f
commit f956e8d85d
13 changed files with 156 additions and 42 deletions
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind.*
import org.jetbrains.kotlin.descriptors.annotations.Annotated
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.descriptors.impl.DescriptorDerivedFromTypeAlias
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
@@ -50,7 +50,7 @@ fun ClassDescriptor.getClassObjectReferenceTarget(): ClassDescriptor = companion
fun DeclarationDescriptor.getImportableDescriptor(): DeclarationDescriptor =
when (this) {
is TypeAliasConstructorDescriptor -> containingDeclaration
is DescriptorDerivedFromTypeAlias -> typeAliasDescriptor
is ConstructorDescriptor -> containingDeclaration
is PropertyAccessorDescriptor -> correspondingProperty
else -> this
@@ -97,13 +97,12 @@ val ClassifierDescriptorWithTypeParameters.hasCompanionObject: Boolean
val ClassDescriptor.hasClassValueDescriptor: Boolean get() = classValueDescriptor != null
val ClassifierDescriptorWithTypeParameters.classValueDescriptor: ClassDescriptor?
get() = denotedClassDescriptor?.let {
if (it.kind.isSingleton)
it
val ClassDescriptor.classValueDescriptor: ClassDescriptor?
get() =
if (kind.isSingleton)
this
else
it.companionObjectDescriptor
}
companionObjectDescriptor
val ClassifierDescriptorWithTypeParameters.classValueTypeDescriptor: ClassDescriptor?
get() = denotedClassDescriptor?.let {