LookupLocation.NO_LOCATION_FROM_IDE -> NoLookupLocation.FROM_IDE

This commit is contained in:
Zalim Bashorov
2015-08-17 20:51:51 +03:00
parent bcacef7bb9
commit 595975a66e
23 changed files with 69 additions and 69 deletions
@@ -16,14 +16,11 @@
package org.jetbrains.kotlin.incremental.components package org.jetbrains.kotlin.incremental.components
import kotlin.platform.platformStatic
public interface LookupLocation { public interface LookupLocation {
companion object { companion object {
@deprecated("Use more suitable constant if possible") @deprecated("Use more suitable constant if possible")
val NO_LOCATION = NoLookupLocation.UNSORTED val NO_LOCATION = NoLookupLocation.UNSORTED
val NO_LOCATION_FROM_IDE = NoLookupLocation.FROM_IDE
val NO_LOCATION_FROM_BACKEND = NoLookupLocation.FROM_BACKEND val NO_LOCATION_FROM_BACKEND = NoLookupLocation.FROM_BACKEND
val NO_LOCATION_FROM_TEST = NoLookupLocation.FROM_TEST val NO_LOCATION_FROM_TEST = NoLookupLocation.FROM_TEST
} }
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION
@@ -82,7 +82,7 @@ fun JetType.isResolvableInScope(scope: JetScope?, checkTypeParameters: Boolean):
if (descriptor == null || descriptor.getName().isSpecial()) return false if (descriptor == null || descriptor.getName().isSpecial()) return false
if (!checkTypeParameters && descriptor is TypeParameterDescriptor) return true if (!checkTypeParameters && descriptor is TypeParameterDescriptor) return true
return scope != null && scope.getClassifier(descriptor.name, LookupLocation.NO_LOCATION_FROM_IDE) == descriptor return scope != null && scope.getClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor
} }
public fun JetType.approximateWithResolvableType(scope: JetScope?, checkTypeParameters: Boolean): JetType { public fun JetType.approximateWithResolvableType(scope: JetScope?, checkTypeParameters: Boolean): JetType {
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.idea.stubindex.JetFullClassNameIndex;
import org.jetbrains.kotlin.idea.stubindex.JetTopLevelClassByPackageIndex; import org.jetbrains.kotlin.idea.stubindex.JetTopLevelClassByPackageIndex;
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil; import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil;
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil; import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils; import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
@@ -60,7 +61,6 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil; import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer; import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer;
import org.jetbrains.kotlin.resolve.scopes.JetScope; import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.incremental.components.LookupLocation;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
@@ -140,7 +140,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
if (declaration instanceof JetFunction) { if (declaration instanceof JetFunction) {
JetFunction jetFunction = (JetFunction) declaration; JetFunction jetFunction = (JetFunction) declaration;
Name name = jetFunction.getNameAsSafeName(); Name name = jetFunction.getNameAsSafeName();
Collection<FunctionDescriptor> functions = packageDescriptor.getMemberScope().getFunctions(name, LookupLocation.NO_LOCATION_FROM_IDE); Collection<FunctionDescriptor> functions = packageDescriptor.getMemberScope().getFunctions(name, NoLookupLocation.FROM_IDE);
for (FunctionDescriptor descriptor : functions) { for (FunctionDescriptor descriptor : functions) {
ForceResolveUtil.forceResolveAllContents(descriptor); ForceResolveUtil.forceResolveAllContents(descriptor);
} }
@@ -148,7 +148,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
else if (declaration instanceof JetProperty) { else if (declaration instanceof JetProperty) {
JetProperty jetProperty = (JetProperty) declaration; JetProperty jetProperty = (JetProperty) declaration;
Name name = jetProperty.getNameAsSafeName(); Name name = jetProperty.getNameAsSafeName();
Collection<VariableDescriptor> properties = packageDescriptor.getMemberScope().getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE); Collection<VariableDescriptor> properties = packageDescriptor.getMemberScope().getProperties(name, NoLookupLocation.FROM_IDE);
for (VariableDescriptor descriptor : properties) { for (VariableDescriptor descriptor : properties) {
ForceResolveUtil.forceResolveAllContents(descriptor); ForceResolveUtil.forceResolveAllContents(descriptor);
} }
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.caches.resolve
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.psi.* import com.intellij.psi.*
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
import org.jetbrains.kotlin.load.java.structure.* import org.jetbrains.kotlin.load.java.structure.*
import org.jetbrains.kotlin.load.java.structure.impl.* import org.jetbrains.kotlin.load.java.structure.impl.*
@@ -74,7 +74,7 @@ fun PsiMember.getJavaMemberDescriptor(): DeclarationDescriptor? {
} }
public fun JavaDescriptorResolver.resolveMethod(method: JavaMethod): FunctionDescriptor? { public fun JavaDescriptorResolver.resolveMethod(method: JavaMethod): FunctionDescriptor? {
return getContainingScope(method)?.getFunctions(method.name, LookupLocation.NO_LOCATION_FROM_IDE)?.findByJavaElement(method) return getContainingScope(method)?.getFunctions(method.name, NoLookupLocation.FROM_IDE)?.findByJavaElement(method)
} }
public fun JavaDescriptorResolver.resolveConstructor(constructor: JavaConstructor): ConstructorDescriptor? { public fun JavaDescriptorResolver.resolveConstructor(constructor: JavaConstructor): ConstructorDescriptor? {
@@ -82,7 +82,7 @@ public fun JavaDescriptorResolver.resolveConstructor(constructor: JavaConstructo
} }
public fun JavaDescriptorResolver.resolveField(field: JavaField): PropertyDescriptor? { public fun JavaDescriptorResolver.resolveField(field: JavaField): PropertyDescriptor? {
return getContainingScope(field)?.getProperties(field.name, LookupLocation.NO_LOCATION_FROM_IDE)?.findByJavaElement(field) as? PropertyDescriptor return getContainingScope(field)?.getProperties(field.name, NoLookupLocation.FROM_IDE)?.findByJavaElement(field) as? PropertyDescriptor
} }
private fun JavaDescriptorResolver.getContainingScope(member: JavaMember): JetScope? { private fun JavaDescriptorResolver.getContainingScope(member: JavaMember): JetScope? {
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
import org.jetbrains.kotlin.idea.imports.getImportableTargets import org.jetbrains.kotlin.idea.imports.getImportableTargets
import org.jetbrains.kotlin.idea.util.ShortenReferences.Options import org.jetbrains.kotlin.idea.util.ShortenReferences.Options
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
@@ -273,7 +273,7 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options.
val typeReference = type.getStrictParentOfType<JetTypeReference>()!! val typeReference = type.getStrictParentOfType<JetTypeReference>()!!
val scope = bindingContext[BindingContext.TYPE_RESOLUTION_SCOPE, typeReference]!! val scope = bindingContext[BindingContext.TYPE_RESOLUTION_SCOPE, typeReference]!!
val name = target.getName() val name = target.getName()
val targetByName = if (target is ClassifierDescriptor) scope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) else scope.getPackage(name) val targetByName = if (target is ClassifierDescriptor) scope.getClassifier(name, NoLookupLocation.FROM_IDE) else scope.getPackage(name)
val canShortenNow = targetByName?.asString() == target.asString() val canShortenNow = targetByName?.asString() == target.asString()
processQualifiedElement(type, target, canShortenNow) processQualifiedElement(type, target, canShortenNow)
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.idea.JetDescriptorIconProvider import org.jetbrains.kotlin.idea.JetDescriptorIconProvider
import org.jetbrains.kotlin.idea.completion.* import org.jetbrains.kotlin.idea.completion.*
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.psi.JetExpression import org.jetbrains.kotlin.psi.JetExpression
import org.jetbrains.kotlin.renderer.render import org.jetbrains.kotlin.renderer.render
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
@@ -90,7 +90,7 @@ class MultipleArgumentsItemProvider(val bindingContext: BindingContext,
private fun variableInScope(parameter: ValueParameterDescriptor, scope: JetScope): VariableDescriptor? { private fun variableInScope(parameter: ValueParameterDescriptor, scope: JetScope): VariableDescriptor? {
val name = parameter.getName() val name = parameter.getName()
//TODO: there can be more than one property with such name in scope and we should be able to select one (but we need API for this) //TODO: there can be more than one property with such name in scope and we should be able to select one (but we need API for this)
val variable = scope.getLocalVariable(name) ?: scope.getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE).singleOrNull() ?: return null val variable = scope.getLocalVariable(name) ?: scope.getProperties(name, NoLookupLocation.FROM_IDE).singleOrNull() ?: return null
return if (smartCastCalculator.types(variable).any { JetTypeChecker.DEFAULT.isSubtypeOf(it, parameter.getType()) }) return if (smartCastCalculator.types(variable).any { JetTypeChecker.DEFAULT.isSubtypeOf(it, parameter.getType()) })
variable variable
else else
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMethodsHandler import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMethodsHandler
import org.jetbrains.kotlin.idea.core.psiClassToDescriptor import org.jetbrains.kotlin.idea.core.psiClassToDescriptor
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
import org.jetbrains.kotlin.psi.JetClassOrObject import org.jetbrains.kotlin.psi.JetClassOrObject
@@ -254,7 +254,7 @@ class TypeInstantiationItems(
is ClassDescriptor -> container.getStaticScope() is ClassDescriptor -> container.getStaticScope()
else -> return else -> return
} }
val samConstructor = scope.getFunctions(`class`.name, LookupLocation.NO_LOCATION_FROM_IDE) val samConstructor = scope.getFunctions(`class`.name, NoLookupLocation.FROM_IDE)
.filterIsInstance<SamConstructorDescriptor>() .filterIsInstance<SamConstructorDescriptor>()
.singleOrNull() ?: return .singleOrNull() ?: return
val lookupElement = lookupElementFactory.createLookupElement(samConstructor, bindingContext, false) val lookupElement = lookupElementFactory.createLookupElement(samConstructor, bindingContext, false)
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.idea.completion.HeuristicSignatures import org.jetbrains.kotlin.idea.completion.HeuristicSignatures
import org.jetbrains.kotlin.idea.util.FuzzyType import org.jetbrains.kotlin.idea.util.FuzzyType
import org.jetbrains.kotlin.idea.util.nullability import org.jetbrains.kotlin.idea.util.nullability
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.JetType
@@ -43,7 +43,7 @@ class TypesWithContainsDetector(
private val containsName = Name.identifier("contains") private val containsName = Name.identifier("contains")
private val booleanType = KotlinBuiltIns.getInstance().getBooleanType() private val booleanType = KotlinBuiltIns.getInstance().getBooleanType()
private val typesWithExtensionContains: Collection<JetType> = scope.getFunctions(containsName, LookupLocation.NO_LOCATION_FROM_IDE) private val typesWithExtensionContains: Collection<JetType> = scope.getFunctions(containsName, NoLookupLocation.FROM_IDE)
.filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) } .filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) }
.map { it.getExtensionReceiverParameter()!!.getType() } .map { it.getExtensionReceiverParameter()!!.getType() }
@@ -53,7 +53,7 @@ class TypesWithContainsDetector(
private fun hasContainsNoCache(type: FuzzyType): Boolean { private fun hasContainsNoCache(type: FuzzyType): Boolean {
return type.nullability() != TypeNullability.NULLABLE && return type.nullability() != TypeNullability.NULLABLE &&
type.type.memberScope.getFunctions(containsName, LookupLocation.NO_LOCATION_FROM_IDE).any { isGoodContainsFunction(it, type.freeParameters) } type.type.memberScope.getFunctions(containsName, NoLookupLocation.FROM_IDE).any { isGoodContainsFunction(it, type.freeParameters) }
|| typesWithExtensionContains.any { type.checkIsSubtypeOf(it) != null } || typesWithExtensionContains.any { type.checkIsSubtypeOf(it) != null }
} }
@@ -20,7 +20,7 @@ import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.frontend.di.createContainerForMacros import org.jetbrains.kotlin.frontend.di.createContainerForMacros
import org.jetbrains.kotlin.idea.util.FuzzyType import org.jetbrains.kotlin.idea.util.FuzzyType
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetPsiFactory
import org.jetbrains.kotlin.resolve.BindingTraceContext import org.jetbrains.kotlin.resolve.BindingTraceContext
@@ -42,7 +42,7 @@ public class IterableTypesDetector(
private val cache = HashMap<FuzzyType, FuzzyType?>() private val cache = HashMap<FuzzyType, FuzzyType?>()
private val iteratorName = Name.identifier("iterator") private val iteratorName = Name.identifier("iterator")
private val typesWithExtensionIterator: Collection<JetType> = scope.getFunctions(iteratorName, LookupLocation.NO_LOCATION_FROM_IDE) private val typesWithExtensionIterator: Collection<JetType> = scope.getFunctions(iteratorName, NoLookupLocation.FROM_IDE)
.map { it.getExtensionReceiverParameter() } .map { it.getExtensionReceiverParameter() }
.filterNotNull() .filterNotNull()
.map { it.getType() } .map { it.getType() }
@@ -75,7 +75,7 @@ public class IterableTypesDetector(
} }
private fun canBeIterable(type: FuzzyType): Boolean { private fun canBeIterable(type: FuzzyType): Boolean {
return type.type.memberScope.getFunctions(iteratorName, LookupLocation.NO_LOCATION_FROM_IDE).isNotEmpty() || return type.type.memberScope.getFunctions(iteratorName, NoLookupLocation.FROM_IDE).isNotEmpty() ||
typesWithExtensionIterator.any { type.checkIsSubtypeOf(it) != null } typesWithExtensionIterator.any { type.checkIsSubtypeOf(it) != null }
} }
} }
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.allChildren import org.jetbrains.kotlin.psi.psiUtil.allChildren
@@ -97,11 +97,11 @@ public class NewDeclarationNameValidator(
return when(target) { return when(target) {
Target.VARIABLES -> Target.VARIABLES ->
getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE).any { !it.isExtension && it.isVisible() } || getProperties(name, NoLookupLocation.FROM_IDE).any { !it.isExtension && it.isVisible() } ||
getLocalVariable(name) != null getLocalVariable(name) != null
Target.FUNCTIONS_AND_CLASSES -> Target.FUNCTIONS_AND_CLASSES ->
getFunctions(name, LookupLocation.NO_LOCATION_FROM_IDE).any { !it.isExtension && it.isVisible() } || getFunctions(name, NoLookupLocation.FROM_IDE).any { !it.isExtension && it.isVisible() } ||
getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE)?.let { it.isVisible() } ?: false getClassifier(name, NoLookupLocation.FROM_IDE)?.let { it.isVisible() } ?: false
} }
} }
@@ -48,7 +48,7 @@ import org.jetbrains.kotlin.idea.references.JetSimpleNameReference
import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.util.ImportInsertHelper import org.jetbrains.kotlin.idea.util.ImportInsertHelper
import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.elementsInRange import org.jetbrains.kotlin.psi.psiUtil.elementsInRange
@@ -238,11 +238,11 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
val originalFqName = FqName(refData.fqName) val originalFqName = FqName(refData.fqName)
if (refData.kind == KotlinReferenceData.Kind.EXTENSION_FUNCTION) { if (refData.kind == KotlinReferenceData.Kind.EXTENSION_FUNCTION) {
val functions = fileResolutionScope.getFunctions(originalFqName.shortName(), LookupLocation.NO_LOCATION_FROM_IDE) val functions = fileResolutionScope.getFunctions(originalFqName.shortName(), NoLookupLocation.FROM_IDE)
if (functions.any { it.importableFqName == originalFqName }) return null // already imported if (functions.any { it.importableFqName == originalFqName }) return null // already imported
} }
else if (refData.kind == KotlinReferenceData.Kind.EXTENSION_PROPERTY) { else if (refData.kind == KotlinReferenceData.Kind.EXTENSION_PROPERTY) {
val properties = fileResolutionScope.getProperties(originalFqName.shortName(), LookupLocation.NO_LOCATION_FROM_IDE) val properties = fileResolutionScope.getProperties(originalFqName.shortName(), NoLookupLocation.FROM_IDE)
if (properties.any { it.importableFqName == originalFqName }) return null // already imported if (properties.any { it.importableFqName == originalFqName }) return null // already imported
} }
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
import org.jetbrains.kotlin.psi.JetDeclaration import org.jetbrains.kotlin.psi.JetDeclaration
import org.jetbrains.kotlin.psi.JetElement import org.jetbrains.kotlin.psi.JetElement
@@ -62,8 +62,8 @@ fun findPackagePartInternalNameForLibraryFile(topLevelDeclaration: JetDeclaratio
val descFromSourceText = render(descriptor) val descFromSourceText = render(descriptor)
val descriptors: Collection<CallableDescriptor> = when (descriptor) { val descriptors: Collection<CallableDescriptor> = when (descriptor) {
is FunctionDescriptor -> packageDescriptor.memberScope.getFunctions(descriptor.name, LookupLocation.NO_LOCATION_FROM_IDE) is FunctionDescriptor -> packageDescriptor.memberScope.getFunctions(descriptor.name, NoLookupLocation.FROM_IDE)
is PropertyDescriptor -> packageDescriptor.memberScope.getProperties(descriptor.name, LookupLocation.NO_LOCATION_FROM_IDE) is PropertyDescriptor -> packageDescriptor.memberScope.getProperties(descriptor.name, NoLookupLocation.FROM_IDE)
else -> { else -> {
reportError(topLevelDeclaration, descriptor) reportError(topLevelDeclaration, descriptor)
listOf() listOf()
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings
import org.jetbrains.kotlin.idea.references.JetReference import org.jetbrains.kotlin.idea.references.JetReference
import org.jetbrains.kotlin.idea.util.ImportInsertHelper import org.jetbrains.kotlin.idea.util.ImportInsertHelper
import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
@@ -199,7 +199,7 @@ public class KotlinImportOptimizer() : ImportOptimizer {
val scope = fileWithImports.getResolutionFacade().getFileTopLevelScope(fileWithImports) val scope = fileWithImports.getResolutionFacade().getFileTopLevelScope(fileWithImports)
for (fqName in classNamesToCheck) { for (fqName in classNamesToCheck) {
if (scope.getClassifier(fqName.shortName(), LookupLocation.NO_LOCATION_FROM_IDE)?.importableFqNameSafe != fqName) { if (scope.getClassifier(fqName.shortName(), NoLookupLocation.FROM_IDE)?.importableFqNameSafe != fqName) {
// add explicit import if failed to import with * (or from current package) // add explicit import if failed to import with * (or from current package)
importsToGenerate.add(ImportPath(fqName, false)) importsToGenerate.add(ImportPath(fqName, false))
@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.search
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.util.ShortenReferences import org.jetbrains.kotlin.idea.util.ShortenReferences
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
@@ -115,7 +115,7 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention<JetN
} }
callableDescriptor.getContainingScope(bindingContext) callableDescriptor.getContainingScope(bindingContext)
?.getProperties(callableDescriptor.name, LookupLocation.NO_LOCATION_FROM_IDE) ?.getProperties(callableDescriptor.name, NoLookupLocation.FROM_IDE)
?.firstOrNull() ?.firstOrNull()
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) } ?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } } ?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.DefaultSearchHelper
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchTarget import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchTarget
import org.jetbrains.kotlin.idea.search.usagesSearch.search import org.jetbrains.kotlin.idea.search.usagesSearch.search
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
@@ -97,7 +97,7 @@ public class ConvertPropertyToFunctionIntention : JetSelfTargetingIntention<JetP
if (callable is JetProperty) { if (callable is JetProperty) {
callableDescriptor.getContainingScope(bindingContext) callableDescriptor.getContainingScope(bindingContext)
?.getFunctions(callableDescriptor.name, LookupLocation.NO_LOCATION_FROM_IDE) ?.getFunctions(callableDescriptor.name, NoLookupLocation.FROM_IDE)
?.firstOrNull { it.getValueParameters().isEmpty() } ?.firstOrNull { it.getValueParameters().isEmpty() }
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) } ?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } } ?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil; import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil;
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers; import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
import org.jetbrains.kotlin.idea.util.ShortenReferences; import org.jetbrains.kotlin.idea.util.ShortenReferences;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.renderer.DescriptorRenderer;
@@ -54,7 +55,6 @@ import org.jetbrains.kotlin.renderer.NameShortness;
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil; import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil;
import org.jetbrains.kotlin.resolve.VisibilityUtil; import org.jetbrains.kotlin.resolve.VisibilityUtil;
import org.jetbrains.kotlin.resolve.scopes.JetScope; import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.incremental.components.LookupLocation;
import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeUtils; import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.kotlin.types.checker.JetTypeChecker; import org.jetbrains.kotlin.types.checker.JetTypeChecker;
@@ -268,7 +268,7 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
Name name = functionDescriptor.getName(); Name name = functionDescriptor.getName();
for (JetType type : TypeUtils.getAllSupertypes(classDescriptor.getDefaultType())) { for (JetType type : TypeUtils.getAllSupertypes(classDescriptor.getDefaultType())) {
JetScope scope = type.getMemberScope(); JetScope scope = type.getMemberScope();
for (FunctionDescriptor function : scope.getFunctions(name, LookupLocation.NO_LOCATION_FROM_IDE)) { for (FunctionDescriptor function : scope.getFunctions(name, NoLookupLocation.FROM_IDE)) {
if (!function.getKind().isReal()) continue; if (!function.getKind().isReal()) continue;
if (function.getModality().isOverridable()) if (function.getModality().isOverridable())
superFunctions.add(function); superFunctions.add(function);
@@ -55,6 +55,7 @@ import org.jetbrains.kotlin.idea.util.ShortenReferences
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
@@ -400,7 +401,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
SourceElement.NO_SOURCE SourceElement.NO_SOURCE
) )
val validator = CollectingNameValidator { scope.getClassifier(Name.identifier(it), LookupLocation.NO_LOCATION_FROM_IDE) == null } val validator = CollectingNameValidator { scope.getClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null }
val parameterNames = KotlinNameSuggester.suggestNamesForTypeParameters(typeParameterCount, validator) val parameterNames = KotlinNameSuggester.suggestNamesForTypeParameters(typeParameterCount, validator)
val typeParameters = (0..typeParameterCount - 1).map { val typeParameters = (0..typeParameterCount - 1).map {
TypeParameterDescriptorImpl.createWithDefaultBound( TypeParameterDescriptorImpl.createWithDefaultBound(
@@ -620,7 +621,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
} }
} }
val validator = CollectingNameValidator { scope.getClassifier(Name.identifier(it), LookupLocation.NO_LOCATION_FROM_IDE) == null } val validator = CollectingNameValidator { scope.getClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null }
val typeParameterNames = allTypeParametersNotInScope.map { KotlinNameSuggester.suggestNameByName(it.getName().asString(), validator) } val typeParameterNames = allTypeParametersNotInScope.map { KotlinNameSuggester.suggestNameByName(it.getName().asString(), validator) }
return allTypeParametersNotInScope.zip(typeParameterNames).toMap() return allTypeParametersNotInScope.zip(typeParameterNames).toMap()
@@ -24,8 +24,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.idea.references.JetSimpleNameReference import org.jetbrains.kotlin.idea.references.JetSimpleNameReference
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS
@@ -38,7 +37,10 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.JetTypeChecker import org.jetbrains.kotlin.types.checker.JetTypeChecker
import java.util.* import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import java.util.Collections
import java.util.HashSet
import java.util.LinkedHashSet
private fun JetType.contains(inner: JetType): Boolean { private fun JetType.contains(inner: JetType): Boolean {
return JetTypeChecker.DEFAULT.equalTypes(this, inner) || getArguments().any { inner in it.getType() } return JetTypeChecker.DEFAULT.equalTypes(this, inner) || getArguments().any { inner in it.getType() }
@@ -66,7 +68,7 @@ private fun JetType.renderLong(typeParameterNameMap: Map<TypeParameterDescriptor
private fun getTypeParameterNamesNotInScope(typeParameters: Collection<TypeParameterDescriptor>, scope: JetScope): List<TypeParameterDescriptor> { private fun getTypeParameterNamesNotInScope(typeParameters: Collection<TypeParameterDescriptor>, scope: JetScope): List<TypeParameterDescriptor> {
return typeParameters.filter { typeParameter -> return typeParameters.filter { typeParameter ->
val classifier = scope.getClassifier(typeParameter.name, LookupLocation.NO_LOCATION_FROM_IDE) val classifier = scope.getClassifier(typeParameter.name, NoLookupLocation.FROM_IDE)
classifier == null || classifier != typeParameter classifier == null || classifier != typeParameter
} }
} }
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getTyp
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessTypes import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessTypes
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetValVar import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetValVar
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
@@ -137,5 +137,5 @@ fun JetType.hasTypeParametersToAdd(functionDescriptor: FunctionDescriptor, conte
else -> null else -> null
} ?: return true } ?: return true
return typeParametersToAdd.any { scope.getClassifier(it.name, LookupLocation.NO_LOCATION_FROM_IDE) != it } return typeParametersToAdd.any { scope.getClassifier(it.name, NoLookupLocation.FROM_IDE) != it }
} }
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.CollectingNameValidator import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.JetCallableDefinitionUsage import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.JetCallableDefinitionUsage
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.JetCallableDeclaration import org.jetbrains.kotlin.psi.JetCallableDeclaration
import org.jetbrains.kotlin.psi.JetClass import org.jetbrains.kotlin.psi.JetClass
@@ -81,7 +81,7 @@ public class JetChangeSignatureData(
val validator = bodyScope?.let { bodyScope -> val validator = bodyScope?.let { bodyScope ->
CollectingNameValidator(paramNames) { CollectingNameValidator(paramNames) {
val name = Name.identifier(it) val name = Name.identifier(it)
bodyScope.getLocalVariable(name) == null && bodyScope.getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE).isEmpty() bodyScope.getLocalVariable(name) == null && bodyScope.getProperties(name, NoLookupLocation.FROM_IDE).isEmpty()
} }
} ?: CollectingNameValidator(paramNames) } ?: CollectingNameValidator(paramNames)
val receiverType = baseDescriptor.getExtensionReceiverParameter()?.getType() ?: return null val receiverType = baseDescriptor.getExtensionReceiverParameter()?.getType() ?: return null
@@ -57,6 +57,7 @@ import org.jetbrains.kotlin.idea.references.JetSimpleNameReference;
import org.jetbrains.kotlin.idea.references.ReferencesPackage; import org.jetbrains.kotlin.idea.references.ReferencesPackage;
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchPackage; import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchPackage;
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers; import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.kdoc.psi.impl.KDocName; import org.jetbrains.kotlin.kdoc.psi.impl.KDocName;
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor; import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
@@ -74,7 +75,6 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind; import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode; import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
import org.jetbrains.kotlin.resolve.scopes.JetScope; import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.incremental.components.LookupLocation;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver; import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver;
import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.JetType;
@@ -623,8 +623,8 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
if (!kind.getIsConstructor() && callableScope != null && !info.getNewName().isEmpty()) { if (!kind.getIsConstructor() && callableScope != null && !info.getNewName().isEmpty()) {
Name newName = Name.identifier(info.getNewName()); Name newName = Name.identifier(info.getNewName());
Collection<? extends CallableDescriptor> conflicts = oldDescriptor instanceof FunctionDescriptor Collection<? extends CallableDescriptor> conflicts = oldDescriptor instanceof FunctionDescriptor
? callableScope.getFunctions(newName, LookupLocation.NO_LOCATION_FROM_IDE) ? callableScope.getFunctions(newName, NoLookupLocation.FROM_IDE)
: callableScope.getProperties(newName, LookupLocation.NO_LOCATION_FROM_IDE); : callableScope.getProperties(newName, NoLookupLocation.FROM_IDE);
for (CallableDescriptor conflict : conflicts) { for (CallableDescriptor conflict : conflicts) {
if (conflict == oldDescriptor) continue; if (conflict == oldDescriptor) continue;
@@ -647,7 +647,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
} }
if (parametersScope != null) { if (parametersScope != null) {
if (kind == JetMethodDescriptor.Kind.PRIMARY_CONSTRUCTOR && valOrVar != JetValVar.None) { if (kind == JetMethodDescriptor.Kind.PRIMARY_CONSTRUCTOR && valOrVar != JetValVar.None) {
for (VariableDescriptor property : parametersScope.getProperties(Name.identifier(parameterName), LookupLocation.NO_LOCATION_FROM_IDE)) { for (VariableDescriptor property : parametersScope.getProperties(Name.identifier(parameterName), NoLookupLocation.FROM_IDE)) {
PsiElement propertyDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(property); PsiElement propertyDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(property);
if (propertyDeclaration != null && !(propertyDeclaration.getParent() instanceof JetParameterList)) { if (propertyDeclaration != null && !(propertyDeclaration.getParent() instanceof JetParameterList)) {
@@ -60,7 +60,7 @@ import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.util.approximateWithResolvableType import org.jetbrains.kotlin.idea.util.approximateWithResolvableType
import org.jetbrains.kotlin.idea.util.isResolvableInScope import org.jetbrains.kotlin.idea.util.isResolvableInScope
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.psi.psiUtil.*
import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.DescriptorRenderer
@@ -650,7 +650,7 @@ private fun ExtractionData.inferParametersInfo(
options.captureLocalFunctions options.captureLocalFunctions
&& originalRef.getReferencedName() == originalDescriptor.getName().asString() // to forbid calls by convention && originalRef.getReferencedName() == originalDescriptor.getName().asString() // to forbid calls by convention
&& originalDeclaration is JetNamedFunction && originalDeclaration.isLocal() && originalDeclaration is JetNamedFunction && originalDeclaration.isLocal()
&& (targetScope == null || originalDescriptor !in targetScope.getFunctions(originalDescriptor.name, LookupLocation.NO_LOCATION_FROM_IDE)) && (targetScope == null || originalDescriptor !in targetScope.getFunctions(originalDescriptor.name, NoLookupLocation.FROM_IDE))
val descriptorToExtract = (if (extractThis) thisDescriptor else null) ?: originalDescriptor val descriptorToExtract = (if (extractThis) thisDescriptor else null) ?: originalDescriptor
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.idea.project.ProjectStructureUtil
import org.jetbrains.kotlin.idea.refactoring.fqName.isImported import org.jetbrains.kotlin.idea.refactoring.fqName.isImported
import org.jetbrains.kotlin.idea.util.ImportInsertHelper import org.jetbrains.kotlin.idea.util.ImportInsertHelper
import org.jetbrains.kotlin.idea.util.ImportInsertHelper.ImportDescriptorResult import org.jetbrains.kotlin.idea.util.ImportInsertHelper.ImportDescriptorResult
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
@@ -121,18 +121,18 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
// check if import is not needed // check if import is not needed
when (target) { when (target) {
is ClassDescriptor -> { is ClassDescriptor -> {
val classifier = topLevelScope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) val classifier = topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE)
if (classifier?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED if (classifier?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED
} }
is PackageViewDescriptor -> { is PackageViewDescriptor -> {
if (topLevelScope.getPackage(name)?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED if (topLevelScope.getPackage(name)?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED
} }
is FunctionDescriptor -> { is FunctionDescriptor -> {
val functions = topLevelScope.getFunctions(name, LookupLocation.NO_LOCATION_FROM_IDE) val functions = topLevelScope.getFunctions(name, NoLookupLocation.FROM_IDE)
if (functions.map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED if (functions.map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED
} }
is PropertyDescriptor -> { is PropertyDescriptor -> {
val properties = topLevelScope.getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE) val properties = topLevelScope.getProperties(name, NoLookupLocation.FROM_IDE)
if (properties.map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED if (properties.map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED
} }
else -> { else -> {
@@ -151,7 +151,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
// check there is an explicit import of a class/package with the same name already // check there is an explicit import of a class/package with the same name already
val conflict = when (target) { val conflict = when (target) {
is ClassDescriptor -> topLevelScope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) is ClassDescriptor -> topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE)
is PackageViewDescriptor -> topLevelScope.getPackage(name) is PackageViewDescriptor -> topLevelScope.getPackage(name)
else -> null else -> null
} }
@@ -170,7 +170,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
&& when (target) { && when (target) {
// this check does not give a guarantee that import with * will import the class - for example, // this check does not give a guarantee that import with * will import the class - for example,
// there can be classes with conflicting name in more than one import with * // there can be classes with conflicting name in more than one import with *
is ClassDescriptor -> topLevelScope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) == null is ClassDescriptor -> topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE) == null
is PackageViewDescriptor -> false is PackageViewDescriptor -> false
is FunctionDescriptor, is PropertyDescriptor -> true is FunctionDescriptor, is PropertyDescriptor -> true
else -> throw Exception() else -> throw Exception()
@@ -236,12 +236,12 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
val topLevelScope = resolutionFacade.getFileTopLevelScope(file) val topLevelScope = resolutionFacade.getFileTopLevelScope(file)
val conflictCandidates: List<ClassifierDescriptor> = classNamesToImport val conflictCandidates: List<ClassifierDescriptor> = classNamesToImport
.flatMap { .flatMap {
importedScopes.map { scope -> scope.getClassifier(it, LookupLocation.NO_LOCATION_FROM_IDE) }.filterNotNull() importedScopes.map { scope -> scope.getClassifier(it, NoLookupLocation.FROM_IDE) }.filterNotNull()
} }
.filter { importedClass -> .filter { importedClass ->
isVisible(importedClass) isVisible(importedClass)
// check that class is really imported // check that class is really imported
&& topLevelScope.getClassifier(importedClass.name, LookupLocation.NO_LOCATION_FROM_IDE) == importedClass && topLevelScope.getClassifier(importedClass.name, NoLookupLocation.FROM_IDE) == importedClass
// and not yet imported explicitly // and not yet imported explicitly
&& imports.all { it.importPath != ImportPath(importedClass.importableFqNameSafe, false) } && imports.all { it.importPath != ImportPath(importedClass.importableFqNameSafe, false) }
} }
@@ -251,7 +251,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
if (target is ClassDescriptor) { if (target is ClassDescriptor) {
val newTopLevelScope = resolutionFacade.getFileTopLevelScope(file) val newTopLevelScope = resolutionFacade.getFileTopLevelScope(file)
val resolvedTo = newTopLevelScope.getClassifier(target.name, LookupLocation.NO_LOCATION_FROM_IDE) val resolvedTo = newTopLevelScope.getClassifier(target.name, NoLookupLocation.FROM_IDE)
if (resolvedTo?.importableFqNameSafe != targetFqName) { if (resolvedTo?.importableFqNameSafe != targetFqName) {
addedImport.delete() addedImport.delete()
return ImportDescriptorResult.FAIL return ImportDescriptorResult.FAIL
@@ -274,7 +274,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
} }
val parentScope = getMemberScope(fqName.parent(), moduleDescriptor) ?: return null val parentScope = getMemberScope(fqName.parent(), moduleDescriptor) ?: return null
val classifier = parentScope.getClassifier(fqName.shortName(), LookupLocation.NO_LOCATION_FROM_IDE) val classifier = parentScope.getClassifier(fqName.shortName(), NoLookupLocation.FROM_IDE)
val classDescriptor = classifier as? ClassDescriptor ?: return null val classDescriptor = classifier as? ClassDescriptor ?: return null
return classDescriptor.getDefaultType().getMemberScope() return classDescriptor.getDefaultType().getMemberScope()
} }
@@ -286,7 +286,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
// check if there is a conflicting class imported with * import // check if there is a conflicting class imported with * import
// (not with explicit import - explicit imports are checked before this method invocation) // (not with explicit import - explicit imports are checked before this method invocation)
val classifier = topLevelScope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) val classifier = topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE)
if (classifier != null && detectNeededImports(listOf(classifier)).isNotEmpty()) { if (classifier != null && detectNeededImports(listOf(classifier)).isNotEmpty()) {
return ImportDescriptorResult.FAIL return ImportDescriptorResult.FAIL
} }
@@ -315,7 +315,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
if (importsToCheck.isNotEmpty()) { if (importsToCheck.isNotEmpty()) {
val topLevelScope = resolutionFacade.getFileTopLevelScope(file) val topLevelScope = resolutionFacade.getFileTopLevelScope(file)
for (classFqName in importsToCheck) { for (classFqName in importsToCheck) {
val classifier = topLevelScope.getClassifier(classFqName.shortName(), LookupLocation.NO_LOCATION_FROM_IDE) val classifier = topLevelScope.getClassifier(classFqName.shortName(), NoLookupLocation.FROM_IDE)
if (classifier?.importableFqNameSafe != classFqName) { if (classifier?.importableFqNameSafe != classFqName) {
addImport(classFqName, false) // restore explicit import addImport(classFqName, false) // restore explicit import
} }