getTopLevelFunctionDescriptorsByName should give descriptors from the predefined resolve session
This commit is contained in:
@@ -88,6 +88,7 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
||||
return text != null ? JetPsiUtil.unquoteIdentifierOrFieldReference(text) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Name getReferencedNameAsName() {
|
||||
String name = getReferencedName();
|
||||
if (name != null && name.length() == 0) {
|
||||
|
||||
@@ -21,10 +21,7 @@ import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PsiShortNamesCache;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -34,17 +31,16 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.asJava.JavaElementFinder;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyBindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
|
||||
@@ -158,13 +154,13 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
||||
public Collection<FunctionDescriptor> getTopLevelFunctionDescriptorsByName(
|
||||
@NotNull String name,
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull GlobalSearchScope scope
|
||||
) {
|
||||
JetFile jetFile = (JetFile) expression.getContainingFile();
|
||||
BindingContext context = WholeProjectAnalyzerFacade.getLazyResolveContext(jetFile, expression);
|
||||
BindingContext context = LazyBindingContextUtils.getExpressionBindingContext(resolveSession, expression);
|
||||
JetScope jetScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
|
||||
|
||||
if (jetScope == null) {
|
||||
if (jetScope == null || name.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -185,11 +181,26 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
||||
}
|
||||
}
|
||||
|
||||
Set<FqName> affectedPackages = Sets.newHashSet();
|
||||
Collection<JetNamedFunction> jetNamedFunctions = JetShortFunctionNameIndex.getInstance().get(name, project, scope);
|
||||
for (JetNamedFunction jetNamedFunction : jetNamedFunctions) {
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile)jetNamedFunction.getContainingFile());
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) resolveSession.resolveToDescriptor(jetNamedFunction);
|
||||
result.add(functionDescriptor);
|
||||
PsiFile containingFile = jetNamedFunction.getContainingFile();
|
||||
if (containingFile instanceof JetFile) {
|
||||
JetFile jetFile = (JetFile) containingFile;
|
||||
String packageName = jetFile.getPackageName();
|
||||
if (packageName != null) {
|
||||
affectedPackages.add(new FqName(packageName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Name referenceName = Name.identifier(name);
|
||||
|
||||
for (FqName affectedPackage : affectedPackages) {
|
||||
NamespaceDescriptor packageDescriptor = resolveSession.getPackageDescriptorByFqName(affectedPackage);
|
||||
assert packageDescriptor != null : "There's a function in stub index with invalid package";
|
||||
JetScope memberScope = packageDescriptor.getMemberScope();
|
||||
result.addAll(memberScope.getFunctions(referenceName));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -35,6 +35,8 @@ import org.jetbrains.jet.cli.jvm.compiler.TipsManager;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyBindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.caches.JetCacheManager;
|
||||
@@ -202,12 +204,12 @@ public class JetCompletionContributor extends CompletionContributor {
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
|
||||
Collection<String> functionNames = namesCache.getAllTopLevelFunctionNames();
|
||||
|
||||
BindingContext resolutionContext = WholeProjectAnalyzerFacade.getLazyResolveContext(
|
||||
(JetFile) position.getContainingFile(), expression);
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) position.getContainingFile());
|
||||
BindingContext resolutionContext = LazyBindingContextUtils.getExpressionBindingContext(resolveSession, expression);
|
||||
|
||||
for (String name : functionNames) {
|
||||
if (name.contains(actualPrefix)) {
|
||||
for (FunctionDescriptor function : namesCache.getTopLevelFunctionDescriptorsByName(name, expression, scope)) {
|
||||
for (FunctionDescriptor function : namesCache.getTopLevelFunctionDescriptorsByName(name, expression, resolveSession, scope)) {
|
||||
addCompletionToResult(result, DescriptorLookupConverter.createLookupElement(resolutionContext, function), session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,6 @@ import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyBindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
|
||||
import static org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache.analyzeFileWithCache;
|
||||
import static org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache.getLazyResolveSession;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -39,12 +36,12 @@ public final class WholeProjectAnalyzerFacade {
|
||||
|
||||
@NotNull
|
||||
public static AnalyzeExhaust analyzeProjectWithCacheOnAFile(@NotNull JetFile file) {
|
||||
return analyzeFileWithCache(file, JetFilesProvider.getInstance(file.getProject()).sampleToAllFilesInModule());
|
||||
return AnalyzerFacadeWithCache.analyzeFileWithCache(file, JetFilesProvider.getInstance(file.getProject()).sampleToAllFilesInModule());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolveSession getLazyResolveSessionForFile(@NotNull JetFile file) {
|
||||
return getLazyResolveSession(file);
|
||||
return AnalyzerFacadeWithCache.getLazyResolveSession(file);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -110,9 +110,11 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
|
||||
JetSimpleNameExpression expression,
|
||||
@NotNull Project project) {
|
||||
JetShortNamesCache namesCache = JetCacheManager.getInstance(project).getNamesCache();
|
||||
|
||||
Collection<FunctionDescriptor> topLevelFunctions = namesCache.getTopLevelFunctionDescriptorsByName(
|
||||
referenceName,
|
||||
expression,
|
||||
WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) expression.getContainingFile()),
|
||||
GlobalSearchScope.allScope(project));
|
||||
|
||||
return Sets.newHashSet(Collections2.transform(topLevelFunctions, new Function<DeclarationDescriptor, FqName>() {
|
||||
|
||||
Reference in New Issue
Block a user