Extension callables index is built correctly when using alias imports
This commit is contained in:
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.stubindex
|
package org.jetbrains.kotlin.idea.stubindex
|
||||||
|
|
||||||
|
import com.google.common.collect.HashMultimap
|
||||||
|
import com.google.common.collect.Multimap
|
||||||
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.psi.stubs.IndexSink
|
import com.intellij.psi.stubs.IndexSink
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.stubs.KotlinCallableStubBase
|
import org.jetbrains.kotlin.psi.stubs.KotlinCallableStubBase
|
||||||
@@ -36,22 +39,25 @@ private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declara
|
|||||||
|
|
||||||
when (this) {
|
when (this) {
|
||||||
is JetUserType -> {
|
is JetUserType -> {
|
||||||
//TODO: aliases
|
var referenceName = getReferencedName() ?: return
|
||||||
var typeName = getReferencedName() ?: return
|
|
||||||
|
|
||||||
if (declaration is JetNamedFunction) {
|
if (declaration is JetNamedFunction) {
|
||||||
val typeParameter = declaration.getTypeParameters().firstOrNull { it.getName() == typeName }
|
val typeParameter = declaration.getTypeParameters().firstOrNull { it.getName() == referenceName }
|
||||||
if (typeParameter != null) {
|
if (typeParameter != null) {
|
||||||
val bound = typeParameter.getExtendsBound()
|
val bound = typeParameter.getExtendsBound()
|
||||||
if (bound != null) {
|
if (bound != null) {
|
||||||
bound.getTypeElement()?.index(declaration, sink)
|
bound.getTypeElement()?.index(declaration, sink)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
typeName = "Any"
|
occurrence("Any")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
occurrence(typeName)
|
occurrence(referenceName)
|
||||||
|
|
||||||
|
val aliasNames = declaration.getContainingJetFile().aliasImportMap()[referenceName]
|
||||||
|
aliasNames.forEach { occurrence(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
is JetNullableType -> getInnerType()?.index(declaration, sink)
|
is JetNullableType -> getInnerType()?.index(declaration, sink)
|
||||||
@@ -64,3 +70,30 @@ private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declara
|
|||||||
else -> occurrence("Any")
|
else -> occurrence("Any")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class CachedAliasImportData(val map: Multimap<String, String>, val fileModificationStamp: Long)
|
||||||
|
|
||||||
|
private val ALIAS_IMPORT_DATA_KEY = Key<CachedAliasImportData>("ALIAS_IMPORT_MAP_KEY")
|
||||||
|
|
||||||
|
private fun JetFile.aliasImportMap(): Multimap<String, String> {
|
||||||
|
val cached = getUserData(ALIAS_IMPORT_DATA_KEY)
|
||||||
|
val modificationStamp = getModificationStamp()
|
||||||
|
if (cached != null && modificationStamp == cached.fileModificationStamp) {
|
||||||
|
return cached.map
|
||||||
|
}
|
||||||
|
|
||||||
|
val data = CachedAliasImportData(buildAliasImportMap(), modificationStamp)
|
||||||
|
putUserData(ALIAS_IMPORT_DATA_KEY, cached)
|
||||||
|
return data.map
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun JetFile.buildAliasImportMap(): Multimap<String, String> {
|
||||||
|
val map = HashMultimap.create<String, String>()
|
||||||
|
val importList = getImportList() ?: return map
|
||||||
|
for (import in importList.getImports()) {
|
||||||
|
val aliasName = import.getAliasName() ?: continue
|
||||||
|
val name = import.getImportPath()?.fqnPart()?.shortName()?.asString() ?: continue
|
||||||
|
map.put(aliasName, name)
|
||||||
|
}
|
||||||
|
return map
|
||||||
|
}
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package second
|
||||||
|
|
||||||
|
import third.Dependency as MyDependency
|
||||||
|
|
||||||
|
fun MyDependency?.helloFun() {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T: MyDependency> T.helloFunGeneric() {
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package third
|
||||||
|
|
||||||
|
class Dependency
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package first
|
||||||
|
|
||||||
|
fun firstFun(x: third.Dependency) {
|
||||||
|
x.hello<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: helloFun
|
||||||
|
// EXIST: helloFunGeneric
|
||||||
|
// NUMBER: 2
|
||||||
+6
@@ -149,6 +149,12 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("NotImportedExtensionFunctionAndAlias")
|
||||||
|
public void testNotImportedExtensionFunctionAndAlias() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/multifile/NotImportedExtensionFunctionAndAlias/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("NotImportedExtensionProperty")
|
@TestMetadata("NotImportedExtensionProperty")
|
||||||
public void testNotImportedExtensionProperty() throws Exception {
|
public void testNotImportedExtensionProperty() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/multifile/NotImportedExtensionProperty/");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/multifile/NotImportedExtensionProperty/");
|
||||||
|
|||||||
Reference in New Issue
Block a user