Make JetShortNamesCache human readible
This commit is contained in:
@@ -16,23 +16,21 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.caches
|
package org.jetbrains.kotlin.idea.caches
|
||||||
|
|
||||||
import com.intellij.util.containers.HashSet
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiMethod
|
|
||||||
import com.intellij.psi.PsiField
|
|
||||||
import com.intellij.psi.PsiClass
|
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.JetClassShortNameIndex
|
||||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
|
||||||
import org.jetbrains.kotlin.idea.stubindex.JetFunctionShortNameIndex
|
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: Project) : PsiShortNamesCache() {
|
||||||
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>()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return kotlin class names from project sources which should be visible from java.
|
* 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()
|
val packageClassShortNames = PackageIndexUtil.getAllPossiblePackageClasses(project).keySet()
|
||||||
classNames.addAll(packageClassShortNames)
|
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.
|
* 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> {
|
override fun getClassesByName(name: String, scope: com.intellij.psi.search.GlobalSearchScope): Array<PsiClass> {
|
||||||
val result = java.util.ArrayList<com.intellij.psi.PsiClass>()
|
val result = ArrayList<PsiClass>()
|
||||||
|
|
||||||
val packageClasses = PackageIndexUtil.getAllPossiblePackageClasses(project)
|
val packageClasses = PackageIndexUtil.getAllPossiblePackageClasses(project)
|
||||||
|
|
||||||
// package classes can not be indexed, since they have no explicit declarations
|
// package classes can not be indexed, since they have no explicit declarations
|
||||||
val fqNames = packageClasses.get(name)
|
val fqNames = packageClasses.get(name)
|
||||||
if (!fqNames.isEmpty()) {
|
for (fqName in fqNames) {
|
||||||
for (fqName in fqNames) {
|
val psiClass = JavaElementFinder.getInstance(project).findClass(fqName.asString(), scope)
|
||||||
val psiClass = org.jetbrains.kotlin.asJava.JavaElementFinder.getInstance(project).findClass(fqName.asString(), scope)
|
if (psiClass != null) {
|
||||||
if (psiClass != null) {
|
result.add(psiClass)
|
||||||
result.add(psiClass)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quick check for classes from getAllClassNames()
|
// Quick check for classes from getAllClassNames()
|
||||||
val classOrObjects = org.jetbrains.kotlin.idea.stubindex.JetClassShortNameIndex.getInstance().get(name, project, scope)
|
val classOrObjects = JetClassShortNameIndex.getInstance().get(name, project, scope)
|
||||||
if (classOrObjects.isEmpty()) {
|
|
||||||
return result.toTypedArray()
|
|
||||||
}
|
|
||||||
|
|
||||||
for (classOrObject in classOrObjects) {
|
for (classOrObject in classOrObjects) {
|
||||||
val fqName = classOrObject.getFqName()
|
val fqName = classOrObject.getFqName()
|
||||||
if (fqName != null) {
|
if (fqName != null) {
|
||||||
@@ -86,19 +78,19 @@ public class JetShortNamesCache(private val project: com.intellij.openapi.projec
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllClassNames(dest: HashSet<String>) {
|
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()
|
= 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()
|
= 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()
|
= 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)
|
= com.intellij.util.containers.ContainerUtil.process(getMethodsByName(name, scope), processor)
|
||||||
|
|
||||||
override fun getAllMethodNames(): Array<String>
|
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))
|
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()
|
= emptyArray()
|
||||||
|
|
||||||
override fun getAllFieldNames(): Array<String>
|
override fun getAllFieldNames(): Array<String>
|
||||||
|
|||||||
Reference in New Issue
Block a user