Code completion and auto-import popup not offer classes from inaccessible modules + some code refactoring JetShortNamesCache
This commit is contained in:
@@ -54,9 +54,6 @@ import org.jetbrains.jet.plugin.stubindex.*;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
|
||||||
import static org.jetbrains.jet.plugin.caches.JetFromJavaDescriptorHelper.getTopLevelFunctionFqNames;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will provide both java elements from kotlin context and some declarations special to kotlin.
|
* Will provide both java elements from kotlin context and some declarations special to kotlin.
|
||||||
* All those declaration are planned to be used in completion.
|
* All those declaration are planned to be used in completion.
|
||||||
@@ -151,8 +148,6 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
/**
|
/**
|
||||||
* Get kotlin non-extension top-level function names. Method is allowed to give invalid names - all result should be
|
* Get kotlin non-extension top-level function names. Method is allowed to give invalid names - all result should be
|
||||||
* checked with getTopLevelFunctionDescriptorsByName().
|
* checked with getTopLevelFunctionDescriptorsByName().
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<String> getAllTopLevelFunctionNames() {
|
public Collection<String> getAllTopLevelFunctionNames() {
|
||||||
@@ -218,34 +213,28 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public Collection<FunctionDescriptor> getTopLevelFunctionDescriptorsByName(
|
public Collection<FunctionDescriptor> getTopLevelFunctionDescriptorsByName(
|
||||||
@NotNull String name,
|
@NotNull String name,
|
||||||
@NotNull JetSimpleNameExpression expression,
|
@NotNull JetExpression context /*TODO: to be dropped*/,
|
||||||
@NotNull ResolveSessionForBodies resolveSession,
|
@NotNull ResolveSessionForBodies resolveSession,
|
||||||
@NotNull GlobalSearchScope scope
|
@NotNull GlobalSearchScope scope) {
|
||||||
) {
|
|
||||||
// name parameter can differ from expression.getReferenceName() when expression contains completion suffix
|
|
||||||
final Name referenceName = expression.getIdentifier() == null ? JetPsiUtil.getConventionName(expression) : Name.identifier(name);
|
|
||||||
if (referenceName == null || referenceName.toString().isEmpty()) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
BindingContext context = resolveSession.resolveToElement(expression);
|
|
||||||
JetScope jetScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
|
|
||||||
|
|
||||||
|
JetScope jetScope = resolveSession.resolveToElement(context).get(BindingContext.RESOLUTION_SCOPE, context);
|
||||||
if (jetScope == null) {
|
if (jetScope == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<FunctionDescriptor> result = Sets.newHashSet();
|
Set<FunctionDescriptor> result = Sets.newHashSet();
|
||||||
|
|
||||||
|
//TODO: this code is temporary and is to be dropped when compiled top level functions are indexed
|
||||||
|
final Name identifier = Name.identifier(name);
|
||||||
Collection<FqName> topLevelFunctionFqNames =
|
Collection<FqName> topLevelFunctionFqNames =
|
||||||
ContainerUtil.filter(getTopLevelFunctionFqNames(project, scope, false), new Condition<FqName>() {
|
ContainerUtil.filter(JetFromJavaDescriptorHelper.getTopLevelFunctionFqNames(project, scope, false), new Condition<FqName>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean value(FqName fqName) {
|
public boolean value(FqName fqName) {
|
||||||
return fqName.lastSegmentIs(referenceName);
|
return fqName.lastSegmentIs(identifier);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (FqName fqName : topLevelFunctionFqNames) {
|
for (FqName fqName : topLevelFunctionFqNames) {
|
||||||
JetImportDirective importDirective = JetPsiFactory(expression).createImportDirective(new ImportPath(fqName, false));
|
JetImportDirective importDirective = new JetPsiFactory(context.getProject()).createImportDirective(new ImportPath(fqName, false));
|
||||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = new QualifiedExpressionResolver().analyseImportReference(
|
Collection<? extends DeclarationDescriptor> declarationDescriptors = new QualifiedExpressionResolver().analyseImportReference(
|
||||||
importDirective, jetScope, new BindingTraceContext(), resolveSession.getModuleDescriptor());
|
importDirective, jetScope, new BindingTraceContext(), resolveSession.getModuleDescriptor());
|
||||||
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
||||||
@@ -256,8 +245,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<FqName> affectedPackages = Sets.newHashSet();
|
Set<FqName> affectedPackages = Sets.newHashSet();
|
||||||
Collection<JetNamedFunction> jetNamedFunctions =
|
Collection<JetNamedFunction> jetNamedFunctions = JetTopLevelNonExtensionFunctionShortNameIndex.getInstance().get(name, project, scope);
|
||||||
JetTopLevelNonExtensionFunctionShortNameIndex.getInstance().get(referenceName.asString(), project, scope);
|
|
||||||
for (JetNamedFunction jetNamedFunction : jetNamedFunctions) {
|
for (JetNamedFunction jetNamedFunction : jetNamedFunctions) {
|
||||||
PsiFile containingFile = jetNamedFunction.getContainingFile();
|
PsiFile containingFile = jetNamedFunction.getContainingFile();
|
||||||
if (containingFile instanceof JetFile) {
|
if (containingFile instanceof JetFile) {
|
||||||
@@ -270,7 +258,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
PackageViewDescriptor packageDescriptor = resolveSession.getModuleDescriptor().getPackage(affectedPackage);
|
PackageViewDescriptor packageDescriptor = resolveSession.getModuleDescriptor().getPackage(affectedPackage);
|
||||||
assert packageDescriptor != null : "There's a function in stub index with invalid package: " + affectedPackage;
|
assert packageDescriptor != null : "There's a function in stub index with invalid package: " + affectedPackage;
|
||||||
JetScope memberScope = packageDescriptor.getMemberScope();
|
JetScope memberScope = packageDescriptor.getMemberScope();
|
||||||
result.addAll(memberScope.getFunctions(referenceName));
|
result.addAll(memberScope.getFunctions(identifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -304,7 +292,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<FqName> functionFQNs = extensionFunctionsFromSourceFqNames(acceptedNameCondition, searchScope);
|
Set<FqName> functionFQNs = extensionFunctionsFromSourceFqNames(acceptedNameCondition, searchScope);
|
||||||
functionFQNs.addAll(ContainerUtil.filter(getTopLevelFunctionFqNames(project, searchScope, true), new Condition<FqName>() {
|
functionFQNs.addAll(ContainerUtil.filter(JetFromJavaDescriptorHelper.getTopLevelFunctionFqNames(project, searchScope, true), new Condition<FqName>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean value(FqName fqName) {
|
public boolean value(FqName fqName) {
|
||||||
return acceptedNameCondition.value(fqName.shortName().asString());
|
return acceptedNameCondition.value(fqName.shortName().asString());
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ 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
|
||||||
|
|
||||||
class CompletionSessionConfiguration(
|
class CompletionSessionConfiguration(
|
||||||
val completeNonImportedDeclarations: Boolean,
|
val completeNonImportedDeclarations: Boolean,
|
||||||
@@ -76,6 +77,11 @@ 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 shortNamesCache = JetShortNamesCache.getKotlinInstance(project)
|
||||||
|
private val module = ModuleUtilCore.findModuleForPsiElement(parameters.getOriginalFile())
|
||||||
|
private val searchScope = if (module != null) GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) else GlobalSearchScope.EMPTY_SCOPE
|
||||||
|
|
||||||
public fun complete(): Boolean {
|
public fun complete(): Boolean {
|
||||||
assert(parameters.getCompletionType() == CompletionType.BASIC)
|
assert(parameters.getCompletionType() == CompletionType.BASIC)
|
||||||
|
|
||||||
@@ -95,7 +101,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addReferenceVariants { isPartOfTypeDeclaration(it) }
|
addReferenceVariants { isPartOfTypeDeclaration(it) }
|
||||||
JavaCompletionContributor.advertiseSecondCompletion(position.getProject(), resultSet)
|
JavaCompletionContributor.advertiseSecondCompletion(project, resultSet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -123,24 +129,18 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
|
|
||||||
if (shouldRunTopLevelCompletion()) {
|
if (shouldRunTopLevelCompletion()) {
|
||||||
TypesCompletion(parameters, resolveSession, prefixMatcher).addAllTypes(collector)
|
TypesCompletion(parameters, resolveSession, prefixMatcher).addAllTypes(collector)
|
||||||
addJetTopLevelFunctions()
|
addKotlinTopLevelFunctions()
|
||||||
addJetTopLevelObjects()
|
addKotlinTopLevelObjects()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRunExtensionsCompletion()) {
|
if (shouldRunExtensionsCompletion()) {
|
||||||
addJetExtensions()
|
addKotlinExtensions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isOnlyKeywordCompletion()
|
private fun isOnlyKeywordCompletion()
|
||||||
= PsiTreeUtil.getParentOfType(position, javaClass<JetModifierList>()) != null
|
= PsiTreeUtil.getParentOfType(position, javaClass<JetModifierList>()) != null
|
||||||
|
|
||||||
private fun addJetExtensions() {
|
|
||||||
val project = position.getProject()
|
|
||||||
val namesCache = JetShortNamesCache.getKotlinInstance(project)
|
|
||||||
collector.addDescriptorElements(namesCache.getJetCallableExtensions({ prefixMatcher.prefixMatches(it!!) }, jetReference!!.expression, resolveSession, GlobalSearchScope.allScope(project)))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isPartOfTypeDeclaration(descriptor: DeclarationDescriptor): Boolean {
|
private fun isPartOfTypeDeclaration(descriptor: DeclarationDescriptor): Boolean {
|
||||||
return when (descriptor) {
|
return when (descriptor) {
|
||||||
is PackageViewDescriptor, is TypeParameterDescriptor -> true
|
is PackageViewDescriptor, is TypeParameterDescriptor -> true
|
||||||
@@ -155,34 +155,26 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addJetTopLevelFunctions() {
|
private fun addKotlinTopLevelFunctions() {
|
||||||
val actualPrefix = prefixMatcher.getPrefix()
|
for (name in shortNamesCache.getAllTopLevelFunctionNames()) {
|
||||||
val project = position.getProject()
|
if (prefixMatcher.prefixMatches(name)) {
|
||||||
val namesCache = JetShortNamesCache.getKotlinInstance(project)
|
collector.addDescriptorElements(shortNamesCache.getTopLevelFunctionDescriptorsByName(name, jetReference!!.expression, resolveSession, searchScope))
|
||||||
val scope = GlobalSearchScope.allScope(project)
|
|
||||||
val functionNames = namesCache.getAllTopLevelFunctionNames()
|
|
||||||
|
|
||||||
// TODO: Fix complete extension not only on contains
|
|
||||||
for (name in functionNames) {
|
|
||||||
if (name.contains(actualPrefix)) {
|
|
||||||
collector.addDescriptorElements(namesCache.getTopLevelFunctionDescriptorsByName(name, jetReference!!.expression, resolveSession, scope))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addJetTopLevelObjects() {
|
private fun addKotlinTopLevelObjects() {
|
||||||
val project = position.getProject()
|
for (name in shortNamesCache.getAllTopLevelObjectNames()) {
|
||||||
val namesCache = JetShortNamesCache.getKotlinInstance(project)
|
|
||||||
val scope = GlobalSearchScope.allScope(project)
|
|
||||||
val objectNames = namesCache.getAllTopLevelObjectNames()
|
|
||||||
|
|
||||||
for (name in objectNames) {
|
|
||||||
if (prefixMatcher.prefixMatches(name)) {
|
if (prefixMatcher.prefixMatches(name)) {
|
||||||
collector.addDescriptorElements(namesCache.getTopLevelObjectsByName(name, jetReference!!.expression, resolveSession, scope))
|
collector.addDescriptorElements(shortNamesCache.getTopLevelObjectsByName(name, jetReference!!.expression, resolveSession, searchScope))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addKotlinExtensions() {
|
||||||
|
collector.addDescriptorElements(shortNamesCache.getJetCallableExtensions({ prefixMatcher.prefixMatches(it!!) }, jetReference!!.expression, resolveSession, searchScope))
|
||||||
|
}
|
||||||
|
|
||||||
private fun shouldRunOnlyTypeCompletion(): Boolean {
|
private fun shouldRunOnlyTypeCompletion(): Boolean {
|
||||||
// Check that completion in the type annotation context and if there's a qualified
|
// Check that completion in the type annotation context and if there's a qualified
|
||||||
// expression we are at first of it
|
// expression we are at first of it
|
||||||
@@ -196,9 +188,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun shouldRunTopLevelCompletion(): Boolean {
|
private fun shouldRunTopLevelCompletion(): Boolean {
|
||||||
if (!configuration.completeNonImportedDeclarations) {
|
if (!configuration.completeNonImportedDeclarations) return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (position.getNode()!!.getElementType() == JetTokens.IDENTIFIER) {
|
if (position.getNode()!!.getElementType() == JetTokens.IDENTIFIER) {
|
||||||
val parent = position.getParent()
|
val parent = position.getParent()
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ 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
|
||||||
|
|
||||||
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) {
|
||||||
@@ -41,7 +42,9 @@ class TypesCompletion(val parameters: CompletionParameters, val resolveSession:
|
|||||||
|
|
||||||
val project = parameters.getOriginalFile().getProject()
|
val project = parameters.getOriginalFile().getProject()
|
||||||
val namesCache = JetShortNamesCache.getKotlinInstance(project)
|
val namesCache = JetShortNamesCache.getKotlinInstance(project)
|
||||||
result.addDescriptorElements(namesCache.getJetClassesDescriptors({ prefixMatcher.prefixMatches(it!!) }, resolveSession, GlobalSearchScope.allScope(project)))
|
val module = ModuleUtilCore.findModuleForPsiElement(parameters.getOriginalFile()) ?: return
|
||||||
|
val searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)
|
||||||
|
result.addDescriptorElements(namesCache.getJetClassesDescriptors({ prefixMatcher.prefixMatches(it!!) }, resolveSession, searchScope))
|
||||||
|
|
||||||
if (!ProjectStructureUtil.isJsKotlinModule(parameters.getOriginalFile() as JetFile)) {
|
if (!ProjectStructureUtil.isJsKotlinModule(parameters.getOriginalFile() as JetFile)) {
|
||||||
addAdaptedJavaCompletion(result)
|
addAdaptedJavaCompletion(result)
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import com.intellij.codeInsight.intention.HighPriorityAction;
|
|||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.command.CommandProcessor;
|
import com.intellij.openapi.command.CommandProcessor;
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
|
import com.intellij.openapi.module.Module;
|
||||||
|
import com.intellij.openapi.module.ModuleUtilCore;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.Condition;
|
import com.intellij.openapi.util.Condition;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
@@ -40,6 +42,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||||
@@ -53,8 +56,8 @@ 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.resolve.ResolvePackage;
|
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
|
|
||||||
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.util.JetPsiHeuristicsUtil;
|
import org.jetbrains.jet.plugin.util.JetPsiHeuristicsUtil;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -93,16 +96,19 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolveSessionForBodies resolveSessionForBodies =
|
ResolveSessionForBodies resolveSessionForBodies = ResolvePackage.getLazyResolveSession(element);
|
||||||
ResolvePackage.getLazyResolveSession(element);
|
|
||||||
|
Module module = ModuleUtilCore.findModuleForPsiElement(file);
|
||||||
|
if (module == null) return Collections.emptyList();
|
||||||
|
GlobalSearchScope searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
|
||||||
|
|
||||||
List<FqName> result = Lists.newArrayList();
|
List<FqName> result = Lists.newArrayList();
|
||||||
if (!isSuppressedTopLevelImportInPosition(element)) {
|
if (!isSuppressedTopLevelImportInPosition(element)) {
|
||||||
result.addAll(getClassNames(referenceName, (JetFile) file, resolveSessionForBodies));
|
result.addAll(getClassNames(referenceName, (JetFile) file, searchScope, resolveSessionForBodies));
|
||||||
result.addAll(getJetTopLevelFunctions(referenceName, element, resolveSessionForBodies, file.getProject()));
|
result.addAll(getJetTopLevelFunctions(referenceName, element, searchScope, resolveSessionForBodies, file.getProject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
result.addAll(getJetExtensionFunctions(referenceName, element, resolveSessionForBodies, file.getProject()));
|
result.addAll(getJetExtensionFunctions(referenceName, element, searchScope, resolveSessionForBodies, file.getProject()));
|
||||||
|
|
||||||
return Collections2.filter(result, new Predicate<FqName>() {
|
return Collections2.filter(result, new Predicate<FqName>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -119,14 +125,15 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
|
|
||||||
private static Collection<FqName> getJetTopLevelFunctions(
|
private static Collection<FqName> getJetTopLevelFunctions(
|
||||||
@NotNull String referenceName,
|
@NotNull String referenceName,
|
||||||
@NotNull JetSimpleNameExpression expression,
|
@NotNull JetExpression context,
|
||||||
|
@NotNull GlobalSearchScope searchScope,
|
||||||
@NotNull ResolveSessionForBodies resolveSession,
|
@NotNull ResolveSessionForBodies resolveSession,
|
||||||
@NotNull Project project
|
@NotNull Project project
|
||||||
) {
|
) {
|
||||||
JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
|
JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
|
||||||
|
|
||||||
Collection<FunctionDescriptor> topLevelFunctions = namesCache.getTopLevelFunctionDescriptorsByName(
|
Collection<FunctionDescriptor> topLevelFunctions = namesCache.getTopLevelFunctionDescriptorsByName(
|
||||||
referenceName, expression, resolveSession, GlobalSearchScope.allScope(project));
|
referenceName, context, resolveSession, searchScope);
|
||||||
|
|
||||||
return Sets.newHashSet(Collections2.transform(topLevelFunctions, new Function<DeclarationDescriptor, FqName>() {
|
return Sets.newHashSet(Collections2.transform(topLevelFunctions, new Function<DeclarationDescriptor, FqName>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -140,6 +147,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
private static Collection<FqName> getJetExtensionFunctions(
|
private static Collection<FqName> getJetExtensionFunctions(
|
||||||
@NotNull final String referenceName,
|
@NotNull final String referenceName,
|
||||||
@NotNull JetSimpleNameExpression expression,
|
@NotNull JetSimpleNameExpression expression,
|
||||||
|
@NotNull GlobalSearchScope searchScope,
|
||||||
@NotNull ResolveSessionForBodies resolveSession,
|
@NotNull ResolveSessionForBodies resolveSession,
|
||||||
@NotNull Project project
|
@NotNull Project project
|
||||||
) {
|
) {
|
||||||
@@ -153,7 +161,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
},
|
},
|
||||||
expression,
|
expression,
|
||||||
resolveSession,
|
resolveSession,
|
||||||
GlobalSearchScope.allScope(project));
|
searchScope);
|
||||||
|
|
||||||
return Sets.newHashSet(Collections2.transform(jetCallableExtensions, new Function<DeclarationDescriptor, FqName>() {
|
return Sets.newHashSet(Collections2.transform(jetCallableExtensions, new Function<DeclarationDescriptor, FqName>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -167,24 +175,24 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
/*
|
/*
|
||||||
* Searches for possible class names in kotlin context and java facade.
|
* Searches for possible class names in kotlin context and java facade.
|
||||||
*/
|
*/
|
||||||
public static Collection<FqName> getClassNames(@NotNull String referenceName, @NotNull JetFile file, @NotNull KotlinCodeAnalyzer analyzer) {
|
public static Collection<FqName> getClassNames(@NotNull String referenceName, @NotNull JetFile file, @NotNull GlobalSearchScope searchScope, @NotNull KotlinCodeAnalyzer analyzer) {
|
||||||
Set<FqName> possibleResolveNames = Sets.newHashSet();
|
Set<FqName> possibleResolveNames = Sets.newHashSet();
|
||||||
|
|
||||||
if (!ProjectStructureUtil.isJsKotlinModule(file)) {
|
if (!ProjectStructureUtil.isJsKotlinModule(file)) {
|
||||||
possibleResolveNames.addAll(getClassesFromCache(referenceName, file));
|
possibleResolveNames.addAll(getClassesFromCache(referenceName, searchScope, file));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
possibleResolveNames.addAll(getJetClasses(referenceName, file.getProject(), analyzer));
|
possibleResolveNames.addAll(getJetClasses(referenceName, searchScope, file.getProject(), analyzer));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Do appropriate sorting
|
// TODO: Do appropriate sorting
|
||||||
return Lists.newArrayList(possibleResolveNames);
|
return Lists.newArrayList(possibleResolveNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<FqName> getClassesFromCache(@NotNull String typeName, @NotNull final JetFile file) {
|
private static Collection<FqName> getClassesFromCache(@NotNull String typeName, @NotNull GlobalSearchScope searchScope, @NotNull final JetFile file) {
|
||||||
PsiShortNamesCache cache = getShortNamesCache(file);
|
PsiShortNamesCache cache = getShortNamesCache(file);
|
||||||
|
|
||||||
PsiClass[] classes = cache.getClassesByName(typeName, GlobalSearchScope.allScope(file.getProject()));
|
PsiClass[] classes = cache.getClassesByName(typeName, searchScope);
|
||||||
|
|
||||||
Collection<PsiClass> accessibleClasses = Collections2.filter(Lists.newArrayList(classes), new Predicate<PsiClass>() {
|
Collection<PsiClass> accessibleClasses = Collections2.filter(Lists.newArrayList(classes), new Predicate<PsiClass>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -214,14 +222,14 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
|||||||
return PsiShortNamesCache.getInstance(jetFile.getProject());
|
return PsiShortNamesCache.getInstance(jetFile.getProject());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<FqName> getJetClasses(@NotNull final String typeName, @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.getKotlinInstance(project);
|
JetShortNamesCache cache = JetShortNamesCache.getKotlinInstance(project);
|
||||||
Collection<ClassDescriptor> descriptors = cache.getJetClassesDescriptors(new Condition<String>() {
|
Collection<ClassDescriptor> descriptors = cache.getJetClassesDescriptors(new Condition<String>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean value(String s) {
|
public boolean value(String s) {
|
||||||
return typeName.equals(s);
|
return typeName.equals(s);
|
||||||
}
|
}
|
||||||
}, resolveSession, GlobalSearchScope.allScope(project));
|
}, resolveSession, searchScope);
|
||||||
|
|
||||||
return Collections2.transform(descriptors, new Function<ClassDescriptor, FqName>() {
|
return Collections2.transform(descriptors, new Function<ClassDescriptor, FqName>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user