Initial version of completing unimported file facades
This commit is contained in:
@@ -23,11 +23,14 @@ import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.search.PsiShortNamesCache
|
||||
import com.intellij.util.Processor
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.containers.HashSet
|
||||
import org.jetbrains.kotlin.asJava.JavaElementFinder
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetClassShortNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetFileFacadeClassIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetFunctionShortNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.util.*
|
||||
|
||||
public class JetShortNamesCache(private val project: Project) : PsiShortNamesCache() {
|
||||
@@ -40,6 +43,7 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac
|
||||
// package classes can not be indexed, since they have no explicit declarations
|
||||
val packageClassShortNames = PackageIndexUtil.getAllPossiblePackageClasses(project).keySet()
|
||||
classNames.addAll(packageClassShortNames)
|
||||
classNames.addAll(JetFileFacadeClassIndex.getAllFacadeShortNames(project))
|
||||
|
||||
return classNames.toTypedArray()
|
||||
}
|
||||
@@ -47,13 +51,13 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac
|
||||
/**
|
||||
* Return class names form kotlin sources in given scope which should be visible as Java classes.
|
||||
*/
|
||||
override fun getClassesByName(name: String, scope: com.intellij.psi.search.GlobalSearchScope): Array<PsiClass> {
|
||||
override fun getClassesByName(name: String, scope: GlobalSearchScope): Array<PsiClass> {
|
||||
val result = ArrayList<PsiClass>()
|
||||
|
||||
val packageClasses = PackageIndexUtil.getAllPossiblePackageClasses(project)
|
||||
|
||||
// package classes can not be indexed, since they have no explicit declarations
|
||||
val fqNames = packageClasses.get(name)
|
||||
val fqNames = packageClasses.get(name) + JetFileFacadeClassIndex.getInstance().getAllKeys(project).map { FqName(it) }.filter { it.shortName().asString() == name }
|
||||
for (fqName in fqNames) {
|
||||
val psiClass = JavaElementFinder.getInstance(project).findClass(fqName.asString(), scope)
|
||||
if (psiClass != null) {
|
||||
@@ -67,7 +71,7 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac
|
||||
val fqName = classOrObject.getFqName()
|
||||
if (fqName != null) {
|
||||
assert(fqName.shortName().asString() == name) { "A declaration obtained from index has non-matching name:\n" + "in index: " + name + "\n" + "declared: " + fqName.shortName() + "(" + fqName + ")" }
|
||||
val psiClass = org.jetbrains.kotlin.asJava.JavaElementFinder.getInstance(project).findClass(fqName.asString(), scope)
|
||||
val psiClass = JavaElementFinder.getInstance(project).findClass(fqName.asString(), scope)
|
||||
if (psiClass != null) {
|
||||
result.add(psiClass)
|
||||
}
|
||||
@@ -91,7 +95,7 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac
|
||||
= emptyArray()
|
||||
|
||||
override fun processMethodsWithName(name: String, scope: GlobalSearchScope, processor: Processor<PsiMethod>): Boolean
|
||||
= com.intellij.util.containers.ContainerUtil.process(getMethodsByName(name, scope), processor)
|
||||
= ContainerUtil.process(getMethodsByName(name, scope), processor)
|
||||
|
||||
override fun getAllMethodNames(): Array<String>
|
||||
= JetFunctionShortNameIndex.getInstance().getAllKeys(project).toTypedArray()
|
||||
|
||||
@@ -20,6 +20,10 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension
|
||||
import com.intellij.psi.stubs.StubIndexKey
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.psi.util.PsiModificationTracker
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
|
||||
public class JetFileFacadeClassIndex private constructor() : StringStubIndexExtension<JetFile>() {
|
||||
@@ -32,5 +36,14 @@ public class JetFileFacadeClassIndex private constructor() : StringStubIndexExte
|
||||
private val KEY = KotlinIndexUtil.createIndexKey(JetFileFacadeClassIndex::class.java)
|
||||
public val INSTANCE: JetFileFacadeClassIndex = JetFileFacadeClassIndex()
|
||||
public @jvmStatic fun getInstance(): JetFileFacadeClassIndex = INSTANCE
|
||||
|
||||
public fun getAllFacadeShortNames(project: Project): Collection<String> {
|
||||
return CachedValuesManager.getManager(project).getCachedValue(project) {
|
||||
val shortNames = getInstance().getAllKeys(project).map {
|
||||
FqName(it).shortName().asString()
|
||||
}
|
||||
CachedValueProvider.Result(shortNames, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user