Use member scope for declaration instead resolution scope in LazyDeclarationResolver
This commit is contained in:
+14
-7
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.storage.LockBasedLazyResolveStorageManager;
|
||||
@@ -64,13 +65,13 @@ public class LazyDeclarationResolver {
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getClassDescriptor(@NotNull JetClassOrObject classOrObject) {
|
||||
JetScope resolutionScope = resolutionScopeToResolveDeclaration(classOrObject);
|
||||
JetScope scope = getMemberScopeDeclaredIn(classOrObject);
|
||||
|
||||
// Why not use the result here. Because it may be that there is a redeclaration:
|
||||
// class A {} class A { fun foo(): A<completion here>}
|
||||
// and if we find the class by name only, we may b-not get the right one.
|
||||
// This call is only needed to make sure the classes are written to trace
|
||||
ClassifierDescriptor scopeDescriptor = resolutionScope.getClassifier(classOrObject.getNameAsSafeName(), NoLookupLocation.UNSORTED);
|
||||
ClassifierDescriptor scopeDescriptor = scope.getClassifier(classOrObject.getNameAsSafeName(), NoLookupLocation.UNSORTED);
|
||||
DeclarationDescriptor descriptor = getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, classOrObject);
|
||||
|
||||
if (descriptor == null) {
|
||||
@@ -133,7 +134,7 @@ public class LazyDeclarationResolver {
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor visitNamedFunction(@NotNull JetNamedFunction function, Void data) {
|
||||
JetScope scopeForDeclaration = resolutionScopeToResolveDeclaration(function);
|
||||
JetScope scopeForDeclaration = getMemberScopeDeclaredIn(function);
|
||||
scopeForDeclaration.getFunctions(function.getNameAsSafeName(), NoLookupLocation.UNSORTED);
|
||||
return getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, function);
|
||||
}
|
||||
@@ -188,7 +189,7 @@ public class LazyDeclarationResolver {
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor visitProperty(@NotNull JetProperty property, Void data) {
|
||||
JetScope scopeForDeclaration = resolutionScopeToResolveDeclaration(property);
|
||||
JetScope scopeForDeclaration = getMemberScopeDeclaredIn(property);
|
||||
scopeForDeclaration.getProperties(property.getNameAsSafeName(), NoLookupLocation.UNSORTED);
|
||||
return getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, property);
|
||||
}
|
||||
@@ -212,8 +213,9 @@ public class LazyDeclarationResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/*package*/ JetScope resolutionScopeToResolveDeclaration(@NotNull JetDeclaration declaration) {
|
||||
boolean isTopLevel = JetStubbedPsiUtil.getContainingDeclaration(declaration) == null;
|
||||
/*package*/ JetScope getMemberScopeDeclaredIn(@NotNull JetDeclaration declaration) {
|
||||
JetDeclaration parentDeclaration = JetStubbedPsiUtil.getContainingDeclaration(declaration);
|
||||
boolean isTopLevel = parentDeclaration == null;
|
||||
if (isTopLevel) { // for top level declarations we search directly in package because of possible conflicts with imports
|
||||
FqName fqName = ((JetFile) declaration.getContainingFile()).getPackageFqName();
|
||||
LazyPackageDescriptor packageDescriptor = topLevelDescriptorProvider.getPackageFragment(fqName);
|
||||
@@ -221,7 +223,12 @@ public class LazyDeclarationResolver {
|
||||
return packageDescriptor.getMemberScope();
|
||||
}
|
||||
else {
|
||||
return scopeProvider.getResolutionScopeForDeclaration(declaration);
|
||||
if (parentDeclaration instanceof JetClassOrObject) {
|
||||
return getClassDescriptor((JetClassOrObject) parentDeclaration).getUnsubstitutedMemberScope();
|
||||
} else {
|
||||
throw new IllegalStateException("Don't call this method for local declarations: " + declaration + "\n" +
|
||||
PsiUtilPackage.getElementTextWithContext(declaration));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,9 +287,9 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getClassDescriptorForScript(@NotNull JetScript script) {
|
||||
JetScope resolutionScope = lazyDeclarationResolver.resolutionScopeToResolveDeclaration(script);
|
||||
JetScope memberScope = lazyDeclarationResolver.getMemberScopeDeclaredIn(script);
|
||||
FqName fqName = ScriptNameUtil.classNameForScript(script);
|
||||
ClassifierDescriptor classifier = resolutionScope.getClassifier(fqName.shortName(), NoLookupLocation.FOR_SCRIPT);
|
||||
ClassifierDescriptor classifier = memberScope.getClassifier(fqName.shortName(), NoLookupLocation.FOR_SCRIPT);
|
||||
assert classifier != null : "No descriptor for " + fqName + " in file " + script.getContainingFile();
|
||||
return (ClassDescriptor) classifier;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user