Revert "KT-14252 Completion could suggest constructors available via typealiases"
Reverted due problems with tests
This reverts commit 55eeb74c08.
This commit is contained in:
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.util
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.getTypeAliasConstructors
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
@@ -77,18 +76,4 @@ fun TypeConstructor.supertypesWithAny(): Collection<KotlinType> {
|
||||
.map { it.constructor.declarationDescriptor as? ClassDescriptor }
|
||||
.all { it == null || it.kind == ClassKind.INTERFACE }
|
||||
return if (noSuperClass) supertypes + builtIns.anyType else supertypes
|
||||
}
|
||||
|
||||
val ClassifierDescriptorWithTypeParameters.constructors: Collection<ConstructorDescriptor>
|
||||
get() = when (this) {
|
||||
is TypeAliasDescriptor -> getTypeAliasConstructors()
|
||||
is ClassDescriptor -> this.constructors
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
val ClassifierDescriptorWithTypeParameters.kind: ClassKind?
|
||||
get() = when (this) {
|
||||
is TypeAliasDescriptor -> classDescriptor?.kind
|
||||
is ClassDescriptor -> kind
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -210,7 +210,7 @@ class SmartCompletion(
|
||||
}
|
||||
|
||||
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
|
||||
TypeInstantiationItems(resolutionFacade, bindingContext, visibilityFilter, toFromOriginalFileMapper, inheritorSearchScope, lookupElementFactory, forBasicCompletion, indicesHelper)
|
||||
TypeInstantiationItems(resolutionFacade, bindingContext, visibilityFilter, toFromOriginalFileMapper, inheritorSearchScope, lookupElementFactory, forBasicCompletion)
|
||||
.addTo(items, inheritanceSearchers, expectedInfos)
|
||||
|
||||
if (expression is KtSimpleNameExpression) {
|
||||
|
||||
+17
-29
@@ -33,7 +33,9 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.completion.*
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
|
||||
import org.jetbrains.kotlin.idea.core.*
|
||||
import org.jetbrains.kotlin.idea.core.ExpectedInfo
|
||||
import org.jetbrains.kotlin.idea.core.Tail
|
||||
import org.jetbrains.kotlin.idea.core.multipleFuzzyTypes
|
||||
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMembersHandler
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.*
|
||||
@@ -42,12 +44,11 @@ import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.util.constructors
|
||||
import org.jetbrains.kotlin.util.kind
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
|
||||
@@ -58,8 +59,7 @@ class TypeInstantiationItems(
|
||||
val toFromOriginalFileMapper: ToFromOriginalFileMapper,
|
||||
val inheritorSearchScope: GlobalSearchScope,
|
||||
val lookupElementFactory: LookupElementFactory,
|
||||
val forOrdinaryCompletion: Boolean,
|
||||
val indicesHelper: KotlinIndicesHelper
|
||||
val forOrdinaryCompletion: Boolean
|
||||
) {
|
||||
fun addTo(
|
||||
items: MutableCollection<LookupElement>,
|
||||
@@ -87,31 +87,22 @@ class TypeInstantiationItems(
|
||||
) {
|
||||
if (fuzzyType.type.isFunctionType) return // do not show "object: ..." for function types
|
||||
|
||||
val classifier = fuzzyType.type.constructor.declarationDescriptor as? ClassifierDescriptorWithTypeParameters ?: return
|
||||
val classDescriptor = when (classifier) {
|
||||
is ClassDescriptor -> classifier
|
||||
is TypeAliasDescriptor -> classifier.classDescriptor
|
||||
else -> null
|
||||
}
|
||||
val classifier = fuzzyType.type.constructor.declarationDescriptor
|
||||
if (classifier !is ClassDescriptor) return
|
||||
|
||||
addSamConstructorItem(items, classifier, tail)
|
||||
|
||||
addSamConstructorItem(items, classifier, classDescriptor, tail)
|
||||
items.addIfNotNull(createTypeInstantiationItem(fuzzyType, tail))
|
||||
|
||||
indicesHelper.resolveTypeAliasesUsingIndex(fuzzyType.type, classifier.name.asString()).forEach {
|
||||
addSamConstructorItem(items, it, classDescriptor, tail)
|
||||
val typeAliasFuzzyType = it.defaultType.toFuzzyType(fuzzyType.freeParameters)
|
||||
items.addIfNotNull(createTypeInstantiationItem(typeAliasFuzzyType, tail))
|
||||
}
|
||||
|
||||
if (classDescriptor != null && !forOrdinaryCompletion && !KotlinBuiltIns.isAny(classDescriptor)) { // do not search inheritors of Any
|
||||
if (!forOrdinaryCompletion && !KotlinBuiltIns.isAny(classifier)) { // do not search inheritors of Any
|
||||
val typeArgs = fuzzyType.type.arguments
|
||||
inheritanceSearchers.addInheritorSearcher(classDescriptor, classDescriptor, typeArgs, fuzzyType.freeParameters, tail)
|
||||
inheritanceSearchers.addInheritorSearcher(classifier, classifier, typeArgs, fuzzyType.freeParameters, tail)
|
||||
|
||||
val javaClassId = JavaToKotlinClassMap.INSTANCE.mapKotlinToJava(DescriptorUtils.getFqName(classifier))
|
||||
if (javaClassId != null) {
|
||||
val javaAnalog = resolutionFacade.moduleDescriptor.resolveTopLevelClass(javaClassId.asSingleFqName(), NoLookupLocation.FROM_IDE)
|
||||
if (javaAnalog != null) {
|
||||
inheritanceSearchers.addInheritorSearcher(javaAnalog, classDescriptor, typeArgs, fuzzyType.freeParameters, tail)
|
||||
inheritanceSearchers.addInheritorSearcher(javaAnalog, classifier, typeArgs, fuzzyType.freeParameters, tail)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,7 +126,7 @@ class TypeInstantiationItems(
|
||||
}
|
||||
|
||||
private fun createTypeInstantiationItem(fuzzyType: FuzzyType, tail: Tail?): LookupElement? {
|
||||
val classifier = fuzzyType.type.constructor.declarationDescriptor as? ClassifierDescriptorWithTypeParameters ?: return null
|
||||
val classifier = fuzzyType.type.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
||||
|
||||
var lookupElement = lookupElementFactory.createLookupElement(classifier, useReceiverTypes = false)
|
||||
|
||||
@@ -295,18 +286,15 @@ class TypeInstantiationItems(
|
||||
return FuzzyType(this, freeParameters).freeParameters.isNotEmpty()
|
||||
}
|
||||
|
||||
private fun addSamConstructorItem(collection: MutableCollection<LookupElement>,
|
||||
classifier: ClassifierDescriptorWithTypeParameters,
|
||||
classDescriptor: ClassDescriptor?,
|
||||
tail: Tail?) {
|
||||
if (classDescriptor?.kind == ClassKind.INTERFACE) {
|
||||
val container = classifier.containingDeclaration
|
||||
private fun addSamConstructorItem(collection: MutableCollection<LookupElement>, `class`: ClassDescriptor, tail: Tail?) {
|
||||
if (`class`.kind == ClassKind.INTERFACE) {
|
||||
val container = `class`.containingDeclaration
|
||||
val scope = when (container) {
|
||||
is PackageFragmentDescriptor -> container.getMemberScope()
|
||||
is ClassDescriptor -> container.staticScope
|
||||
else -> return
|
||||
}
|
||||
val samConstructor = scope.getContributedFunctions(classifier.name, NoLookupLocation.FROM_IDE)
|
||||
val samConstructor = scope.getContributedFunctions(`class`.name, NoLookupLocation.FROM_IDE)
|
||||
.filterIsInstance<SamConstructorDescriptor>()
|
||||
.singleOrNull() ?: return
|
||||
lookupElementFactory.createStandardLookupElementsForDescriptor(samConstructor, useReceiverTypes = false)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
|
||||
typealias TaRunnable = Runnable
|
||||
|
||||
|
||||
fun usesRunnable(runnable: Runnable) {
|
||||
|
||||
}
|
||||
|
||||
fun usage() {
|
||||
usesRunnable(<caret>)
|
||||
}
|
||||
|
||||
// EXIST: {"lookupString":"TaRunnable","tailText":"() (<root>)","typeText":"Runnable"}
|
||||
@@ -1,13 +0,0 @@
|
||||
class SomeClass
|
||||
typealias TaSomeClass = SomeClass
|
||||
|
||||
fun usesSomeClass(p: SomeClass) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun usage() {
|
||||
usesSomeClass(<caret>)
|
||||
}
|
||||
|
||||
// EXIST: {"lookupString":"TaSomeClass","tailText":"() (<root>)"}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
class SomeClass<K, V>
|
||||
typealias TaSomeClass<K, V> = SomeClass<K, V>
|
||||
|
||||
fun <T> usesSomeClass(p: SomeClass<T, *>) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun usage() {
|
||||
usesSomeClass<Any>(<caret>)
|
||||
}
|
||||
|
||||
// EXIST: {"lookupString":"TaSomeClass","tailText":"() (<root>)","typeText":"SomeClass<K, V>"}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
class SomeClass<K, V>
|
||||
typealias TaSomeClass<V> = SomeClass<Any, V>
|
||||
|
||||
fun usesSomeClass(p: SomeClass<*, *>) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun usage() {
|
||||
usesSomeClass(<caret>)
|
||||
}
|
||||
|
||||
// EXIST: {"lookupString":"TaSomeClass","tailText":"() (<root>)","typeText":"SomeClass<Any, V>"}
|
||||
idea/idea-completion/testData/smart/constructor/ConstructorWithTypeParamsSubstitutionViaTypeAlias.kt
Vendored
-13
@@ -1,13 +0,0 @@
|
||||
class SomeClass<K, V>
|
||||
typealias TaSomeClass = SomeClass<Any, Any>
|
||||
|
||||
fun usesSomeClass(p: SomeClass<*, *>) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun usage() {
|
||||
usesSomeClass(<caret>)
|
||||
}
|
||||
|
||||
// EXIST: {"lookupString":"TaSomeClass","tailText":"() (<root>)","typeText":"SomeClass<Any, Any>"}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
class SomeClass<K, V>
|
||||
typealias TaSomeClass<K, V> = SomeClass<K, V>
|
||||
|
||||
fun usesSomeClass(p: SomeClass<*, *>) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun usage() {
|
||||
usesSomeClass(<caret>)
|
||||
}
|
||||
|
||||
// EXIST: {"lookupString":"TaSomeClass","tailText":"() (<root>)","typeText":"SomeClass<K, V>"}
|
||||
-36
@@ -498,12 +498,6 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SAMConstructorForTypeAlias.kt")
|
||||
public void testSAMConstructorForTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/SAMConstructorForTypeAlias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SAMExpected1.kt")
|
||||
public void testSAMExpected1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/SAMExpected1.kt");
|
||||
@@ -833,36 +827,6 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/smart/constructor"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorViaTypeAlias.kt")
|
||||
public void testConstructorViaTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/constructor/ConstructorViaTypeAlias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithTypeParamsPartialSubstitution1ViaTypeAlias.kt")
|
||||
public void testConstructorWithTypeParamsPartialSubstitution1ViaTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/constructor/ConstructorWithTypeParamsPartialSubstitution1ViaTypeAlias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithTypeParamsPartialSubstitution2ViaTypeAlias.kt")
|
||||
public void testConstructorWithTypeParamsPartialSubstitution2ViaTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/constructor/ConstructorWithTypeParamsPartialSubstitution2ViaTypeAlias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithTypeParamsSubstitutionViaTypeAlias.kt")
|
||||
public void testConstructorWithTypeParamsSubstitutionViaTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/constructor/ConstructorWithTypeParamsSubstitutionViaTypeAlias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithTypeParamsViaTypeAlias.kt")
|
||||
public void testConstructorWithTypeParamsViaTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/constructor/ConstructorWithTypeParamsViaTypeAlias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("GenericJavaClass.kt")
|
||||
public void testGenericJavaClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/constructor/GenericJavaClass.kt");
|
||||
|
||||
@@ -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.types.asSimpleType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Modifier
|
||||
@@ -176,33 +175,29 @@ class KotlinIndicesHelper(
|
||||
}
|
||||
|
||||
|
||||
fun resolveTypeAliasesUsingIndex(type: KotlinType, originalTypeName: String): Set<TypeAliasDescriptor> {
|
||||
val typeConstructor = type.constructor
|
||||
|
||||
private fun resolveTypeAliasesUsingIndex(type: KotlinType, originalTypeName: String, out: MutableCollection<String>) {
|
||||
val index = KotlinTypeAliasByExpansionShortNameIndex.INSTANCE
|
||||
val out = mutableSetOf<TypeAliasDescriptor>()
|
||||
|
||||
fun searchRecursively(typeName: String) {
|
||||
ProgressManager.checkCanceled()
|
||||
index[typeName, project, scope].asSequence()
|
||||
.map { it.resolveToDescriptorIfAny() as? TypeAliasDescriptor }
|
||||
.filterNotNull()
|
||||
.filter { it.expandedType.constructor == typeConstructor }
|
||||
.filter { it !in out }
|
||||
.onEach { out.add(it) }
|
||||
.filter { it.expandedType == type }
|
||||
.map { it.name.asString() }
|
||||
.forEach(::searchRecursively)
|
||||
.filter { it !in out }
|
||||
.onEach(::searchRecursively)
|
||||
.toCollection(out)
|
||||
}
|
||||
|
||||
searchRecursively(originalTypeName)
|
||||
return out
|
||||
}
|
||||
|
||||
private fun MutableCollection<String>.addTypeNames(type: KotlinType) {
|
||||
val constructor = type.constructor
|
||||
constructor.declarationDescriptor?.name?.asString()?.let { typeName ->
|
||||
add(typeName)
|
||||
resolveTypeAliasesUsingIndex(type, typeName).mapTo(this, { it.name.asString() })
|
||||
resolveTypeAliasesUsingIndex(type, typeName, this)
|
||||
}
|
||||
constructor.supertypes.forEach { addTypeNames(it) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user