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
|
||||
|
||||
+2
-2
@@ -206,7 +206,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
||||
@NotNull
|
||||
protected static ClassDescriptor getClassDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
|
||||
Name className = Name.identifier(name);
|
||||
ClassifierDescriptor aClass = packageView.getMemberScope().getClassifier(className);
|
||||
ClassifierDescriptor aClass = packageView.getMemberScope().getClassifier(className, Location.NOWHERE);
|
||||
assertNotNull("Failed to find class: " + packageView.getName() + "." + className, aClass);
|
||||
assert aClass instanceof ClassDescriptor : "Not a class: " + aClass;
|
||||
return (ClassDescriptor) aClass;
|
||||
@@ -216,7 +216,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
||||
private static ClassDescriptor getInnerClassDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
|
||||
Name propertyName = Name.identifier(name);
|
||||
JetScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
|
||||
ClassifierDescriptor innerClass = memberScope.getClassifier(propertyName);
|
||||
ClassifierDescriptor innerClass = memberScope.getClassifier(propertyName, Location.NOWHERE);
|
||||
assert innerClass instanceof ClassDescriptor : "Failed to find inner class " +
|
||||
propertyName +
|
||||
" in class " +
|
||||
|
||||
@@ -426,7 +426,7 @@ public class DescriptorValidator {
|
||||
public Void visitTypeParameterDescriptor(
|
||||
TypeParameterDescriptor descriptor, JetScope scope
|
||||
) {
|
||||
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName()), true);
|
||||
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), Location.NOWHERE), true);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ public class DescriptorValidator {
|
||||
public Void visitClassDescriptor(
|
||||
ClassDescriptor descriptor, JetScope scope
|
||||
) {
|
||||
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName()), true);
|
||||
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), Location.NOWHERE), true);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -623,7 +623,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
else {
|
||||
Name shortName = fqName.shortName();
|
||||
assert shortName.equals(defaultImport.getImportedName());
|
||||
writableScope.addClassifierDescriptor(module.getPackage(fqName.parent()).getMemberScope().getClassifier(shortName));
|
||||
writableScope.addClassifierDescriptor(module.getPackage(fqName.parent()).getMemberScope().getClassifier(shortName, Location.NOWHERE));
|
||||
}
|
||||
}
|
||||
scopeChain.add(module.getPackage(FqName.ROOT).getMemberScope());
|
||||
|
||||
@@ -85,7 +85,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
JetFile jetFile = JetPsiFactory(getProject()).createFile(text);
|
||||
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment());
|
||||
JetScope topLevelDeclarations = module.getPackage(FqName.ROOT).getMemberScope();
|
||||
ClassifierDescriptor contextClass = topLevelDeclarations.getClassifier(Name.identifier("___Context"));
|
||||
ClassifierDescriptor contextClass = topLevelDeclarations.getClassifier(Name.identifier("___Context"), Location.NOWHERE);
|
||||
assert contextClass instanceof ClassDescriptor;
|
||||
WritableScopeImpl typeParameters = new WritableScopeImpl(JetScope.Empty.INSTANCE$, module, RedeclarationHandler.THROW_EXCEPTION,
|
||||
"Type parameter scope");
|
||||
@@ -124,7 +124,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
String typeParameterName = pair.first;
|
||||
String replacementProjectionString = pair.second;
|
||||
|
||||
ClassifierDescriptor classifier = scope.getClassifier(Name.identifier(typeParameterName));
|
||||
ClassifierDescriptor classifier = scope.getClassifier(Name.identifier(typeParameterName), Location.NOWHERE);
|
||||
assertNotNull("No type parameter named " + typeParameterName, classifier);
|
||||
assertTrue(typeParameterName + " is not a type parameter: " + classifier, classifier instanceof TypeParameterDescriptor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user