From bdd834604aebeef8defc2ad9691ebcd17e1e1f08 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 18 Aug 2015 22:34:05 +0300 Subject: [PATCH] Add lacation parameter to ModuleDescriptor.resolveTopLevelClass (in DescriptorUtils.kt) --- .../compiler/AbstractSdkAnnotationsValidityTest.java | 3 ++- .../ResolveDescriptorsFromExternalLibraries.java | 3 ++- .../kotlin/resolve/JetExpectedResolveDataUtil.java | 3 ++- .../lazy/descriptors/LazyJavaAnnotationDescriptor.kt | 3 ++- .../kotlin/incremental/components/LookupLocation.kt | 3 ++- .../org/jetbrains/kotlin/resolve/DescriptorUtils.kt | 5 +++-- .../idea/completion/smart/TypeInstantiationItems.kt | 2 +- .../createFromUsage/callableBuilder/typeUtils.kt | 11 ++++++----- .../extractionEngine/ExtractableCodeDescriptor.kt | 5 +++-- .../decompiler/textBuilder/TextConsistencyBaseTest.kt | 3 ++- 10 files changed, 25 insertions(+), 16 deletions(-) diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractSdkAnnotationsValidityTest.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractSdkAnnotationsValidityTest.java index beb3abe66b9..2aba1a53aa9 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractSdkAnnotationsValidityTest.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractSdkAnnotationsValidityTest.java @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies; +import org.jetbrains.kotlin.incremental.components.NoLookupLocation; import org.jetbrains.kotlin.load.java.JavaBindingContext; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.platform.JavaToKotlinClassMap; @@ -85,7 +86,7 @@ public abstract class AbstractSdkAnnotationsValidityTest extends UsefulTestCase int chunkStart = chunkIndex * CLASSES_IN_CHUNK; for (FqName javaClass : affectedClasses.subList(chunkStart, Math.min(chunkStart + CLASSES_IN_CHUNK, affectedClasses.size()))) { - ClassDescriptor topLevelClass = resolveTopLevelClass(module, javaClass); + ClassDescriptor topLevelClass = resolveTopLevelClass(module, javaClass, NoLookupLocation.FROM_TEST); PackageViewDescriptor topLevelPackage = module.getPackage(javaClass); if (topLevelClass == null) { continue; diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/longTest/ResolveDescriptorsFromExternalLibraries.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/longTest/ResolveDescriptorsFromExternalLibraries.java index 4dfffe96de7..06a9639b0e9 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/longTest/ResolveDescriptorsFromExternalLibraries.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/longTest/ResolveDescriptorsFromExternalLibraries.java @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.config.CompilerConfiguration; import org.jetbrains.kotlin.descriptors.ClassDescriptor; import org.jetbrains.kotlin.descriptors.ModuleDescriptor; +import org.jetbrains.kotlin.incremental.components.NoLookupLocation; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil; import org.jetbrains.kotlin.test.ConfigurationKind; @@ -209,7 +210,7 @@ public class ResolveDescriptorsFromExternalLibraries { String className = entryName.substring(0, entryName.length() - ".class".length()).replace("/", "."); try { - ClassDescriptor clazz = resolveTopLevelClass(module, new FqName(className)); + ClassDescriptor clazz = resolveTopLevelClass(module, new FqName(className), NoLookupLocation.FROM_TEST); if (clazz == null) { throw new IllegalStateException("class not found by name " + className + " in " + libDescription); } diff --git a/compiler/tests/org/jetbrains/kotlin/resolve/JetExpectedResolveDataUtil.java b/compiler/tests/org/jetbrains/kotlin/resolve/JetExpectedResolveDataUtil.java index 6eb83adf546..a8f72dd4d72 100644 --- a/compiler/tests/org/jetbrains/kotlin/resolve/JetExpectedResolveDataUtil.java +++ b/compiler/tests/org/jetbrains/kotlin/resolve/JetExpectedResolveDataUtil.java @@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl; +import org.jetbrains.kotlin.incremental.components.NoLookupLocation; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; @@ -113,7 +114,7 @@ public class JetExpectedResolveDataUtil { @NotNull private static PsiClass findClass(String qualifiedName, Project project) { ModuleDescriptor module = LazyResolveTestUtil.resolveProject(project); - ClassDescriptor classDescriptor = DescriptorUtilPackage.resolveTopLevelClass(module, new FqName(qualifiedName)); + ClassDescriptor classDescriptor = DescriptorUtilPackage.resolveTopLevelClass(module, new FqName(qualifiedName), NoLookupLocation.FROM_TEST); assertNotNull("Class descriptor wasn't resolved: " + qualifiedName, classDescriptor); PsiClass psiClass = (PsiClass) DescriptorToSourceUtils.getSourceFromDescriptor(classDescriptor); assertNotNull("Class declaration wasn't found: " + classDescriptor, psiClass); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt index 5e6c746c48a..fc8a167f718 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.load.java.JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME import org.jetbrains.kotlin.load.java.JvmAnnotationNames.isSpecialAnnotation import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils @@ -141,7 +142,7 @@ class LazyJavaAnnotationDescriptor( TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes(allowFlexible = false)) ) - val jlClass = c.module.resolveTopLevelClass(FqName("java.lang.Class")) ?: return null + val jlClass = c.module.resolveTopLevelClass(FqName("java.lang.Class"), NoLookupLocation.FOR_NON_TRACKED_SCOPE) ?: return null val arguments = listOf(TypeProjectionImpl(type)) diff --git a/core/descriptors/src/org/jetbrains/kotlin/incremental/components/LookupLocation.kt b/core/descriptors/src/org/jetbrains/kotlin/incremental/components/LookupLocation.kt index c884f696816..f23d700bff9 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/incremental/components/LookupLocation.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/incremental/components/LookupLocation.kt @@ -35,5 +35,6 @@ public enum class NoLookupLocation : LookupLocation { // TODO replace with real location (e.g. FROM_IDE) where it possible WHEN_GET_ALL_DESCRIPTORS, WHEN_TYPING, - WHEN_GET_SUPER_MEMBERS + WHEN_GET_SUPER_MEMBERS, + FOR_NON_TRACKED_SCOPE } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt index 59fc1b7bf0a..a2f43cf7bb5 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind.ENUM_ENTRY import org.jetbrains.kotlin.descriptors.ClassKind.OBJECT import org.jetbrains.kotlin.descriptors.annotations.Annotated import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqNameUnsafe @@ -54,9 +55,9 @@ public val DeclarationDescriptor.isExtension: Boolean public val DeclarationDescriptor.module: ModuleDescriptor get() = DescriptorUtils.getContainingModule(this) -public fun ModuleDescriptor.resolveTopLevelClass(topLevelClassFqName: FqName): ClassDescriptor? { +public fun ModuleDescriptor.resolveTopLevelClass(topLevelClassFqName: FqName, location: LookupLocation): ClassDescriptor? { assert(!topLevelClassFqName.isRoot()) - return getPackage(topLevelClassFqName.parent()).memberScope.getClassifier(topLevelClassFqName.shortName()) as? ClassDescriptor + return getPackage(topLevelClassFqName.parent()).memberScope.getClassifier(topLevelClassFqName.shortName(), location) as? ClassDescriptor } public val ClassDescriptor.classId: ClassId diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt index b583e932601..beba4cc3fe2 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt @@ -94,7 +94,7 @@ class TypeInstantiationItems( val javaClassId = JavaToKotlinClassMap.INSTANCE.mapKotlinToJava(DescriptorUtils.getFqName(classifier)) if (javaClassId != null) { - val javaAnalog = resolutionFacade.moduleDescriptor.resolveTopLevelClass(javaClassId.asSingleFqName()) + val javaAnalog = resolutionFacade.moduleDescriptor.resolveTopLevelClass(javaClassId.asSingleFqName(), NoLookupLocation.FROM_IDE) if (javaAnalog != null) { inheritanceSearchers.addInheritorSearcher(javaAnalog, classifier, typeArgs, tail) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt index 9c25872225d..036e407df55 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt @@ -19,7 +19,10 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder import com.intellij.refactoring.psi.SearchUtils import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.cfg.pseudocode.* -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.ModuleDescriptor +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.idea.references.JetSimpleNameReference import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.FqName @@ -35,9 +38,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.JetTypeChecker import org.jetbrains.kotlin.types.typeUtil.makeNotNullable -import java.util.Collections -import java.util.HashSet -import java.util.LinkedHashSet +import java.util.* private fun JetType.contains(inner: JetType): Boolean { return JetTypeChecker.DEFAULT.equalTypes(this, inner) || getArguments().any { inner in it.getType() } @@ -170,7 +171,7 @@ fun JetExpression.guessTypes( parent is JetPropertyDelegate -> { val variableDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, parent.getParent() as JetProperty] as VariableDescriptor val delegateClassName = if (variableDescriptor.isVar()) "ReadWriteProperty" else "ReadOnlyProperty" - val delegateClass = module.resolveTopLevelClass(FqName("kotlin.properties.$delegateClassName")) + val delegateClass = module.resolveTopLevelClass(FqName("kotlin.properties.$delegateClassName"), NoLookupLocation.FROM_IDE) ?: return arrayOf(module.builtIns.getAnyType()) val receiverType = (variableDescriptor.getExtensionReceiverParameter() ?: variableDescriptor.getDispatchReceiverParameter())?.getType() ?: module.builtIns.getNullableNothingType() diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt index 3a6fa1e3664..a5af7ca591e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.idea.util.approximateFlexibleTypes import org.jetbrains.kotlin.idea.util.isAnnotatedNotNull import org.jetbrains.kotlin.idea.util.isAnnotatedNullable import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange +import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector @@ -208,8 +209,8 @@ abstract class OutputValueBoxer(val outputValues: List) { fun getType(): JetType { val boxingClass = when (outputValues.size()) { 1 -> return outputValues.first().valueType - 2 -> module.resolveTopLevelClass(FqName("kotlin.Pair"))!! - 3 -> module.resolveTopLevelClass(FqName("kotlin.Triple"))!! + 2 -> module.resolveTopLevelClass(FqName("kotlin.Pair"), NoLookupLocation.FROM_IDE)!! + 3 -> module.resolveTopLevelClass(FqName("kotlin.Triple"), NoLookupLocation.FROM_IDE)!! else -> return DEFAULT_RETURN_TYPE } return TypeUtils.substituteParameters(boxingClass, outputValueTypes) diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/TextConsistencyBaseTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/TextConsistencyBaseTest.kt index a9f202f4dc6..d081e644a41 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/TextConsistencyBaseTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/TextConsistencyBaseTest.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.load.kotlin.PackageClassUtils import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder import org.jetbrains.kotlin.name.ClassId @@ -63,7 +64,7 @@ public abstract class TextConsistencyBaseTest : JetLightCodeInsightFixtureTestCa private class ResolverForDecompilerImpl(val module: ModuleDescriptor) : ResolverForDecompiler { override fun resolveTopLevelClass(classId: ClassId): ClassDescriptor? { - return module.resolveTopLevelClass(classId.asSingleFqName()) + return module.resolveTopLevelClass(classId.asSingleFqName(), NoLookupLocation.FROM_TEST) } override fun resolveDeclarationsInPackage(packageFqName: FqName): Collection {