KT-15153 Support typeAlias extensions in completion and add import

#KT-15153 fixed
This commit is contained in:
Simon Ogorodnik
2017-01-19 18:49:22 +03:00
parent 9bc45a9c91
commit 3948c1e007
30 changed files with 432 additions and 13 deletions
@@ -49,7 +49,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.isHiddenInResolution
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
import java.lang.reflect.Field
import java.lang.reflect.Modifier
@@ -175,9 +174,31 @@ class KotlinIndicesHelper(
suitableExtensions
}
private fun resolveTypeAliasesUsingIndex(type: KotlinType, originalTypeName: String, out: MutableCollection<String>) {
val index = KotlinTypeAliasByExpansionShortNameIndex.INSTANCE
fun searchRecursively(typeName: String) {
ProgressManager.checkCanceled()
index[typeName, project, scope].asSequence()
.map { it.resolveToDescriptorIfAny() as? TypeAliasDescriptor }
.filterNotNull()
.filter { it.expandedType == type }
.map { it.name.asString() }
.filter { it !in out }
.onEach(::searchRecursively)
.toCollection(out)
}
searchRecursively(originalTypeName)
}
private fun MutableCollection<String>.addTypeNames(type: KotlinType) {
val constructor = type.constructor
addIfNotNull(constructor.declarationDescriptor?.name?.asString())
constructor.declarationDescriptor?.name?.asString()?.let { typeName ->
add(typeName)
resolveTypeAliasesUsingIndex(type, typeName, this)
}
constructor.supertypes.forEach { addTypeNames(it) }
}