Make JetShortNamesCache human readible
This commit is contained in:
@@ -16,23 +16,21 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.caches
|
||||
|
||||
import com.intellij.util.containers.HashSet
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiField
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||
import com.intellij.psi.PsiField
|
||||
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.HashSet
|
||||
import org.jetbrains.kotlin.asJava.JavaElementFinder
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetClassShortNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetFunctionShortNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||
import java.util.*
|
||||
|
||||
// used in Upsource, what's why in idea-analysis module
|
||||
public class JetShortNamesCache(private val project: com.intellij.openapi.project.Project) : com.intellij.psi.search.PsiShortNamesCache() {
|
||||
companion object {
|
||||
public fun getKotlinInstance(project: com.intellij.openapi.project.Project): org.jetbrains.kotlin.idea.caches.JetShortNamesCache
|
||||
= com.intellij.openapi.extensions.Extensions.getArea(project).getExtensionPoint<com.intellij.psi.search.PsiShortNamesCache>(com.intellij.psi.search.PsiShortNamesCache.EP_NAME).getExtensions()
|
||||
.firstIsInstance<JetShortNamesCache>()
|
||||
}
|
||||
|
||||
public class JetShortNamesCache(private val project: Project) : PsiShortNamesCache() {
|
||||
/**
|
||||
* Return kotlin class names from project sources which should be visible from java.
|
||||
*/
|
||||
@@ -43,34 +41,28 @@ public class JetShortNamesCache(private val project: com.intellij.openapi.projec
|
||||
val packageClassShortNames = PackageIndexUtil.getAllPossiblePackageClasses(project).keySet()
|
||||
classNames.addAll(packageClassShortNames)
|
||||
|
||||
return com.intellij.util.ArrayUtil.toStringArray(classNames)
|
||||
return classNames.toTypedArray()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class names form kotlin sources in given scope which should be visible as Java classes.
|
||||
*/
|
||||
override fun getClassesByName(org.jetbrains.annotations.NonNls name: String, scope: com.intellij.psi.search.GlobalSearchScope): Array<PsiClass> {
|
||||
val result = java.util.ArrayList<com.intellij.psi.PsiClass>()
|
||||
override fun getClassesByName(name: String, scope: com.intellij.psi.search.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)
|
||||
if (!fqNames.isEmpty()) {
|
||||
for (fqName in fqNames) {
|
||||
val psiClass = org.jetbrains.kotlin.asJava.JavaElementFinder.getInstance(project).findClass(fqName.asString(), scope)
|
||||
if (psiClass != null) {
|
||||
result.add(psiClass)
|
||||
}
|
||||
for (fqName in fqNames) {
|
||||
val psiClass = JavaElementFinder.getInstance(project).findClass(fqName.asString(), scope)
|
||||
if (psiClass != null) {
|
||||
result.add(psiClass)
|
||||
}
|
||||
}
|
||||
|
||||
// Quick check for classes from getAllClassNames()
|
||||
val classOrObjects = org.jetbrains.kotlin.idea.stubindex.JetClassShortNameIndex.getInstance().get(name, project, scope)
|
||||
if (classOrObjects.isEmpty()) {
|
||||
return result.toTypedArray()
|
||||
}
|
||||
|
||||
val classOrObjects = JetClassShortNameIndex.getInstance().get(name, project, scope)
|
||||
for (classOrObject in classOrObjects) {
|
||||
val fqName = classOrObject.getFqName()
|
||||
if (fqName != null) {
|
||||
@@ -86,19 +78,19 @@ public class JetShortNamesCache(private val project: com.intellij.openapi.projec
|
||||
}
|
||||
|
||||
override fun getAllClassNames(dest: HashSet<String>) {
|
||||
dest.addAll(java.util.Arrays.asList<String>(*getAllClassNames()))
|
||||
dest.addAll(getAllClassNames())
|
||||
}
|
||||
|
||||
override fun getMethodsByName(org.jetbrains.annotations.NonNls name: String, scope: com.intellij.psi.search.GlobalSearchScope): Array<PsiMethod>
|
||||
override fun getMethodsByName(name: String, scope: GlobalSearchScope): Array<PsiMethod>
|
||||
= emptyArray()
|
||||
|
||||
override fun getMethodsByNameIfNotMoreThan(org.jetbrains.annotations.NonNls name: String, scope: com.intellij.psi.search.GlobalSearchScope, maxCount: Int): Array<PsiMethod>
|
||||
override fun getMethodsByNameIfNotMoreThan(name: String, scope: GlobalSearchScope, maxCount: Int): Array<PsiMethod>
|
||||
= emptyArray()
|
||||
|
||||
override fun getFieldsByNameIfNotMoreThan(org.jetbrains.annotations.NonNls s: String, scope: com.intellij.psi.search.GlobalSearchScope, i: Int): Array<PsiField>
|
||||
override fun getFieldsByNameIfNotMoreThan(s: String, scope: GlobalSearchScope, i: Int): Array<PsiField>
|
||||
= emptyArray()
|
||||
|
||||
override fun processMethodsWithName(org.jetbrains.annotations.NonNls name: String, scope: com.intellij.psi.search.GlobalSearchScope, processor: com.intellij.util.Processor<PsiMethod>): Boolean
|
||||
override fun processMethodsWithName(name: String, scope: GlobalSearchScope, processor: Processor<PsiMethod>): Boolean
|
||||
= com.intellij.util.containers.ContainerUtil.process(getMethodsByName(name, scope), processor)
|
||||
|
||||
override fun getAllMethodNames(): Array<String>
|
||||
@@ -108,7 +100,7 @@ public class JetShortNamesCache(private val project: com.intellij.openapi.projec
|
||||
set.addAll(JetFunctionShortNameIndex.getInstance().getAllKeys(project))
|
||||
}
|
||||
|
||||
override fun getFieldsByName(org.jetbrains.annotations.NonNls name: String, scope: com.intellij.psi.search.GlobalSearchScope): Array<PsiField>
|
||||
override fun getFieldsByName(name: String, scope: GlobalSearchScope): Array<PsiField>
|
||||
= emptyArray()
|
||||
|
||||
override fun getAllFieldNames(): Array<String>
|
||||
|
||||
Reference in New Issue
Block a user