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);
|
||||
|
||||
|
||||
+2
-2
@@ -35,12 +35,12 @@ import org.jetbrains.kotlin.load.java.structure.JavaArrayType
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaConstructor
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
||||
import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.load.java.typeEnhacement.enhanceSignatures
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.Location
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.utils.*
|
||||
@@ -285,7 +285,7 @@ public class LazyJavaClassMemberScope(
|
||||
override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? =
|
||||
DescriptorUtils.getDispatchReceiverParameterIfNeeded(getContainingDeclaration())
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? = nestedClasses(name)
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? = nestedClasses(name)
|
||||
|
||||
override fun getClassNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
|
||||
= nestedClassIndex().keySet() + enumEntryIndex().keySet()
|
||||
|
||||
+10
-6
@@ -16,14 +16,18 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.lazy.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.name.*
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory.*
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory.createEnumValueOfMethod
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory.createEnumValuesMethod
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.Location
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
public class LazyJavaStaticClassScope(
|
||||
c: LazyJavaResolverContext,
|
||||
@@ -54,7 +58,7 @@ public class LazyJavaStaticClassScope(
|
||||
memberIndex().getAllFieldNames()
|
||||
|
||||
override fun getClassNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name> = listOf()
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? = null
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? = null
|
||||
|
||||
override fun getSubPackages(): Collection<FqName> = listOf()
|
||||
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ public class LazyPackageFragmentScopeForJavaPackage(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? = classes(name)
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? = classes(name)
|
||||
|
||||
override fun getProperties(name: Name, location: Location) = deserializedPackageScope().getProperties(name)
|
||||
override fun getFunctions(name: Name, location: Location) = deserializedPackageScope().getFunctions(name) + super.getFunctions(name)
|
||||
|
||||
@@ -237,7 +237,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
private ClassDescriptor getAnnotationClassByName(@NotNull Name simpleName) {
|
||||
ClassifierDescriptor classifier = annotationPackageFragment.getMemberScope().getClassifier(simpleName);
|
||||
ClassifierDescriptor classifier = annotationPackageFragment.getMemberScope().getClassifier(simpleName, UsageLocation.NO_LOCATION);
|
||||
assert classifier instanceof ClassDescriptor : "Must be a class descriptor " + simpleName + ", but was " +
|
||||
(classifier == null ? "null" : classifier.toString());
|
||||
return (ClassDescriptor) classifier;
|
||||
@@ -252,7 +252,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
@Nullable
|
||||
public ClassDescriptor getBuiltInClassByNameNullable(@NotNull Name simpleName) {
|
||||
ClassifierDescriptor classifier = getBuiltInsPackageFragment().getMemberScope().getClassifier(simpleName);
|
||||
ClassifierDescriptor classifier = getBuiltInsPackageFragment().getMemberScope().getClassifier(simpleName, Location.NOWHERE);
|
||||
assert classifier == null ||
|
||||
classifier instanceof ClassDescriptor : "Must be a class descriptor " + simpleName + ", but was " + classifier;
|
||||
return (ClassDescriptor) classifier;
|
||||
@@ -401,7 +401,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
@Nullable
|
||||
public ClassDescriptor getAnnotationTargetEnumEntry(@NotNull Name name) {
|
||||
ClassifierDescriptor result = getAnnotationTargetEnum().getUnsubstitutedInnerClassesScope().getClassifier(name);
|
||||
ClassifierDescriptor result = getAnnotationTargetEnum().getUnsubstitutedInnerClassesScope().getClassifier(name, UsageLocation.NO_LOCATION);
|
||||
return result instanceof ClassDescriptor ? (ClassDescriptor) result : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.kotlin.resolve.scopes.FilteringScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.Location;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.LazyType;
|
||||
@@ -387,7 +388,8 @@ public class DescriptorUtils {
|
||||
|
||||
@Nullable
|
||||
public static ClassDescriptor getInnerClassByName(@NotNull ClassDescriptor classDescriptor, @NotNull String innerClassName) {
|
||||
ClassifierDescriptor classifier = classDescriptor.getDefaultType().getMemberScope().getClassifier(Name.identifier(innerClassName));
|
||||
ClassifierDescriptor classifier =
|
||||
classDescriptor.getDefaultType().getMemberScope().getClassifier(Name.identifier(innerClassName), Location.NOWHERE);
|
||||
assert classifier instanceof ClassDescriptor :
|
||||
"Inner class " + innerClassName + " in " + classDescriptor + " should be instance of ClassDescriptor, but was: "
|
||||
+ (classifier == null ? "null" : classifier.getClass());
|
||||
|
||||
@@ -39,7 +39,7 @@ public abstract class AbstractScopeAdapter : JetScope {
|
||||
return workerScope.getPackage(name)
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
|
||||
return workerScope.getClassifier(name)
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public open class ChainedScope(
|
||||
return result ?: emptySet()
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor?
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor?
|
||||
= getFirstMatch { it.getClassifier(name) }
|
||||
|
||||
override fun getPackage(name: Name): PackageViewDescriptor?
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
|
||||
public class ExplicitImportsScope(private val descriptors: Collection<DeclarationDescriptor>) : JetScopeImpl() {
|
||||
override fun getClassifier(name: Name) = descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<ClassifierDescriptor>()
|
||||
override fun getClassifier(name: Name, location: Location) = descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<ClassifierDescriptor>()
|
||||
|
||||
override fun getPackage(name: Name)= descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<PackageViewDescriptor>()
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class FilteringScope(private val workerScope: JetScope, private val predi
|
||||
|
||||
override fun getPackage(name: Name) = filterDescriptor(workerScope.getPackage(name))
|
||||
|
||||
override fun getClassifier(name: Name) = filterDescriptor(workerScope.getClassifier(name))
|
||||
override fun getClassifier(name: Name, location: Location) = filterDescriptor(workerScope.getClassifier(name))
|
||||
|
||||
override fun getProperties(name: Name, location: Location) = workerScope.getProperties(name).filter(predicate)
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public class InnerClassesScopeWrapper(override val workerScope: JetScope) : AbstractScopeAdapter() {
|
||||
override fun getClassifier(name: Name) = workerScope.getClassifier(name) as? ClassDescriptor
|
||||
override fun getClassifier(name: Name, location: Location) = workerScope.getClassifier(name) as? ClassDescriptor
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = workerScope.getDeclarationsByLabel(labelName).filterIsInstance<ClassDescriptor>()
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.lang.reflect.Modifier
|
||||
|
||||
public interface JetScope {
|
||||
|
||||
public fun getClassifier(name: Name): ClassifierDescriptor?
|
||||
public fun getClassifier(name: Name, location: Location = Location.NOWHERE): ClassifierDescriptor?
|
||||
|
||||
public fun getPackage(name: Name): PackageViewDescriptor?
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
public abstract class JetScopeImpl : JetScope {
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? = null
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? = null
|
||||
|
||||
override fun getProperties(name: Name, location: Location): Collection<VariableDescriptor> = setOf()
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import java.util.ArrayList
|
||||
public class StaticScopeForKotlinClass(
|
||||
private val containingClass: ClassDescriptor
|
||||
) : JetScopeImpl() {
|
||||
override fun getClassifier(name: Name) = null // TODO
|
||||
override fun getClassifier(name: Name, location: Location) = null // TODO
|
||||
|
||||
private val functions: List<FunctionDescriptor> by lazy {
|
||||
if (containingClass.getKind() != ClassKind.ENUM_CLASS) {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class SubstitutingScope(private val workerScope: JetScope, private val su
|
||||
|
||||
override fun getLocalVariable(name: Name) = substitute(workerScope.getLocalVariable(name))
|
||||
|
||||
override fun getClassifier(name: Name) = substitute(workerScope.getClassifier(name))
|
||||
override fun getClassifier(name: Name, location: Location) = substitute(workerScope.getClassifier(name))
|
||||
|
||||
override fun getFunctions(name: Name, location: Location) = substitute(workerScope.getFunctions(name))
|
||||
|
||||
|
||||
@@ -81,8 +81,9 @@ public class ErrorUtils {
|
||||
this.debugMessage = debugMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name, @NotNull Location location) {
|
||||
return createErrorClass(name.asString());
|
||||
}
|
||||
|
||||
@@ -180,7 +181,7 @@ public class ErrorUtils {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
||||
public ClassifierDescriptor getClassifier(@NotNull Name name, @NotNull Location location) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ public abstract class DeserializedMemberScope protected constructor(
|
||||
|
||||
override fun getProperties(name: Name, location: Location): Collection<VariableDescriptor> = properties.invoke(name)
|
||||
|
||||
override fun getClassifier(name: Name) = getClassDescriptor(name)
|
||||
override fun getClassifier(name: Name, location: Location) = getClassDescriptor(name)
|
||||
|
||||
protected abstract fun getClassDescriptor(name: Name): ClassifierDescriptor?
|
||||
|
||||
|
||||
@@ -88,4 +88,4 @@ public fun JetType.approximateWithResolvableType(scope: JetScope?, checkTypePara
|
||||
if (isError() || isResolvableInScope(scope, checkTypeParameters)) return this
|
||||
return supertypes().firstOrNull { it.isResolvableInScope(scope, checkTypeParameters) }
|
||||
?: KotlinBuiltIns.getInstance().getAnyType()
|
||||
}
|
||||
}
|
||||
|
||||
+11
-10
@@ -16,20 +16,21 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.error.MissingDependencyErrorClass
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.TypeProjection
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.scopes.Location
|
||||
import org.jetbrains.kotlin.types.ErrorUtils.createErrorType
|
||||
import org.jetbrains.kotlin.types.TypeProjection
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.error.MissingDependencyErrorClass
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
private class PackageFragmentWithMissingDependencies(override val fqName: FqName, moduleDescriptor: ModuleDescriptor) :
|
||||
PackageFragmentDescriptorImpl(moduleDescriptor, fqName) {
|
||||
@@ -47,7 +48,7 @@ private class ScopeWithMissingDependencies(val fqName: FqName, val containing: D
|
||||
p.println("Special scope for decompiler, containing class with any name")
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
||||
override fun getClassifier(name: Name, location: Location): ClassifierDescriptor? {
|
||||
return MissingDependencyErrorClassDescriptor(getContainingDeclaration(), fqName.child(name))
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.Location
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.SubstitutionUtils
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
@@ -109,6 +110,6 @@ public object HeuristicSignatures {
|
||||
private class TypeParametersScope(params: Collection<TypeParameterDescriptor>) : JetScope by JetScope.Empty {
|
||||
private val paramsByName = params.map { it.getName() to it }.toMap()
|
||||
|
||||
override fun getClassifier(name: Name) = paramsByName[name]
|
||||
override fun getClassifier(name: Name, location: Location) = paramsByName[name]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -246,4 +246,4 @@ private fun TypePredicate.getRepresentativeTypes(): Set<JetType> {
|
||||
is AllTypes -> emptySet()
|
||||
else -> throw AssertionError("Invalid type predicate: ${this}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user