Moved code that has nothing to do with short names from short names cache
This commit is contained in:
@@ -122,131 +122,6 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac
|
|||||||
destination.addAll(Arrays.asList<String>(*getAllClassNames()))
|
destination.addAll(Arrays.asList<String>(*getAllClassNames()))
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getTopLevelObjects(nameFilter: (String) -> Boolean, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection<ClassDescriptor> {
|
|
||||||
val allObjectNames = JetTopLevelObjectShortNameIndex.getInstance().getAllKeys(project).stream() +
|
|
||||||
JetFromJavaDescriptorHelper.getPossiblePackageDeclarationsNames(project, GlobalSearchScope.allScope(project)).stream()
|
|
||||||
return allObjectNames
|
|
||||||
.filter(nameFilter)
|
|
||||||
.toSet()
|
|
||||||
.flatMap { getTopLevelObjectsByName(it, resolveSession, scope) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getTopLevelObjectsByName(name: String, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection<ClassDescriptor> {
|
|
||||||
val result = hashSetOf<ClassDescriptor>()
|
|
||||||
|
|
||||||
val topObjects = JetTopLevelObjectShortNameIndex.getInstance().get(name, project, scope)
|
|
||||||
for (objectDeclaration in topObjects) {
|
|
||||||
val fqName = objectDeclaration.getFqName() ?: error("Local object declaration in JetTopLevelShortObjectNameIndex:${objectDeclaration.getText()}")
|
|
||||||
result.addAll(ResolveSessionUtils.getClassOrObjectDescriptorsByFqName(resolveSession, fqName, ResolveSessionUtils.SINGLETON_FILTER))
|
|
||||||
}
|
|
||||||
|
|
||||||
for (psiClass in JetFromJavaDescriptorHelper.getCompiledClassesForTopLevelObjects(project, GlobalSearchScope.allScope(project))) {
|
|
||||||
val qualifiedName = psiClass.getQualifiedName()
|
|
||||||
if (qualifiedName != null) {
|
|
||||||
result.addAll(ResolveSessionUtils.getClassOrObjectDescriptorsByFqName(resolveSession, FqName(qualifiedName), ResolveSessionUtils.SINGLETON_FILTER))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getTopLevelFunctionDescriptorsByName(name: String, context: JetExpression /*TODO: to be dropped*/, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection<FunctionDescriptor> {
|
|
||||||
|
|
||||||
val jetScope = resolveSession.resolveToElement(context).get(BindingContext.RESOLUTION_SCOPE, context) ?: return listOf()
|
|
||||||
|
|
||||||
val result = hashSetOf<FunctionDescriptor>()
|
|
||||||
|
|
||||||
//TODO: this code is temporary and is to be dropped when compiled top level functions are indexed
|
|
||||||
val identifier = Name.identifier(name)
|
|
||||||
for (fqName in JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, false)) {
|
|
||||||
if (fqName.lastSegmentIs(identifier)) {
|
|
||||||
findTopLevelCallables(fqName, context, jetScope, resolveSession).filterIsInstanceTo(result, javaClass<FunctionDescriptor>())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.addSourceTopLevelFunctions(name, resolveSession, scope)
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun MutableCollection<in FunctionDescriptor>.addSourceTopLevelFunctions(name: String, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope) {
|
|
||||||
val identifier = Name.identifier(name)
|
|
||||||
val affectedPackages = JetTopLevelNonExtensionFunctionShortNameIndex.getInstance().get(name, project, scope)
|
|
||||||
.map { it.getContainingFile() }
|
|
||||||
.filterIsInstance(javaClass<JetFile>())
|
|
||||||
.map { it.getPackageFqName() }
|
|
||||||
.toSet()
|
|
||||||
|
|
||||||
for (affectedPackage in affectedPackages) {
|
|
||||||
val packageDescriptor = resolveSession.getModuleDescriptor().getPackage(affectedPackage)
|
|
||||||
?: error("There's a function in stub index with invalid package: $affectedPackage")
|
|
||||||
addAll(packageDescriptor.getMemberScope().getFunctions(identifier))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getTopLevelCallables(nameFilter: (String) -> Boolean, context: JetExpression /*TODO: to be dropped*/, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection<DeclarationDescriptor> {
|
|
||||||
val result = ArrayList<DeclarationDescriptor>()
|
|
||||||
|
|
||||||
val sourceNames = JetTopLevelFunctionsFqnNameIndex.getInstance().getAllKeys(project).stream() + JetTopLevelPropertiesFqnNameIndex.getInstance().getAllKeys(project).stream()
|
|
||||||
val allFqNames = sourceNames.map { FqName(it) } + JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, false).stream()
|
|
||||||
|
|
||||||
val jetScope = resolveSession.resolveToElement(context).get(BindingContext.RESOLUTION_SCOPE, context) ?: return listOf()
|
|
||||||
allFqNames.filter { nameFilter(it.shortName().asString()) }
|
|
||||||
.toSet()
|
|
||||||
.flatMapTo(result) { findTopLevelCallables(it, context, jetScope, resolveSession) }
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getCallableExtensions(nameFilter: (String) -> Boolean,
|
|
||||||
expression: JetSimpleNameExpression,
|
|
||||||
resolveSession: ResolveSessionForBodies,
|
|
||||||
scope: GlobalSearchScope): Collection<DeclarationDescriptor> {
|
|
||||||
val context = resolveSession.resolveToElement(expression)
|
|
||||||
val receiverExpression = expression.getReceiverExpression() ?: return listOf()
|
|
||||||
val expressionType = context.get<JetExpression, JetType>(BindingContext.EXPRESSION_TYPE, receiverExpression)
|
|
||||||
val jetScope = context.get(BindingContext.RESOLUTION_SCOPE, receiverExpression)
|
|
||||||
|
|
||||||
if (expressionType == null || jetScope == null || expressionType.isError()) {
|
|
||||||
return listOf()
|
|
||||||
}
|
|
||||||
|
|
||||||
val sourceNames = JetTopLevelFunctionsFqnNameIndex.getInstance().getAllKeys(project).stream() + JetTopLevelPropertiesFqnNameIndex.getInstance().getAllKeys(project).stream()
|
|
||||||
val allFqNames = sourceNames.map { FqName(it) } + JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, true).stream()
|
|
||||||
|
|
||||||
// Iterate through the function with attempt to resolve found functions
|
|
||||||
return allFqNames
|
|
||||||
.filter { nameFilter(it.shortName().asString()) }
|
|
||||||
.toSet()
|
|
||||||
.flatMap { ExpressionTypingUtils.canFindSuitableCall(it, receiverExpression, expressionType, jetScope, resolveSession.getModuleDescriptor()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getClassDescriptors(nameFilter: (String) -> Boolean, analyzer: KotlinCodeAnalyzer, scope: GlobalSearchScope): Collection<ClassDescriptor> {
|
|
||||||
return JetFullClassNameIndex.getInstance().getAllKeys(project).stream()
|
|
||||||
.map { FqName(it) }
|
|
||||||
.filter { nameFilter(it.shortName().asString()) }
|
|
||||||
.toList()
|
|
||||||
.flatMap { getClassDescriptorsByFQName(analyzer, it, scope) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getClassDescriptorsByFQName(analyzer: KotlinCodeAnalyzer, classFQName: FqName, scope: GlobalSearchScope): Collection<ClassDescriptor> {
|
|
||||||
val jetClassOrObjects = JetFullClassNameIndex.getInstance().get(classFQName.asString(), project, scope)
|
|
||||||
|
|
||||||
if (jetClassOrObjects.isEmpty()) {
|
|
||||||
// This fqn is absent in caches, dead or not in scope
|
|
||||||
return listOf()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: Can't search with psi element as analyzer could be built over temp files
|
|
||||||
return ResolveSessionUtils.getClassDescriptorsByFqName(analyzer, classFQName)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun findTopLevelCallables(fqName: FqName, context: JetExpression, jetScope: JetScope, resolveSession: ResolveSessionForBodies): Collection<DeclarationDescriptor> {
|
|
||||||
val importDirective = JetPsiFactory(context.getProject()).createImportDirective(ImportPath(fqName, false))
|
|
||||||
val allDescriptors = QualifiedExpressionResolver().analyseImportReference(importDirective, jetScope, BindingTraceContext(), resolveSession.getModuleDescriptor())
|
|
||||||
return allDescriptors.filterIsInstance(javaClass<CallableDescriptor>()).filter { it.getReceiverParameter() == null }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getMethodsByName(NonNls name: String, scope: GlobalSearchScope): Array<PsiMethod>
|
override fun getMethodsByName(NonNls name: String, scope: GlobalSearchScope): Array<PsiMethod>
|
||||||
= array()
|
= array()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.plugin.caches
|
||||||
|
|
||||||
|
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetTopLevelObjectShortNameIndex
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression
|
||||||
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetTopLevelNonExtensionFunctionShortNameIndex
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||||
|
import java.util.ArrayList
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex
|
||||||
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.psiUtil.getReceiverExpression
|
||||||
|
import org.jetbrains.jet.lang.types.JetType
|
||||||
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||||
|
import org.jetbrains.jet.lang.resolve.ImportPath
|
||||||
|
import org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingTraceContext
|
||||||
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
|
||||||
|
public class KotlinIndicesHelper(private val project: Project) {
|
||||||
|
public fun getTopLevelObjects(nameFilter: (String) -> Boolean, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection<ClassDescriptor> {
|
||||||
|
val allObjectNames = JetTopLevelObjectShortNameIndex.getInstance().getAllKeys(project).stream() +
|
||||||
|
JetFromJavaDescriptorHelper.getPossiblePackageDeclarationsNames(project, GlobalSearchScope.allScope(project)).stream()
|
||||||
|
return allObjectNames
|
||||||
|
.filter(nameFilter)
|
||||||
|
.toSet()
|
||||||
|
.flatMap { getTopLevelObjectsByName(it, resolveSession, scope) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getTopLevelObjectsByName(name: String, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection<ClassDescriptor> {
|
||||||
|
val result = hashSetOf<ClassDescriptor>()
|
||||||
|
|
||||||
|
val topObjects = JetTopLevelObjectShortNameIndex.getInstance().get(name, project, scope)
|
||||||
|
for (objectDeclaration in topObjects) {
|
||||||
|
val fqName = objectDeclaration.getFqName() ?: error("Local object declaration in JetTopLevelShortObjectNameIndex:${objectDeclaration.getText()}")
|
||||||
|
result.addAll(ResolveSessionUtils.getClassOrObjectDescriptorsByFqName(resolveSession, fqName, ResolveSessionUtils.SINGLETON_FILTER))
|
||||||
|
}
|
||||||
|
|
||||||
|
for (psiClass in JetFromJavaDescriptorHelper.getCompiledClassesForTopLevelObjects(project, GlobalSearchScope.allScope(project))) {
|
||||||
|
val qualifiedName = psiClass.getQualifiedName()
|
||||||
|
if (qualifiedName != null) {
|
||||||
|
result.addAll(ResolveSessionUtils.getClassOrObjectDescriptorsByFqName(resolveSession, FqName(qualifiedName), ResolveSessionUtils.SINGLETON_FILTER))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun getTopLevelFunctionDescriptorsByName(name: String, context: JetExpression /*TODO: to be dropped*/, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection<FunctionDescriptor> {
|
||||||
|
|
||||||
|
val jetScope = resolveSession.resolveToElement(context).get(BindingContext.RESOLUTION_SCOPE, context) ?: return listOf()
|
||||||
|
|
||||||
|
val result = hashSetOf<FunctionDescriptor>()
|
||||||
|
|
||||||
|
//TODO: this code is temporary and is to be dropped when compiled top level functions are indexed
|
||||||
|
val identifier = Name.identifier(name)
|
||||||
|
for (fqName in JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, false)) {
|
||||||
|
if (fqName.lastSegmentIs(identifier)) {
|
||||||
|
findTopLevelCallables(fqName, context, jetScope, resolveSession).filterIsInstanceTo(result, javaClass<FunctionDescriptor>())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.addSourceTopLevelFunctions(name, resolveSession, scope)
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun MutableCollection<in FunctionDescriptor>.addSourceTopLevelFunctions(name: String, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope) {
|
||||||
|
val identifier = Name.identifier(name)
|
||||||
|
val affectedPackages = JetTopLevelNonExtensionFunctionShortNameIndex.getInstance().get(name, project, scope)
|
||||||
|
.map { it.getContainingFile() }
|
||||||
|
.filterIsInstance(javaClass<JetFile>())
|
||||||
|
.map { it.getPackageFqName() }
|
||||||
|
.toSet()
|
||||||
|
|
||||||
|
for (affectedPackage in affectedPackages) {
|
||||||
|
val packageDescriptor = resolveSession.getModuleDescriptor().getPackage(affectedPackage)
|
||||||
|
?: error("There's a function in stub index with invalid package: $affectedPackage")
|
||||||
|
addAll(packageDescriptor.getMemberScope().getFunctions(identifier))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun getTopLevelCallables(nameFilter: (String) -> Boolean, context: JetExpression /*TODO: to be dropped*/, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection<DeclarationDescriptor> {
|
||||||
|
val result = ArrayList<DeclarationDescriptor>()
|
||||||
|
|
||||||
|
val sourceNames = JetTopLevelFunctionsFqnNameIndex.getInstance().getAllKeys(project).stream() + JetTopLevelPropertiesFqnNameIndex.getInstance().getAllKeys(project).stream()
|
||||||
|
val allFqNames = sourceNames.map { FqName(it) } + JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, false).stream()
|
||||||
|
|
||||||
|
val jetScope = resolveSession.resolveToElement(context).get(BindingContext.RESOLUTION_SCOPE, context) ?: return listOf()
|
||||||
|
allFqNames.filter { nameFilter(it.shortName().asString()) }
|
||||||
|
.toSet()
|
||||||
|
.flatMapTo(result) { findTopLevelCallables(it, context, jetScope, resolveSession) }
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun getCallableExtensions(nameFilter: (String) -> Boolean,
|
||||||
|
expression: JetSimpleNameExpression,
|
||||||
|
resolveSession: ResolveSessionForBodies,
|
||||||
|
scope: GlobalSearchScope): Collection<DeclarationDescriptor> {
|
||||||
|
val context = resolveSession.resolveToElement(expression)
|
||||||
|
val receiverExpression = expression.getReceiverExpression() ?: return listOf()
|
||||||
|
val expressionType = context.get<JetExpression, JetType>(BindingContext.EXPRESSION_TYPE, receiverExpression)
|
||||||
|
val jetScope = context.get(BindingContext.RESOLUTION_SCOPE, receiverExpression)
|
||||||
|
|
||||||
|
if (expressionType == null || jetScope == null || expressionType.isError()) {
|
||||||
|
return listOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
val sourceNames = JetTopLevelFunctionsFqnNameIndex.getInstance().getAllKeys(project).stream() + JetTopLevelPropertiesFqnNameIndex.getInstance().getAllKeys(project).stream()
|
||||||
|
val allFqNames = sourceNames.map { FqName(it) } + JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, true).stream()
|
||||||
|
|
||||||
|
// Iterate through the function with attempt to resolve found functions
|
||||||
|
return allFqNames
|
||||||
|
.filter { nameFilter(it.shortName().asString()) }
|
||||||
|
.toSet()
|
||||||
|
.flatMap { ExpressionTypingUtils.canFindSuitableCall(it, receiverExpression, expressionType, jetScope, resolveSession.getModuleDescriptor()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun getClassDescriptors(nameFilter: (String) -> Boolean, analyzer: KotlinCodeAnalyzer, scope: GlobalSearchScope): Collection<ClassDescriptor> {
|
||||||
|
return JetFullClassNameIndex.getInstance().getAllKeys(project).stream()
|
||||||
|
.map { FqName(it) }
|
||||||
|
.filter { nameFilter(it.shortName().asString()) }
|
||||||
|
.toList()
|
||||||
|
.flatMap { getClassDescriptorsByFQName(analyzer, it, scope) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getClassDescriptorsByFQName(analyzer: KotlinCodeAnalyzer, classFQName: FqName, scope: GlobalSearchScope): Collection<ClassDescriptor> {
|
||||||
|
val jetClassOrObjects = JetFullClassNameIndex.getInstance().get(classFQName.asString(), project, scope)
|
||||||
|
|
||||||
|
if (jetClassOrObjects.isEmpty()) {
|
||||||
|
// This fqn is absent in caches, dead or not in scope
|
||||||
|
return listOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: Can't search with psi element as analyzer could be built over temp files
|
||||||
|
return ResolveSessionUtils.getClassDescriptorsByFqName(analyzer, classFQName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun findTopLevelCallables(fqName: FqName, context: JetExpression, jetScope: JetScope, resolveSession: ResolveSessionForBodies): Collection<DeclarationDescriptor> {
|
||||||
|
val importDirective = JetPsiFactory(context.getProject()).createImportDirective(ImportPath(fqName, false))
|
||||||
|
val allDescriptors = QualifiedExpressionResolver().analyseImportReference(importDirective, jetScope, BindingTraceContext(), resolveSession.getModuleDescriptor())
|
||||||
|
return allDescriptors.filterIsInstance(javaClass<CallableDescriptor>()).filter { it.getReceiverParameter() == null }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,13 +25,13 @@ import org.jetbrains.jet.lang.psi.*
|
|||||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||||
import org.jetbrains.jet.lexer.JetTokens
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
import org.jetbrains.jet.plugin.caches.JetShortNamesCache
|
|
||||||
import org.jetbrains.jet.plugin.caches.resolve.*
|
import org.jetbrains.jet.plugin.caches.resolve.*
|
||||||
import org.jetbrains.jet.plugin.codeInsight.TipsManager
|
import org.jetbrains.jet.plugin.codeInsight.TipsManager
|
||||||
import org.jetbrains.jet.plugin.completion.smart.SmartCompletion
|
import org.jetbrains.jet.plugin.completion.smart.SmartCompletion
|
||||||
import org.jetbrains.jet.plugin.references.JetSimpleNameReference
|
import org.jetbrains.jet.plugin.references.JetSimpleNameReference
|
||||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
|
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
|
||||||
import com.intellij.openapi.module.ModuleUtilCore
|
import com.intellij.openapi.module.ModuleUtilCore
|
||||||
|
import org.jetbrains.jet.plugin.caches.KotlinIndicesHelper
|
||||||
|
|
||||||
class CompletionSessionConfiguration(
|
class CompletionSessionConfiguration(
|
||||||
val completeNonImportedDeclarations: Boolean,
|
val completeNonImportedDeclarations: Boolean,
|
||||||
@@ -78,7 +78,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
private val collector: LookupElementsCollector = LookupElementsCollector(prefixMatcher, resolveSession, { isVisibleDescriptor(it) })
|
private val collector: LookupElementsCollector = LookupElementsCollector(prefixMatcher, resolveSession, { isVisibleDescriptor(it) })
|
||||||
|
|
||||||
private val project = position.getProject()
|
private val project = position.getProject()
|
||||||
private val shortNamesCache = JetShortNamesCache.getKotlinInstance(project)
|
private val indicesHelper = KotlinIndicesHelper(project)
|
||||||
private val module = ModuleUtilCore.findModuleForPsiElement(parameters.getOriginalFile())
|
private val module = ModuleUtilCore.findModuleForPsiElement(parameters.getOriginalFile())
|
||||||
private val searchScope = if (module != null) GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) else GlobalSearchScope.EMPTY_SCOPE
|
private val searchScope = if (module != null) GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) else GlobalSearchScope.EMPTY_SCOPE
|
||||||
|
|
||||||
@@ -156,12 +156,12 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
|
|
||||||
private fun addKotlinTopLevelDeclarations() {
|
private fun addKotlinTopLevelDeclarations() {
|
||||||
val filter = { (name: String) -> prefixMatcher.prefixMatches(name) }
|
val filter = { (name: String) -> prefixMatcher.prefixMatches(name) }
|
||||||
collector.addDescriptorElements(shortNamesCache.getTopLevelCallables(filter, jetReference!!.expression, resolveSession, searchScope) +
|
collector.addDescriptorElements(indicesHelper.getTopLevelCallables(filter, jetReference!!.expression, resolveSession, searchScope) +
|
||||||
shortNamesCache.getTopLevelObjects(filter, resolveSession, searchScope))
|
indicesHelper.getTopLevelObjects(filter, resolveSession, searchScope))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addKotlinExtensions() {
|
private fun addKotlinExtensions() {
|
||||||
collector.addDescriptorElements(shortNamesCache.getCallableExtensions({ prefixMatcher.prefixMatches(it) }, jetReference!!.expression, resolveSession, searchScope))
|
collector.addDescriptorElements(indicesHelper.getCallableExtensions({ prefixMatcher.prefixMatches(it) }, jetReference!!.expression, resolveSession, searchScope))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shouldRunOnlyTypeCompletion(): Boolean {
|
private fun shouldRunOnlyTypeCompletion(): Boolean {
|
||||||
|
|||||||
@@ -30,21 +30,20 @@ import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils
|
|||||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||||
import org.jetbrains.jet.plugin.caches.JetFromJavaDescriptorHelper
|
import org.jetbrains.jet.plugin.caches.JetFromJavaDescriptorHelper
|
||||||
import org.jetbrains.jet.plugin.caches.JetShortNamesCache
|
|
||||||
import org.jetbrains.jet.plugin.completion.handlers.JetJavaClassInsertHandler
|
import org.jetbrains.jet.plugin.completion.handlers.JetJavaClassInsertHandler
|
||||||
import org.jetbrains.jet.plugin.project.ProjectStructureUtil
|
import org.jetbrains.jet.plugin.project.ProjectStructureUtil
|
||||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
|
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
|
||||||
import com.intellij.openapi.module.ModuleUtilCore
|
import com.intellij.openapi.module.ModuleUtilCore
|
||||||
|
import org.jetbrains.jet.plugin.caches.KotlinIndicesHelper
|
||||||
|
|
||||||
class TypesCompletion(val parameters: CompletionParameters, val resolveSession: ResolveSessionForBodies, val prefixMatcher: PrefixMatcher) {
|
class TypesCompletion(val parameters: CompletionParameters, val resolveSession: ResolveSessionForBodies, val prefixMatcher: PrefixMatcher) {
|
||||||
fun addAllTypes(result: LookupElementsCollector) {
|
fun addAllTypes(result: LookupElementsCollector) {
|
||||||
result.addDescriptorElements(KotlinBuiltIns.getInstance().getNonPhysicalClasses())
|
result.addDescriptorElements(KotlinBuiltIns.getInstance().getNonPhysicalClasses())
|
||||||
|
|
||||||
val project = parameters.getOriginalFile().getProject()
|
val project = parameters.getOriginalFile().getProject()
|
||||||
val namesCache = JetShortNamesCache.getKotlinInstance(project)
|
|
||||||
val module = ModuleUtilCore.findModuleForPsiElement(parameters.getOriginalFile()) ?: return
|
val module = ModuleUtilCore.findModuleForPsiElement(parameters.getOriginalFile()) ?: return
|
||||||
val searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)
|
val searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)
|
||||||
result.addDescriptorElements(namesCache.getClassDescriptors({ prefixMatcher.prefixMatches(it) }, resolveSession, searchScope))
|
result.addDescriptorElements(KotlinIndicesHelper(project).getClassDescriptors({ prefixMatcher.prefixMatches(it) }, resolveSession, searchScope))
|
||||||
|
|
||||||
if (!ProjectStructureUtil.isJsKotlinModule(parameters.getOriginalFile() as JetFile)) {
|
if (!ProjectStructureUtil.isJsKotlinModule(parameters.getOriginalFile() as JetFile)) {
|
||||||
addAdaptedJavaCompletion(result)
|
addAdaptedJavaCompletion(result)
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
|||||||
import org.jetbrains.jet.plugin.JetBundle;
|
import org.jetbrains.jet.plugin.JetBundle;
|
||||||
import org.jetbrains.jet.plugin.actions.JetAddImportAction;
|
import org.jetbrains.jet.plugin.actions.JetAddImportAction;
|
||||||
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
|
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
|
||||||
|
import org.jetbrains.jet.plugin.caches.KotlinIndicesHelper;
|
||||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
||||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
|
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
|
||||||
@@ -130,9 +131,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
@NotNull ResolveSessionForBodies resolveSession,
|
@NotNull ResolveSessionForBodies resolveSession,
|
||||||
@NotNull Project project
|
@NotNull Project project
|
||||||
) {
|
) {
|
||||||
JetShortNamesCache namesCache = JetShortNamesCache.OBJECT$.getKotlinInstance(project);
|
Collection<FunctionDescriptor> topLevelFunctions = new KotlinIndicesHelper(project).getTopLevelFunctionDescriptorsByName(
|
||||||
|
|
||||||
Collection<FunctionDescriptor> topLevelFunctions = namesCache.getTopLevelFunctionDescriptorsByName(
|
|
||||||
referenceName, context, resolveSession, searchScope);
|
referenceName, context, resolveSession, searchScope);
|
||||||
|
|
||||||
return Sets.newHashSet(Collections2.transform(topLevelFunctions, new Function<DeclarationDescriptor, FqName>() {
|
return Sets.newHashSet(Collections2.transform(topLevelFunctions, new Function<DeclarationDescriptor, FqName>() {
|
||||||
@@ -151,8 +150,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
@NotNull ResolveSessionForBodies resolveSession,
|
@NotNull ResolveSessionForBodies resolveSession,
|
||||||
@NotNull Project project
|
@NotNull Project project
|
||||||
) {
|
) {
|
||||||
JetShortNamesCache namesCache = JetShortNamesCache.OBJECT$.getKotlinInstance(project);
|
Collection<DeclarationDescriptor> jetCallableExtensions = new KotlinIndicesHelper(project).getCallableExtensions(
|
||||||
Collection<DeclarationDescriptor> jetCallableExtensions = namesCache.getCallableExtensions(
|
|
||||||
new Function1<String, Boolean>() {
|
new Function1<String, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean invoke(String callableExtensionName) {
|
public Boolean invoke(String callableExtensionName) {
|
||||||
@@ -223,8 +221,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<FqName> getJetClasses(@NotNull final String typeName, @NotNull GlobalSearchScope searchScope, @NotNull Project project, @NotNull KotlinCodeAnalyzer resolveSession) {
|
private static Collection<FqName> getJetClasses(@NotNull final String typeName, @NotNull GlobalSearchScope searchScope, @NotNull Project project, @NotNull KotlinCodeAnalyzer resolveSession) {
|
||||||
JetShortNamesCache cache = JetShortNamesCache.OBJECT$.getKotlinInstance(project);
|
Collection<ClassDescriptor> descriptors = new KotlinIndicesHelper(project).getClassDescriptors(new Function1<String, Boolean>() {
|
||||||
Collection<ClassDescriptor> descriptors = cache.getClassDescriptors(new Function1<String, Boolean>() {
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean invoke(String s) {
|
public Boolean invoke(String s) {
|
||||||
return typeName.equals(s);
|
return typeName.equals(s);
|
||||||
|
|||||||
Reference in New Issue
Block a user