Make additional resolution work for descriptors

This commit is contained in:
Nikolay Krasko
2013-07-12 15:32:01 +04:00
parent 51f690ed4d
commit f8e3275861
4 changed files with 17 additions and 27 deletions
@@ -120,9 +120,6 @@ public class ResolveSessionUtils {
@NotNull ResolveSession resolveSession,
@NotNull JetElement jetElement
) {
// All additional resolve should be done to separate trace
DelegatingBindingTrace trace = new DelegatingBindingTrace(resolveSession.getBindingContext(), "trace to resolve element", jetElement);
@SuppressWarnings("unchecked")
PsiElement resolveElement = JetPsiUtil.getTopmostParentOfTypes(jetElement,
JetNamedFunction.class, JetClassInitializer.class,
@@ -132,6 +129,9 @@ public class ResolveSessionUtils {
JetNamespaceHeader.class);
if (resolveElement != null) {
// All additional resolve should be done to separate trace
DelegatingBindingTrace trace = new DelegatingBindingTrace(resolveSession.getBindingContext(), "trace to resolve element", jetElement);
JetFile file = (JetFile) jetElement.getContainingFile();
if (resolveElement instanceof JetNamedFunction) {
@@ -176,7 +176,13 @@ public class ResolveSessionUtils {
return trace.getBindingContext();
}
return trace.getBindingContext();
JetDeclaration declaration = PsiTreeUtil.getParentOfType(jetElement, JetDeclaration.class, false);
if (declaration != null) {
// Activate descriptor resolution
resolveSession.resolveToDescriptor(declaration);
}
return resolveSession.getBindingContext();
}
private static void namespaceRefAdditionalResolve(
@@ -57,8 +57,6 @@ import org.jetbrains.jet.lang.descriptors.Modality;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.codeInsight.JetFunctionPsiElementCellRenderer;
@@ -238,22 +236,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
if (!(element instanceof JetNamedFunction || element instanceof JetProperty)) return null;
ResolveSession sessionForFile = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile(file);
BindingContext bindingContext;
if ((element instanceof JetNamedFunction && ((JetNamedFunction) element).isLocal()) ||
element instanceof JetProperty && ((JetProperty) element).isLocal()) {
bindingContext = ResolveSessionUtils.resolveToElement(sessionForFile, (JetElement) element);
}
else {
try {
sessionForFile.resolveToDescriptor((JetDeclaration) element);
bindingContext = sessionForFile.getBindingContext();
} catch (IllegalStateException e) {
return null;
}
}
BindingContext bindingContext = WholeProjectAnalyzerFacade.getContextForElement((JetElement) element);
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
if (!(descriptor instanceof CallableMemberDescriptor)) {
@@ -18,7 +18,7 @@ package org.jetbrains.jet.plugin.project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
@@ -39,8 +39,8 @@ public final class WholeProjectAnalyzerFacade {
return AnalyzerFacadeWithCache.getLazyResolveSession(file);
}
public static BindingContext getContextForExpression(@NotNull JetExpression jetExpression) {
ResolveSession resolveSession = getLazyResolveSessionForFile((JetFile) jetExpression.getContainingFile());
return ResolveSessionUtils.resolveToElement(resolveSession, jetExpression);
public static BindingContext getContextForElement(@NotNull JetElement jetElement) {
ResolveSession resolveSession = getLazyResolveSessionForFile((JetFile) jetElement.getContainingFile());
return ResolveSessionUtils.resolveToElement(resolveSession, jetElement);
}
}
@@ -102,7 +102,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
@Nullable
protected PsiElement doResolve() {
BindingContext context = WholeProjectAnalyzerFacade.getContextForExpression(myExpression);
BindingContext context = WholeProjectAnalyzerFacade.getContextForElement(myExpression);
List<PsiElement> psiElements = BindingContextUtils.resolveToDeclarationPsiElements(context, myExpression);
if (psiElements.size() == 1) {
@@ -115,6 +115,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
if (stdlibSymbols.size() == 1) {
return stdlibSymbols.iterator().next();
}
return null;
}