Add location parameter to JetScope::getClassifier
This commit is contained in:
@@ -42,7 +42,7 @@ class AllUnderImportsScope : JetScope {
|
||||
return scopes.flatMap { it.getDescriptors(kindFilter, nameFilter) }
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
|
||||
return scopes.asSequence().map { it.getClassifier(name) }.filterNotNull().singleOrNull()
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,7 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsPackage;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils;
|
||||
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.kotlin.resolve.scopes.*;
|
||||
import org.jetbrains.kotlin.storage.StorageManager;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
@@ -528,7 +525,7 @@ public class DescriptorResolver {
|
||||
|
||||
Name name = nameExpression.getReferencedNameAsName();
|
||||
|
||||
ClassifierDescriptor classifier = scope.getClassifier(name);
|
||||
ClassifierDescriptor classifier = scope.getClassifier(name, Location.NOWHERE);
|
||||
if (classifier instanceof TypeParameterDescriptor && classifier.getContainingDeclaration() == descriptor) continue;
|
||||
|
||||
if (classifier != null) {
|
||||
|
||||
@@ -228,7 +228,7 @@ public class QualifiedExpressionResolver {
|
||||
descriptors.add(packageDescriptor);
|
||||
}
|
||||
|
||||
ClassifierDescriptor classifierDescriptor = outerScope.getClassifier(referencedName);
|
||||
ClassifierDescriptor classifierDescriptor = outerScope.getClassifier(referencedName, Location.NOWHERE);
|
||||
if (classifierDescriptor != null) {
|
||||
descriptors.add(classifierDescriptor);
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.resolve.scopes.Location
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
class SingleImportScope(private val aliasName: Name, private val descriptors: Collection<DeclarationDescriptor>) : JetScopeImpl() {
|
||||
override fun getClassifier(name: Name)
|
||||
override fun getClassifier(name: Name, location: Location)
|
||||
= if (name == aliasName) descriptors.filterIsInstance<ClassifierDescriptor>().singleOrNull() else null
|
||||
|
||||
override fun getPackage(name: Name)
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ public class LazyDeclarationResolver {
|
||||
// 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());
|
||||
ClassifierDescriptor scopeDescriptor = resolutionScope.getClassifier(classOrObject.getNameAsSafeName(), Location.NOWHERE);
|
||||
DeclarationDescriptor descriptor = getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, classOrObject);
|
||||
|
||||
if (descriptor == null) {
|
||||
|
||||
@@ -234,7 +234,7 @@ class LazyImportScope(
|
||||
return Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, importResolver.moduleDescriptor) == includeVisible
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
|
||||
return importResolver.selectSingleFromImports(name, LookupMode.ONLY_CLASSES_AND_PACKAGES) { scope, name ->
|
||||
val descriptor = scope.getClassifier(name)
|
||||
if (descriptor != null && isClassVisible(descriptor as ClassDescriptor/*no type parameter can be imported*/)) descriptor else null
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationsContextImpl;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyScriptDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.Location;
|
||||
import org.jetbrains.kotlin.storage.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -281,7 +282,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
public ClassDescriptor getClassDescriptorForScript(@NotNull JetScript script) {
|
||||
JetScope resolutionScope = lazyDeclarationResolver.resolutionScopeToResolveDeclaration(script);
|
||||
FqName fqName = ScriptNameUtil.classNameForScript(script);
|
||||
ClassifierDescriptor classifier = resolutionScope.getClassifier(fqName.shortName());
|
||||
ClassifierDescriptor classifier = resolutionScope.getClassifier(fqName.shortName(), Location.NOWHERE);
|
||||
assert classifier != null : "No descriptor for " + fqName + " in file " + script.getContainingFile();
|
||||
return (ClassDescriptor) classifier;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetNamedDeclarationUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -83,7 +84,7 @@ public class ResolveSessionUtils {
|
||||
|
||||
JetScope scope = outerScope;
|
||||
for (Name name : path.pathSegments()) {
|
||||
ClassifierDescriptor classifier = scope.getClassifier(name);
|
||||
ClassifierDescriptor classifier = scope.getClassifier(name, Location.NOWHERE);
|
||||
if (!(classifier instanceof ClassDescriptor)) return null;
|
||||
scope = ((ClassDescriptor) classifier).getUnsubstitutedInnerClassesScope();
|
||||
}
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ protected constructor(
|
||||
|
||||
override fun getContainingDeclaration() = thisDescriptor
|
||||
|
||||
override fun getClassifier(name: Name): ClassDescriptor? = classDescriptors(name).firstOrNull()
|
||||
override fun getClassifier(name: Name, location: Location): ClassDescriptor? = classDescriptors(name).firstOrNull()
|
||||
|
||||
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> = functionDescriptors(name)
|
||||
|
||||
|
||||
+1
-1
@@ -349,7 +349,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
Name name = ((JetClassOrObjectInfo) companionObjectInfo).getName();
|
||||
assert name != null;
|
||||
getUnsubstitutedMemberScope().getClassifier(name);
|
||||
getUnsubstitutedMemberScope().getClassifier(name, Location.NOWHERE);
|
||||
ClassDescriptor companionObjectDescriptor = c.getTrace().get(BindingContext.CLASS, companionObject);
|
||||
if (companionObjectDescriptor instanceof LazyClassDescriptor) {
|
||||
assert DescriptorUtils.isCompanionObject(companionObjectDescriptor) : "Not a companion object: " + companionObjectDescriptor;
|
||||
|
||||
@@ -166,7 +166,7 @@ public class WritableScopeImpl @jvmOverloads constructor(
|
||||
addVariableOrClassDescriptor(classifierDescriptor)
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
|
||||
checkMayRead()
|
||||
|
||||
return variableOrClassDescriptorByName(name) as? ClassifierDescriptor
|
||||
@@ -276,7 +276,7 @@ public class WritableScopeImpl @jvmOverloads constructor(
|
||||
return concatInOrder(functionsByName(name, descriptorLimit), workerScope.getFunctions(name))
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
|
||||
checkMayRead()
|
||||
|
||||
return variableOrClassDescriptorByName(name, descriptorLimit) as? ClassifierDescriptor
|
||||
|
||||
Reference in New Issue
Block a user