stdlib reference might be multi
(for fake reference defined in several super traits)
This commit is contained in:
@@ -103,19 +103,19 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
|
||||
protected PsiElement doResolve() {
|
||||
JetFile file = (JetFile) getElement().getContainingFile();
|
||||
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file).getBindingContext();
|
||||
List<PsiElement> psiElement = BindingContextUtils.resolveToDeclarationPsiElements(bindingContext, myExpression);
|
||||
if (psiElement.size() == 1) {
|
||||
return psiElement.iterator().next();
|
||||
List<PsiElement> psiElements = BindingContextUtils.resolveToDeclarationPsiElements(bindingContext, myExpression);
|
||||
if (psiElements.size() == 1) {
|
||||
return psiElements.iterator().next();
|
||||
}
|
||||
if (psiElement.size() > 1) {
|
||||
if (psiElements.size() > 1) {
|
||||
return null;
|
||||
}
|
||||
if (psiElement.isEmpty()) {
|
||||
PsiElement stdlibSymbol = myExpression.getProject().getComponent(StandardLibraryReferenceResolver.class)
|
||||
.resolveStandardLibrarySymbol(bindingContext, myExpression);
|
||||
if (stdlibSymbol != null) {
|
||||
return stdlibSymbol;
|
||||
}
|
||||
List<PsiElement> stdlibSymbols = resolveStandardLibrarySymbol(bindingContext);
|
||||
if (stdlibSymbols.size() == 1) {
|
||||
return stdlibSymbols.iterator().next();
|
||||
}
|
||||
if (stdlibSymbols.size() > 1) {
|
||||
return null;
|
||||
}
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
|
||||
if (declarationDescriptors != null) return null;
|
||||
@@ -129,10 +129,16 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
|
||||
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file)
|
||||
.getBindingContext();
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
|
||||
if (declarationDescriptors == null) return ResolveResult.EMPTY_ARRAY;
|
||||
if (declarationDescriptors == null) {
|
||||
List<PsiElement> standardLibraryElements = resolveStandardLibrarySymbol(bindingContext);
|
||||
if (!standardLibraryElements.isEmpty()) {
|
||||
return PsiElementResolveResult.createResults(standardLibraryElements);
|
||||
}
|
||||
return ResolveResult.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
List<ResolveResult> results = new ArrayList<ResolveResult>(declarationDescriptors.size());
|
||||
|
||||
ArrayList<ResolveResult> results = new ArrayList<ResolveResult>(declarationDescriptors.size());
|
||||
|
||||
for (DeclarationDescriptor descriptor : declarationDescriptors) {
|
||||
List<PsiElement> elements = BindingContextUtils.descriptorToDeclarations(bindingContext, descriptor);
|
||||
if (elements.isEmpty()) {
|
||||
@@ -149,4 +155,9 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
|
||||
|
||||
return results.toArray(new ResolveResult[results.size()]);
|
||||
}
|
||||
|
||||
private List<PsiElement> resolveStandardLibrarySymbol(@NotNull BindingContext bindingContext) {
|
||||
return myExpression.getProject().getComponent(StandardLibraryReferenceResolver.class)
|
||||
.resolveStandardLibrarySymbol(bindingContext, myExpression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,26 +157,26 @@ public class StandardLibraryReferenceResolver extends AbstractProjectComponent {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement resolveStandardLibrarySymbol(@NotNull BindingContext originalContext,
|
||||
@NotNull
|
||||
public List<PsiElement> resolveStandardLibrarySymbol(@NotNull BindingContext originalContext,
|
||||
@Nullable JetReferenceExpression referenceExpression) {
|
||||
ensureInitialized();
|
||||
DeclarationDescriptor declarationDescriptor = originalContext.get(BindingContext.REFERENCE_TARGET, referenceExpression);
|
||||
|
||||
return declarationDescriptor != null ? resolveStandardLibrarySymbol(declarationDescriptor) : null;
|
||||
return declarationDescriptor != null ? resolveStandardLibrarySymbol(declarationDescriptor) : Collections.<PsiElement>emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement resolveStandardLibrarySymbol(@NotNull DeclarationDescriptor declarationDescriptor) {
|
||||
@NotNull
|
||||
public List<PsiElement> resolveStandardLibrarySymbol(@NotNull DeclarationDescriptor declarationDescriptor) {
|
||||
ensureInitialized();
|
||||
DeclarationDescriptor descriptor = declarationDescriptor;
|
||||
|
||||
descriptor = descriptor.getOriginal();
|
||||
descriptor = findCurrentDescriptor(descriptor);
|
||||
if (descriptor != null) {
|
||||
return BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||
return BindingContextUtils.descriptorToDeclarations(bindingContext, descriptor);
|
||||
}
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user