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;
|
return text != null ? JetPsiUtil.unquoteIdentifierOrFieldReference(text) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Name getReferencedNameAsName() {
|
public Name getReferencedNameAsName() {
|
||||||
String name = getReferencedName();
|
String name = getReferencedName();
|
||||||
if (name != null && name.length() == 0) {
|
if (name != null && name.length() == 0) {
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ import com.google.common.collect.Collections2;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
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.*;
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.PsiField;
|
|
||||||
import com.intellij.psi.PsiMethod;
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import com.intellij.psi.search.PsiShortNamesCache;
|
import com.intellij.psi.search.PsiShortNamesCache;
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
@@ -34,17 +31,16 @@ import org.jetbrains.annotations.NonNls;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.asJava.JavaElementFinder;
|
import org.jetbrains.jet.asJava.JavaElementFinder;
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
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.psi.*;
|
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.resolve.BindingTraceContext;
|
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||||
import org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver;
|
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.lazy.ResolveSession;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
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.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
|
||||||
@@ -158,13 +154,13 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
public Collection<FunctionDescriptor> getTopLevelFunctionDescriptorsByName(
|
public Collection<FunctionDescriptor> getTopLevelFunctionDescriptorsByName(
|
||||||
@NotNull String name,
|
@NotNull String name,
|
||||||
@NotNull JetSimpleNameExpression expression,
|
@NotNull JetSimpleNameExpression expression,
|
||||||
|
@NotNull ResolveSession resolveSession,
|
||||||
@NotNull GlobalSearchScope scope
|
@NotNull GlobalSearchScope scope
|
||||||
) {
|
) {
|
||||||
JetFile jetFile = (JetFile) expression.getContainingFile();
|
BindingContext context = LazyBindingContextUtils.getExpressionBindingContext(resolveSession, expression);
|
||||||
BindingContext context = WholeProjectAnalyzerFacade.getLazyResolveContext(jetFile, expression);
|
|
||||||
JetScope jetScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
|
JetScope jetScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
|
||||||
|
|
||||||
if (jetScope == null) {
|
if (jetScope == null || name.isEmpty()) {
|
||||||
return Collections.emptyList();
|
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);
|
Collection<JetNamedFunction> jetNamedFunctions = JetShortFunctionNameIndex.getInstance().get(name, project, scope);
|
||||||
for (JetNamedFunction jetNamedFunction : jetNamedFunctions) {
|
for (JetNamedFunction jetNamedFunction : jetNamedFunctions) {
|
||||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile)jetNamedFunction.getContainingFile());
|
PsiFile containingFile = jetNamedFunction.getContainingFile();
|
||||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) resolveSession.resolveToDescriptor(jetNamedFunction);
|
if (containingFile instanceof JetFile) {
|
||||||
result.add(functionDescriptor);
|
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;
|
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.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
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.resolve.lazy.LazyBindingContextUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
import org.jetbrains.jet.plugin.caches.JetCacheManager;
|
import org.jetbrains.jet.plugin.caches.JetCacheManager;
|
||||||
@@ -202,12 +204,12 @@ public class JetCompletionContributor extends CompletionContributor {
|
|||||||
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
|
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
|
||||||
Collection<String> functionNames = namesCache.getAllTopLevelFunctionNames();
|
Collection<String> functionNames = namesCache.getAllTopLevelFunctionNames();
|
||||||
|
|
||||||
BindingContext resolutionContext = WholeProjectAnalyzerFacade.getLazyResolveContext(
|
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) position.getContainingFile());
|
||||||
(JetFile) position.getContainingFile(), expression);
|
BindingContext resolutionContext = LazyBindingContextUtils.getExpressionBindingContext(resolveSession, expression);
|
||||||
|
|
||||||
for (String name : functionNames) {
|
for (String name : functionNames) {
|
||||||
if (name.contains(actualPrefix)) {
|
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);
|
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.LazyBindingContextUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
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
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
@@ -39,12 +36,12 @@ public final class WholeProjectAnalyzerFacade {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static AnalyzeExhaust analyzeProjectWithCacheOnAFile(@NotNull JetFile file) {
|
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
|
@NotNull
|
||||||
public static ResolveSession getLazyResolveSessionForFile(@NotNull JetFile file) {
|
public static ResolveSession getLazyResolveSessionForFile(@NotNull JetFile file) {
|
||||||
return getLazyResolveSession(file);
|
return AnalyzerFacadeWithCache.getLazyResolveSession(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -110,9 +110,11 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
|
|||||||
JetSimpleNameExpression expression,
|
JetSimpleNameExpression expression,
|
||||||
@NotNull Project project) {
|
@NotNull Project project) {
|
||||||
JetShortNamesCache namesCache = JetCacheManager.getInstance(project).getNamesCache();
|
JetShortNamesCache namesCache = JetCacheManager.getInstance(project).getNamesCache();
|
||||||
|
|
||||||
Collection<FunctionDescriptor> topLevelFunctions = namesCache.getTopLevelFunctionDescriptorsByName(
|
Collection<FunctionDescriptor> topLevelFunctions = namesCache.getTopLevelFunctionDescriptorsByName(
|
||||||
referenceName,
|
referenceName,
|
||||||
expression,
|
expression,
|
||||||
|
WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) expression.getContainingFile()),
|
||||||
GlobalSearchScope.allScope(project));
|
GlobalSearchScope.allScope(project));
|
||||||
|
|
||||||
return Sets.newHashSet(Collections2.transform(topLevelFunctions, new Function<DeclarationDescriptor, FqName>() {
|
return Sets.newHashSet(Collections2.transform(topLevelFunctions, new Function<DeclarationDescriptor, FqName>() {
|
||||||
|
|||||||
Reference in New Issue
Block a user