This commit is contained in:
Valentin Kipyatkov
2015-10-25 12:03:29 +03:00
parent e1b8b21abb
commit 5f06f53bfd
45 changed files with 187 additions and 193 deletions
@@ -56,7 +56,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
val owner = getterOrSetter.getContainingDeclaration() as? ClassDescriptor ?: return null
val originalGetterOrSetter = getterOrSetter.original
return resolutionScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(listOf(owner.defaultType)) }
return resolutionScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(listOf(owner.defaultType)) }
.filterIsInstance<SyntheticJavaPropertyDescriptor>()
.firstOrNull { originalGetterOrSetter == it.getMethod || originalGetterOrSetter == it.setMethod }
}
@@ -130,7 +130,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : ImportingSc
return null
}
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
//TODO: use location parameter!
var result: SmartList<PropertyDescriptor>? = null
@@ -162,7 +162,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : ImportingSc
return result
}
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
val result = ArrayList<PropertyDescriptor>()
val processedTypes = HashSet<TypeConstructor>()
receiverTypes.forEach { result.collectSyntheticProperties(it.constructor, processedTypes) }
@@ -53,7 +53,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : ImportingScope
return MyFunctionDescriptor.create(enhancedFunction)
}
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
var result: SmartList<FunctionDescriptor>? = null
for (type in receiverTypes) {
for (function in type.memberScope.getFunctions(name, location)) {
@@ -73,7 +73,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : ImportingScope
}
}
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
return receiverTypes.flatMapTo(LinkedHashSet<FunctionDescriptor>()) { type ->
type.memberScope.getDescriptors(DescriptorKindFilter.FUNCTIONS)
.filterIsInstance<FunctionDescriptor>()
@@ -37,28 +37,28 @@ class AllUnderImportsScope(descriptor: DeclarationDescriptor) : ImportingScope b
listOf(NoSubpackagesInPackageScope(descriptor as PackageViewDescriptor))
}
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= scopes.flatMap { it.getDescriptors(kindFilter, nameFilter) }
override fun getDeclaredClassifier(name: Name, location: LookupLocation)
override fun getContributedClassifier(name: Name, location: LookupLocation)
= scopes.asSequence().map { it.getClassifier(name, location) }.filterNotNull().singleOrNull()
override fun getDeclaredVariables(name: Name, location: LookupLocation)
override fun getContributedVariables(name: Name, location: LookupLocation)
= scopes.flatMap { it.getProperties(name, location) }
override fun getDeclaredFunctions(name: Name, location: LookupLocation)
override fun getContributedFunctions(name: Name, location: LookupLocation)
= scopes.flatMap { it.getFunctions(name, location) }
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes, name, location) }
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= scopes.flatMap { it.getSyntheticExtensionFunctions(receiverTypes, name, location) }
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
= scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes) }
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
= scopes.flatMap { it.getSyntheticExtensionFunctions(receiverTypes) }
override fun printStructure(p: Printer) {
@@ -556,7 +556,7 @@ public class DescriptorResolver {
Name name = nameExpression.getReferencedNameAsName();
ClassifierDescriptor classifier = ScopeUtilsKt.getClassifier(scope, name, NoLookupLocation.UNSORTED);
ClassifierDescriptor classifier = ScopeUtilsKt.findClassifier(scope, name, NoLookupLocation.UNSORTED);
if (classifier instanceof TypeParameterDescriptor && classifier.getContainingDeclaration() == descriptor) continue;
if (classifier != null) {
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.check
@@ -55,7 +55,7 @@ public class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageVa
): ClassifierDescriptor? {
if (userType.qualifier == null && !userType.startWithPackage) { // optimization for non-qualified types
return userType.referenceExpression?.let {
val classifier = scope.getClassifier(it.getReferencedNameAsName(), KotlinLookupLocation(it))
val classifier = scope.findClassifier(it.getReferencedNameAsName(), KotlinLookupLocation(it))
storeResult(trace, it, classifier, scope.ownerDescriptor, inImport = false, isQualifier = false)
classifier
}
@@ -278,7 +278,7 @@ public class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageVa
val firstDescriptor = scopeForFirstPart?.let {
val firstPart = path.first()
it.getClassifier(firstPart.name, firstPart.location)?.apply {
it.findClassifier(firstPart.name, firstPart.location)?.apply {
storeResult(trace, firstPart.expression, this, shouldBeVisibleFrom, inImport)
}
}
@@ -24,19 +24,19 @@ import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.utils.Printer
class SingleImportScope(private val aliasName: Name, private val descriptors: Collection<DeclarationDescriptor>) : ImportingScope by ImportingScope.Empty {
override fun getDeclaredClassifier(name: Name, location: LookupLocation)
override fun getContributedClassifier(name: Name, location: LookupLocation)
= if (name == aliasName) descriptors.filterIsInstance<ClassifierDescriptor>().singleOrNull() else null
override fun getContributedPackage(name: Name)
= if (name == aliasName) descriptors.filterIsInstance<PackageViewDescriptor>().singleOrNull() else null
override fun getDeclaredVariables(name: Name, location: LookupLocation)
override fun getContributedVariables(name: Name, location: LookupLocation)
= if (name == aliasName) descriptors.filterIsInstance<VariableDescriptor>() else emptyList()
override fun getDeclaredFunctions(name: Name, location: LookupLocation)
override fun getContributedFunctions(name: Name, location: LookupLocation)
= if (name == aliasName) descriptors.filterIsInstance<FunctionDescriptor>() else emptyList()
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= descriptors
override fun printStructure(p: Printer) {
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.scopes.KtScope
import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent
import org.jetbrains.kotlin.resolve.scopes.utils.getLocalVariable
import org.jetbrains.kotlin.resolve.scopes.utils.findLocalVariable
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.util.OperatorNameConventions
@@ -84,7 +84,7 @@ private object FunctionCollector : CallableDescriptorCollector<FunctionDescripto
override fun getStaticInheritanceByName(lexicalScope: LexicalScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
return lexicalScope.collectAllFromMeAndParent {
if (it is LexicalChainedScope && it.isStaticScope) {
it.getDeclaredFunctions(name, location).filter { it.extensionReceiverParameter == null }
it.getContributedFunctions(name, location).filter { it.extensionReceiverParameter == null }
}
else {
emptyList()
@@ -95,8 +95,8 @@ private object FunctionCollector : CallableDescriptorCollector<FunctionDescripto
override fun getLocalNonExtensionsByName(lexicalScope: LexicalScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
return lexicalScope.collectAllFromMeAndParent {
if (it !is ImportingScope && it.ownerDescriptor is FunctionDescriptor) {
it.getDeclaredFunctions(name, location).filter { it.extensionReceiverParameter == null } +
getConstructors(it.getDeclaredClassifier(name, location))
it.getContributedFunctions(name, location).filter { it.extensionReceiverParameter == null } +
getConstructors(it.getContributedClassifier(name, location))
}
else {
emptyList()
@@ -169,13 +169,13 @@ private object FunctionCollector : CallableDescriptorCollector<FunctionDescripto
private object VariableCollector : CallableDescriptorCollector<VariableDescriptor> {
override fun getLocalNonExtensionsByName(lexicalScope: LexicalScope, name: Name, location: LookupLocation): Collection<VariableDescriptor> {
return listOfNotNull(lexicalScope.getLocalVariable(name))
return listOfNotNull(lexicalScope.findLocalVariable(name))
}
override fun getStaticInheritanceByName(lexicalScope: LexicalScope, name: Name, location: LookupLocation): Collection<VariableDescriptor> {
return lexicalScope.collectAllFromMeAndParent {
if (it is LexicalChainedScope && it.isStaticScope) {
it.getDeclaredVariables(name, location)
it.getContributedVariables(name, location)
}
else {
emptyList()
@@ -86,7 +86,7 @@ class LazyImportResolver(
if (!directive.isAllUnder) {
PlatformTypesMappedToKotlinChecker.checkPlatformTypesMappedToKotlin(
moduleDescriptor, traceForImportResolve, directive, directiveImportScope.getDescriptors())
moduleDescriptor, traceForImportResolve, directive, directiveImportScope.getContributedDescriptors())
}
directiveImportScope
@@ -100,7 +100,7 @@ class LazyImportResolver(
val alias = KtPsiUtil.getAliasName(importDirective)?.identifier
if (scope != null && alias != null) {
if (scope.getDeclaredClassifier(Name.identifier(alias), KotlinLookupLocation(importDirective)) != null) {
if (scope.getContributedClassifier(Name.identifier(alias), KotlinLookupLocation(importDirective)) != null) {
explicitClassImports.put(alias, importDirective)
}
}
@@ -184,58 +184,58 @@ class LazyImportScope(
return Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, importResolver.moduleDescriptor) == includeVisible
}
override fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
return importResolver.selectSingleFromImports(name) { scope, name ->
val descriptor = scope.getDeclaredClassifier(name, location)
val descriptor = scope.getContributedClassifier(name, location)
if (descriptor != null && isClassVisible(descriptor as ClassDescriptor/*no type parameter can be imported*/)) descriptor else null
}
}
override fun getContributedPackage(name: Name) = null
override fun getDeclaredVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name) { scope, name -> scope.getDeclaredVariables(name, location) }
return importResolver.collectFromImports(name) { scope, name -> scope.getContributedVariables(name, location) }
}
override fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name) { scope, name -> scope.getDeclaredFunctions(name, location) }
return importResolver.collectFromImports(name) { scope, name -> scope.getContributedFunctions(name, location) }
}
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name) { scope, name -> scope.getSyntheticExtensionProperties(receiverTypes, name, location) }
return importResolver.collectFromImports(name) { scope, name -> scope.getContributedSyntheticExtensionProperties(receiverTypes, name, location) }
}
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name) { scope, name -> scope.getSyntheticExtensionFunctions(receiverTypes, name, location) }
return importResolver.collectFromImports(name) { scope, name -> scope.getContributedSyntheticExtensionFunctions(receiverTypes, name, location) }
}
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
// we do not perform any filtering by visibility here because all descriptors from both visible/invisible filter scopes are to be added anyway
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.storageManager.compute {
importResolver.indexedImports.imports.flatMapTo(LinkedHashSet<PropertyDescriptor>()) { import ->
importResolver.getImportScope(import).getSyntheticExtensionProperties(receiverTypes)
importResolver.getImportScope(import).getContributedSyntheticExtensionProperties(receiverTypes)
}
}
}
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
// we do not perform any filtering by visibility here because all descriptors from both visible/invisible filter scopes are to be added anyway
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.storageManager.compute {
importResolver.indexedImports.imports.flatMapTo(LinkedHashSet<FunctionDescriptor>()) { import ->
importResolver.getImportScope(import).getSyntheticExtensionFunctions(receiverTypes)
importResolver.getImportScope(import).getContributedSyntheticExtensionFunctions(receiverTypes)
}
}
}
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
// we do not perform any filtering by visibility here because all descriptors from both visible/invisible filter scopes are to be added anyway
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
@@ -245,7 +245,7 @@ class LazyImportScope(
val importPath = directive.getImportPath() ?: continue
val importedName = importPath.getImportedName()
if (importedName == null || nameFilter(importedName)) {
descriptors.addAll(importResolver.getImportScope(directive).getDescriptors(kindFilter, nameFilter))
descriptors.addAll(importResolver.getImportScope(directive).getContributedDescriptors(kindFilter, nameFilter))
}
}
descriptors
@@ -38,13 +38,13 @@ public class LexicalChainedScope(
override val parent = parent.takeSnapshot()
private val scopeChain = memberScopes.clone()
override fun getDeclaredDescriptors() = getFromAllScopes(scopeChain) { it.getAllDescriptors() }
override fun getContributedDescriptors() = getFromAllScopes(scopeChain) { it.getAllDescriptors() }
override fun getDeclaredClassifier(name: Name, location: LookupLocation) = getFirstMatch(scopeChain) { it.getClassifier(name, location) }
override fun getContributedClassifier(name: Name, location: LookupLocation) = getFirstMatch(scopeChain) { it.getClassifier(name, location) }
override fun getDeclaredVariables(name: Name, location: LookupLocation) = getFromAllScopes(scopeChain) { it.getProperties(name, location) }
override fun getContributedVariables(name: Name, location: LookupLocation) = getFromAllScopes(scopeChain) { it.getProperties(name, location) }
override fun getDeclaredFunctions(name: Name, location: LookupLocation) = getFromAllScopes(scopeChain) { it.getFunctions(name, location) }
override fun getContributedFunctions(name: Name, location: LookupLocation) = getFromAllScopes(scopeChain) { it.getFunctions(name, location) }
override fun toString(): String = debugName
@@ -44,13 +44,13 @@ public class LexicalScopeImpl @JvmOverloads constructor(
InitializeHandler(redeclarationHandler).initialize()
}
override fun getDeclaredDescriptors() = addedDescriptors
override fun getContributedDescriptors() = addedDescriptors
override fun getDeclaredClassifier(name: Name, location: LookupLocation) = getDeclaredClassifier(name)
override fun getContributedClassifier(name: Name, location: LookupLocation) = getDeclaredClassifier(name)
override fun getDeclaredVariables(name: Name, location: LookupLocation) = getDeclaredVariables(name)
override fun getContributedVariables(name: Name, location: LookupLocation) = getDeclaredVariables(name)
override fun getDeclaredFunctions(name: Name, location: LookupLocation) = getDeclaredFunctions(name)
override fun getContributedFunctions(name: Name, location: LookupLocation) = getDeclaredFunctions(name)
override fun toString(): String = debugName
@@ -70,13 +70,13 @@ class LexicalWritableScope(
addVariableOrClassDescriptor(classifierDescriptor)
}
override fun getDeclaredDescriptors() = checkMayRead().addedDescriptors
override fun getContributedDescriptors() = checkMayRead().addedDescriptors
override fun getDeclaredClassifier(name: Name, location: LookupLocation) = checkMayRead().getDeclaredClassifier(name)
override fun getContributedClassifier(name: Name, location: LookupLocation) = checkMayRead().getDeclaredClassifier(name)
override fun getDeclaredVariables(name: Name, location: LookupLocation) = checkMayRead().getDeclaredVariables(name)
override fun getContributedVariables(name: Name, location: LookupLocation) = checkMayRead().getDeclaredVariables(name)
override fun getDeclaredFunctions(name: Name, location: LookupLocation) = checkMayRead().getDeclaredFunctions(name)
override fun getContributedFunctions(name: Name, location: LookupLocation) = checkMayRead().getDeclaredFunctions(name)
private fun checkMayRead(): LexicalWritableScope {
if (lockLevel != WritableScope.LockLevel.READING && lockLevel != WritableScope.LockLevel.BOTH) {
@@ -101,15 +101,15 @@ class LexicalWritableScope(
override val implicitReceiver: ReceiverParameterDescriptor?
get() = this@LexicalWritableScope.implicitReceiver
override fun getDeclaredDescriptors() = this@LexicalWritableScope.addedDescriptors.subList(0, descriptorLimit)
override fun getContributedDescriptors() = this@LexicalWritableScope.addedDescriptors.subList(0, descriptorLimit)
override fun getDeclaredClassifier(name: Name, location: LookupLocation)
override fun getContributedClassifier(name: Name, location: LookupLocation)
= this@LexicalWritableScope.getDeclaredClassifier(name, descriptorLimit)
override fun getDeclaredVariables(name: Name, location: LookupLocation)
override fun getContributedVariables(name: Name, location: LookupLocation)
= this@LexicalWritableScope.getDeclaredVariables(name, descriptorLimit)
override fun getDeclaredFunctions(name: Name, location: LookupLocation)
override fun getContributedFunctions(name: Name, location: LookupLocation)
= this@LexicalWritableScope.getDeclaredFunctions(name, descriptorLimit)
override fun toString(): String = "Snapshot($descriptorLimit) for $debugName"
@@ -66,38 +66,36 @@ public fun LexicalScope.getDeclarationsByLabel(labelName: Name): Collection<Decl
}
// Result is guaranteed to be filtered by kind and name.
public fun LexicalScope.getDescriptorsFromAllFiltered(
public fun LexicalScope.collectDescriptorsFiltered(
kindFilter: DescriptorKindFilter = DescriptorKindFilter.ALL,
nameFilter: (Name) -> Boolean = { true }
): Collection<DeclarationDescriptor> {
if (kindFilter.kindMask == 0) return listOf()
return collectAllFromMeAndParent { it.getDescriptors(kindFilter, nameFilter) }
return collectAllFromMeAndParent { it.getContributedDescriptors(kindFilter, nameFilter) }
.filter { kindFilter.accepts(it) && nameFilter(it.name) }
}
@Deprecated("Use getOwnProperties instead")
public fun LexicalScope.getLocalVariable(name: Name): VariableDescriptor? {
public fun LexicalScope.findLocalVariable(name: Name): VariableDescriptor? {
return findFirstFromMeAndParent {
when {
it is LexicalScopeWrapper -> it.delegate.getLocalVariable(name)
it is LexicalScopeWrapper -> it.delegate.findLocalVariable(name)
it is MemberScopeToImportingScopeAdapter -> it.memberScope.getLocalVariable(name) /* todo remove hack*/
it !is ImportingScope && it !is LexicalChainedScope -> it.getDeclaredVariables(name, NoLookupLocation.UNSORTED).singleOrNull() /* todo check this*/
it !is ImportingScope && it !is LexicalChainedScope -> it.getContributedVariables(name, NoLookupLocation.UNSORTED).singleOrNull() /* todo check this*/
else -> null
}
}
}
public fun LexicalScope.getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
return findFirstFromMeAndParent { it.getDeclaredClassifier(name, location) }
}
public fun LexicalScope.findClassifier(name: Name, location: LookupLocation): ClassifierDescriptor?
= findFirstFromMeAndParent { it.getContributedClassifier(name, location) }
public fun LexicalScope.getPackage(name: Name): PackageViewDescriptor? {
return findFirstFromImportingScopes { it.getContributedPackage(name) }
}
public fun LexicalScope.findPackage(name: Name): PackageViewDescriptor?
= findFirstFromImportingScopes { it.getContributedPackage(name) }
public fun LexicalScope.takeSnapshot(): LexicalScope = if (this is LexicalWritableScope) takeSnapshot() else this
@@ -122,34 +120,34 @@ public fun KtScope.asLexicalScope(): LexicalScope
private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope {
val lexicalScope = lexicalScope.takeSnapshot()
override fun getClassifier(name: Name, location: LookupLocation) = lexicalScope.getClassifier(name, location)
override fun getClassifier(name: Name, location: LookupLocation) = lexicalScope.findClassifier(name, location)
override fun getPackage(name: Name) = lexicalScope.getPackage(name)
override fun getPackage(name: Name) = lexicalScope.findPackage(name)
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
return lexicalScope.collectAllFromImportingScopes { it.getDeclaredVariables(name, location) }
return lexicalScope.collectAllFromImportingScopes { it.getContributedVariables(name, location) }
}
override fun getFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
return lexicalScope.collectAllFromMeAndParent { it.getDeclaredFunctions(name, location) }
return lexicalScope.collectAllFromMeAndParent { it.getContributedFunctions(name, location) }
}
override fun getLocalVariable(name: Name) = lexicalScope.getLocalVariable(name)
override fun getLocalVariable(name: Name) = lexicalScope.findLocalVariable(name)
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(receiverTypes, name, location) }
return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes, name, location) }
}
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionFunctions(receiverTypes, name, location) }
return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes, name, location) }
}
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(receiverTypes) }
return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes) }
}
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionFunctions(receiverTypes) }
return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes) }
}
override fun getContainingDeclaration() = lexicalScope.ownerDescriptor
@@ -157,11 +155,11 @@ private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope {
override fun getDeclarationsByLabel(labelName: Name) = lexicalScope.getDeclarationsByLabel(labelName)
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
return lexicalScope.collectAllFromMeAndParent { it.getDescriptors(kindFilter, nameFilter) }
return lexicalScope.collectAllFromMeAndParent { it.getContributedDescriptors(kindFilter, nameFilter) }
}
override fun getImplicitReceiversHierarchy() = lexicalScope.getImplicitReceiversHierarchy()
override fun getOwnDeclaredDescriptors() = lexicalScope.getDeclaredDescriptors()
override fun getOwnDeclaredDescriptors() = lexicalScope.getContributedDescriptors()
override fun equals(other: Any?) = other is LexicalToKtScopeAdapter && other.lexicalScope == this.lexicalScope
@@ -183,31 +181,31 @@ private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope {
private class MemberScopeToImportingScopeAdapter(override val parent: ImportingScope?, val memberScope: KtScope) : ImportingScope {
override fun getContributedPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name)
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= memberScope.getSyntheticExtensionProperties(receiverTypes, name, location)
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= memberScope.getSyntheticExtensionFunctions(receiverTypes, name, location)
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
= memberScope.getSyntheticExtensionProperties(receiverTypes)
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
= memberScope.getSyntheticExtensionFunctions(receiverTypes)
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= memberScope.getDescriptors(kindFilter, nameFilter)
override val ownerDescriptor: DeclarationDescriptor
get() = memberScope.getContainingDeclaration()
override fun getDeclaredDescriptors() = memberScope.getOwnDeclaredDescriptors()
override fun getContributedDescriptors() = memberScope.getOwnDeclaredDescriptors()
override fun getDeclaredClassifier(name: Name, location: LookupLocation) = memberScope.getClassifier(name, location)
override fun getContributedClassifier(name: Name, location: LookupLocation) = memberScope.getClassifier(name, location)
override fun getDeclaredVariables(name: Name, location: LookupLocation) = memberScope.getProperties(name, location)
override fun getContributedVariables(name: Name, location: LookupLocation) = memberScope.getProperties(name, location)
override fun getDeclaredFunctions(name: Name, location: LookupLocation) = memberScope.getFunctions(name, location)
override fun getContributedFunctions(name: Name, location: LookupLocation) = memberScope.getFunctions(name, location)
override fun equals(other: Any?) = other is MemberScopeToImportingScopeAdapter && other.memberScope == memberScope
@@ -455,7 +455,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
{
// http://youtrack.jetbrains.net/issue/KT-527
VariableDescriptor olderVariable = ScopeUtilsKt.getLocalVariable(context.scope, variableDescriptor.getName());
VariableDescriptor olderVariable = ScopeUtilsKt.findLocalVariable(context.scope, variableDescriptor.getName());
if (olderVariable != null && isLocal(context.scope.getOwnerDescriptor(), olderVariable)) {
PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(variableDescriptor);
context.trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().asString()));
@@ -154,7 +154,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
}
{
VariableDescriptor olderVariable = ScopeUtilsKt.getLocalVariable(scope, propertyDescriptor.getName());
VariableDescriptor olderVariable = ScopeUtilsKt.findLocalVariable(scope, propertyDescriptor.getName());
ExpressionTypingUtils.checkVariableShadowing(context, propertyDescriptor, olderVariable);
}
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.TypeResolver
import org.jetbrains.kotlin.resolve.dataClassUtils.createComponentName
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.utils.getLocalVariable
import org.jetbrains.kotlin.resolve.scopes.utils.findLocalVariable
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
@@ -75,7 +75,7 @@ public class MultiDeclarationResolver(
}
val variableDescriptor = descriptorResolver.resolveLocalVariableDescriptorWithType(writableScope, entry, componentType, context.trace)
val olderVariable = writableScope.getLocalVariable(variableDescriptor.getName())
val olderVariable = writableScope.findLocalVariable(variableDescriptor.getName())
ExpressionTypingUtils.checkVariableShadowing(context, variableDescriptor, olderVariable)
writableScope.addVariableDescriptor(variableDescriptor)
@@ -23,19 +23,19 @@ import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
public class ExplicitImportsScope(private val descriptors: Collection<DeclarationDescriptor>) : ImportingScope by ImportingScope.Empty {
override fun getDeclaredClassifier(name: Name, location: LookupLocation)
override fun getContributedClassifier(name: Name, location: LookupLocation)
= descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<ClassifierDescriptor>()
override fun getContributedPackage(name: Name)
= descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<PackageViewDescriptor>()
override fun getDeclaredVariables(name: Name, location: LookupLocation)
override fun getContributedVariables(name: Name, location: LookupLocation)
= descriptors.filter { it.getName() == name }.filterIsInstance<VariableDescriptor>()
override fun getDeclaredFunctions(name: Name, location: LookupLocation)
override fun getContributedFunctions(name: Name, location: LookupLocation)
= descriptors.filter { it.getName() == name }.filterIsInstance<FunctionDescriptor>()
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= descriptors
override fun printStructure(p: Printer) {
@@ -36,22 +36,18 @@ interface LexicalScope {
* All visible descriptors from current scope possibly filtered by the given name and kind filters
* (that means that the implementation is not obliged to use the filters but may do so when it gives any performance advantage).
*/
open fun getDescriptors(
open fun getContributedDescriptors(
kindFilter: DescriptorKindFilter = DescriptorKindFilter.ALL,
nameFilter: (Name) -> Boolean = KtScope.ALL_NAME_FILTER
): Collection<DeclarationDescriptor> = getDeclaredDescriptors()
): Collection<DeclarationDescriptor> = getContributedDescriptors()
//TODO: rename
fun getDeclaredDescriptors(): Collection<DeclarationDescriptor>
fun getContributedDescriptors(): Collection<DeclarationDescriptor>
//TODO: rename
fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor?
fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor?
//TODO: rename
fun getDeclaredVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor>
fun getContributedVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor>
//TODO: rename
fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
fun printStructure(p: Printer)
@@ -68,13 +64,13 @@ interface LexicalScope {
override val implicitReceiver: ReceiverParameterDescriptor?
get() = null
override fun getDeclaredDescriptors(): Collection<DeclarationDescriptor> = emptyList()
override fun getContributedDescriptors(): Collection<DeclarationDescriptor> = emptyList()
override fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null
override fun getDeclaredVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> = emptyList()
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> = emptyList()
override fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
override fun printStructure(p: Printer) = throw UnsupportedOperationException()
}
@@ -94,28 +90,28 @@ interface ImportingScope : LexicalScope {
fun getContributedPackage(name: Name): PackageViewDescriptor?
fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor>
fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor>
fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor>
fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor>
fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor>
fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor>
fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor>
fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor>
// please, do not override this method
override fun getDeclaredDescriptors(): Collection<DeclarationDescriptor> {
return getDescriptors()
override fun getContributedDescriptors(): Collection<DeclarationDescriptor> {
return getContributedDescriptors(DescriptorKindFilter.ALL, { true })
}
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor>
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor>
object Empty : ImportingScope, LexicalScope by LexicalScope.Empty {
override fun getContributedPackage(name: Name) = null
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> = emptyList()
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> = emptyList()
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> = emptyList()
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> = emptyList()
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> = emptyList()
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> = emptyList()
}
}
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromImportingScopes
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.types.KotlinType
@@ -162,7 +162,7 @@ public class ReferenceVariantsHelper(
descriptors.processAll(implicitReceiverTypes, implicitReceiverTypes, resolutionScope, callType, kindFilter, nameFilter)
// add non-instance members
descriptors.addAll(resolutionScope.getDescriptorsFromAllFiltered(kindFilter exclude DescriptorKindExclude.Extensions, nameFilter))
descriptors.addAll(resolutionScope.collectDescriptorsFiltered(kindFilter exclude DescriptorKindExclude.Extensions, nameFilter))
}
return descriptors
@@ -182,7 +182,7 @@ public class ReferenceVariantsHelper(
val lexicalScope = expression.getParentOfType<KtTypeReference>(strict = true)?.let {
context[BindingContext.LEXICAL_SCOPE, it]
} ?: return emptyList()
return lexicalScope.getDescriptorsFromAllFiltered(kindFilter, nameFilter)
return lexicalScope.collectDescriptorsFiltered(kindFilter, nameFilter)
}
}
@@ -274,7 +274,7 @@ public class ReferenceVariantsHelper(
filterToUse = filterToUse.withKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK)
}
for (descriptor in scope.getDescriptorsFromAllFiltered(filterToUse, nameFilter)) {
for (descriptor in scope.collectDescriptorsFiltered(filterToUse, nameFilter)) {
if (descriptor is ClassDescriptor) {
if (descriptor.modality == Modality.ABSTRACT || descriptor.modality == Modality.SEALED) continue
if (!constructorFilter(descriptor)) continue
@@ -301,19 +301,19 @@ public class ReferenceVariantsHelper(
}
}
for (descriptor in resolutionScope.getDescriptorsFromAllFiltered(kindFilter exclude DescriptorKindExclude.NonExtensions, nameFilter)) {
for (descriptor in resolutionScope.collectDescriptorsFiltered(kindFilter exclude DescriptorKindExclude.NonExtensions, nameFilter)) {
// todo: sometimes resolution scope here is LazyJavaClassMemberScope. see ea.jetbrains.com/browser/ea_problems/72572
process(descriptor as CallableDescriptor)
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) {
for (extension in resolutionScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(receiverTypes) }) {
for (extension in resolutionScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes) }) {
process(extension)
}
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) {
for (extension in resolutionScope.collectAllFromImportingScopes { it.getSyntheticExtensionFunctions(receiverTypes) }) {
for (extension in resolutionScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes) }) {
process(extension)
}
}
@@ -335,6 +335,6 @@ public class ReferenceVariantsHelper(
nameFilter: (Name) -> Boolean
): Collection<DeclarationDescriptor> {
val resolutionScope = context[BindingContext.LEXICAL_SCOPE, expression] ?: return listOf()
return resolutionScope.getDescriptorsFromAllFiltered(DescriptorKindFilter.PACKAGES, nameFilter).filter(visibilityFilter)
return resolutionScope.collectDescriptorsFiltered(DescriptorKindFilter.PACKAGES, nameFilter).filter(visibilityFilter)
}
}
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.*
@@ -84,7 +84,7 @@ fun KotlinType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Bo
if (descriptor == null || descriptor.getName().isSpecial()) return false
if (!checkTypeParameters && descriptor is TypeParameterDescriptor) return true
return scope != null && scope.getClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor
return scope != null && scope.findClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor
}
public fun KotlinType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): KotlinType {
@@ -27,12 +27,12 @@ import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent
public fun LexicalScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor> {
return getVariablesFromImplicitReceivers(name) + collectAllFromMeAndParent { it.getDeclaredVariables(name, NoLookupLocation.FROM_IDE) }
return getVariablesFromImplicitReceivers(name) + collectAllFromMeAndParent { it.getContributedVariables(name, NoLookupLocation.FROM_IDE) }
}
public fun LexicalScope.getAllAccessibleFunctions(name: Name): Collection<FunctionDescriptor> {
return getImplicitReceiversWithInstance().flatMap { it.type.memberScope.getFunctions(name, NoLookupLocation.FROM_IDE) } +
collectAllFromMeAndParent { it.getDeclaredFunctions(name, NoLookupLocation.FROM_IDE) }
collectAllFromMeAndParent { it.getContributedFunctions(name, NoLookupLocation.FROM_IDE) }
}
public fun LexicalScope.getVariablesFromImplicitReceivers(name: Name): Collection<VariableDescriptor> = getImplicitReceiversWithInstance().flatMap {
@@ -89,7 +89,7 @@ public fun ResolutionFacade.resolveImportReference(
val importDirective = KtPsiFactory(project).createImportDirective(ImportPath(fqName, false))
val qualifiedExpressionResolver = this.getFrontendService(moduleDescriptor, QualifiedExpressionResolver::class.java)
return qualifiedExpressionResolver.processImportReference(
importDirective, moduleDescriptor, BindingTraceContext(), packageFragmentForVisibilityCheck = null)?.getDescriptors() ?: emptyList()
importDirective, moduleDescriptor, BindingTraceContext(), packageFragmentForVisibilityCheck = null)?.getContributedDescriptors() ?: emptyList()
}
//NOTE: idea default API returns module search scope for file under module but not in source or production source (for example, test data )
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
import org.jetbrains.kotlin.resolve.scopes.*
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
@@ -86,7 +86,7 @@ public fun resolveKDocLink(resolutionFacade: ResolutionFacade,
var result: Collection<DeclarationDescriptor> = listOf(fromDescriptor)
qualifiedName.forEach { nameComponent ->
val scope = getResolutionScope(resolutionFacade, result.singleOrNull() ?: return emptyList())
result = scope.getDescriptorsFromAllFiltered(nameFilter = { it.asString() == nameComponent})
result = scope.collectDescriptorsFiltered(nameFilter = { it.asString() == nameComponent})
}
return result
@@ -96,7 +96,7 @@ private fun resolveInLocalScope(fromDescriptor: DeclarationDescriptor,
name: String,
resolutionFacade: ResolutionFacade): List<DeclarationDescriptor> {
val scope = getResolutionScope(resolutionFacade, fromDescriptor)
return scope.getDescriptorsFromAllFiltered(nameFilter = { it.asString() == name }).filter {
return scope.collectDescriptorsFiltered(nameFilter = { it.asString() == name }).filter {
it.containingDeclaration == fromDescriptor
}
}
@@ -41,8 +41,8 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.getPackage
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.findPackage
import java.util.*
public class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT }) {
@@ -278,9 +278,9 @@ public class ShortenReferences(val options: (KtElement) -> Options = { Options.D
val scope = bindingContext[BindingContext.LEXICAL_SCOPE, typeReference] ?: return
val name = target.getName()
val targetByName = if (target is ClassifierDescriptor)
scope.getClassifier(name, NoLookupLocation.FROM_IDE)
scope.findClassifier(name, NoLookupLocation.FROM_IDE)
else
scope.getPackage(name)
scope.findPackage(name)
val canShortenNow = targetByName?.asString() == target.asString()
processQualifiedElement(type, target, canShortenNow)
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
class KDocCompletionContributor(): CompletionContributor() {
@@ -107,7 +107,7 @@ class KDocNameCompletionSession(parameters: CompletionParameters,
return true
}
scope.getDescriptorsFromAllFiltered(nameFilter = descriptorNameFilter).filter(::isApplicable).forEach {
scope.collectDescriptorsFiltered(nameFilter = descriptorNameFilter).filter(::isApplicable).forEach {
val element = lookupElementFactory.createLookupElement(it, useReceiverTypes = false, parametersAndTypeGrayed = true)
collector.addElement(object: LookupElementDecorator<LookupElement>(element) {
override fun handleInsert(context: InsertionContext?) {
@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered
import org.jetbrains.kotlin.types.KotlinType
import java.util.*
@@ -74,7 +74,7 @@ class ParameterNameAndTypeCompletion(
public fun addFromImportedClasses(position: PsiElement, bindingContext: BindingContext, visibilityFilter: (DeclarationDescriptor) -> Boolean) {
for ((classNameMatcher, userPrefix) in classNamePrefixMatchers.zip(userPrefixes)) {
val resolutionScope = position.getResolutionScope(bindingContext, resolutionFacade)
val classifiers = resolutionScope.getDescriptorsFromAllFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS, classNameMatcher.asNameFilter())
val classifiers = resolutionScope.collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS, classNameMatcher.asNameFilter())
for (classifier in classifiers) {
if (visibilityFilter(classifier)) {
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent
import org.jetbrains.kotlin.resolve.scopes.utils.getLocalVariable
import org.jetbrains.kotlin.resolve.scopes.utils.findLocalVariable
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import java.util.*
@@ -106,8 +106,8 @@ class MultipleArgumentsItemProvider(
private fun variableInScope(parameter: ValueParameterDescriptor, scope: LexicalScope): VariableDescriptor? {
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)
val variable = scope.getLocalVariable(name)
?: scope.collectAllFromMeAndParent { it.getDeclaredVariables(name, NoLookupLocation.FROM_IDE) }.singleOrNull()
val variable = scope.findLocalVariable(name)
?: scope.collectAllFromMeAndParent { it.getContributedVariables(name, NoLookupLocation.FROM_IDE) }.singleOrNull()
?: scope.getVariableFromImplicitReceivers(name) ?: return null
return if (smartCastCalculator.types(variable).any { KotlinTypeChecker.DEFAULT.isSubtypeOf(it, parameter.getType()) })
variable
@@ -43,7 +43,7 @@ class TypesWithContainsDetector(
private val heuristicSignatures = resolutionFacade.ideService<HeuristicSignatures>()
private val typesWithExtensionContains: Collection<KotlinType> = scope
.collectAllFromMeAndParent { it.getDeclaredFunctions(containsName, NoLookupLocation.FROM_IDE) }
.collectAllFromMeAndParent { it.getContributedFunctions(containsName, NoLookupLocation.FROM_IDE) }
.filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) }
.map { it.getExtensionReceiverParameter()!!.getType() }
@@ -47,7 +47,7 @@ public class IterableTypesDetection(
private val cache = HashMap<FuzzyType, FuzzyType?>()
private val typesWithExtensionIterator: Collection<KotlinType> = scope
.collectAllFromMeAndParent { it.getDeclaredFunctions(iteratorName, NoLookupLocation.FROM_IDE) }
.collectAllFromMeAndParent { it.getContributedFunctions(iteratorName, NoLookupLocation.FROM_IDE) }
.map { it.extensionReceiverParameter }
.filterNotNull()
.map { it.type }
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import java.util.*
@@ -100,7 +100,7 @@ public class NewDeclarationNameValidator(
getAllAccessibleVariables(name).any { !it.isExtension && it.isVisible() }
Target.FUNCTIONS_AND_CLASSES ->
getAllAccessibleFunctions(name).any { !it.isExtension && it.isVisible() } ||
getClassifier(name, NoLookupLocation.FROM_IDE)?.let { it.isVisible() } ?: false
findClassifier(name, NoLookupLocation.FROM_IDE)?.let { it.isVisible() } ?: false
}
}
@@ -231,12 +231,12 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
if (refData.kind == KotlinReferenceData.Kind.EXTENSION_FUNCTION) {
if (fileResolutionScope.parentsWithSelf.any { scope ->
scope.getDeclaredFunctions(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == originalFqName }
scope.getContributedFunctions(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == originalFqName }
}) return null // already imported
}
else if (refData.kind == KotlinReferenceData.Kind.EXTENSION_PROPERTY) {
if (fileResolutionScope.parentsWithSelf.any { scope ->
scope.getDeclaredVariables(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == originalFqName }
scope.getContributedVariables(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == originalFqName }
}) return null // already imported
}
@@ -122,13 +122,13 @@ public class KotlinImportOptimizer() : ImportOptimizer {
return scope.parentsWithSelf.any {
when (target) {
is FunctionDescriptor ->
it.getDeclaredFunctions(target.name, NoLookupLocation.FROM_IDE).contains(target)
it.getContributedFunctions(target.name, NoLookupLocation.FROM_IDE).contains(target)
is PropertyDescriptor ->
it.getDeclaredVariables(target.name, NoLookupLocation.FROM_IDE).contains(target)
it.getContributedVariables(target.name, NoLookupLocation.FROM_IDE).contains(target)
is ClassDescriptor ->
it.getDeclaredClassifier(target.name, NoLookupLocation.FROM_IDE) == target
it.getContributedClassifier(target.name, NoLookupLocation.FROM_IDE) == target
else -> false
}
@@ -221,7 +221,7 @@ public class KotlinImportOptimizer() : ImportOptimizer {
val scope = fileWithImports.getResolutionFacade().getFileResolutionScope(fileWithImports)
for (fqName in classNamesToCheck) {
if (scope.getClassifier(fqName.shortName(), NoLookupLocation.FROM_IDE)?.importableFqName != fqName) {
if (scope.findClassifier(fqName.shortName(), NoLookupLocation.FROM_IDE)?.importableFqName != fqName) {
// add explicit import if failed to import with * (or from current package)
importsToGenerate.add(ImportPath(fqName, false))
@@ -90,7 +90,7 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection()
private fun conflictingSyntheticExtension(descriptor: PropertyDescriptor, importingScope: ImportingScope): SyntheticJavaPropertyDescriptor? {
val extensionReceiverType = descriptor.extensionReceiverParameter?.type ?: return null
return importingScope.collectAllFromImportingScopes {
it.getSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE)
it.getContributedSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE)
}.firstIsInstanceOrNull<SyntheticJavaPropertyDescriptor>()
}
@@ -180,7 +180,7 @@ public class RedundantSamConstructorInspection : AbstractKotlinInspection() {
// SAM adapters for member functions
val resolutionScope = functionCall.getResolutionScope(bindingContext, functionCall.getResolutionFacade())
val syntheticExtensions = resolutionScope.collectAllFromImportingScopes {
it.getSyntheticExtensionFunctions(
it.getContributedSyntheticExtensionFunctions(
containingClass.defaultType.singletonList(),
functionResolvedCall.resultingDescriptor.name,
NoLookupLocation.FROM_IDE)
@@ -124,7 +124,7 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention<KtNa
}
callableDescriptor.getContainingScope()
?.collectAllFromMeAndParent { it.getDeclaredVariables(callableDescriptor.name, NoLookupLocation.FROM_IDE) }
?.collectAllFromMeAndParent { it.getContributedVariables(callableDescriptor.name, NoLookupLocation.FROM_IDE) }
?.firstOrNull()
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
@@ -103,7 +103,7 @@ public class ConvertPropertyToFunctionIntention : JetSelfTargetingIntention<KtPr
if (callable is KtProperty) {
callableDescriptor.getContainingScope()
?.collectAllFromMeAndParent { it.getDeclaredFunctions(callableDescriptor.name, NoLookupLocation.FROM_IDE) }
?.collectAllFromMeAndParent { it.getContributedFunctions(callableDescriptor.name, NoLookupLocation.FROM_IDE) }
?.firstOrNull { it.getValueParameters().isEmpty() }
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
@@ -108,7 +108,7 @@ public abstract class BaseJetVariableMacro extends Macro {
private static Collection<DeclarationDescriptor> getAllVariables(LexicalScope scope) {
Collection<DeclarationDescriptor> result = ContainerUtil.newArrayList();
result.addAll(ScopeUtilsKt.getDescriptorsFromAllFiltered(scope, DescriptorKindFilter.VARIABLES, KtScope.Companion.getALL_NAME_FILTER()));
result.addAll(ScopeUtilsKt.collectDescriptorsFiltered(scope, DescriptorKindFilter.VARIABLES, KtScope.Companion.getALL_NAME_FILTER()));
for (ReceiverParameterDescriptor implicitReceiver : ScopeUtilsKt.getImplicitReceiversHierarchy(scope)) {
result.addAll(implicitReceiver.getType().getMemberScope().getDescriptors(DescriptorKindFilter.VARIABLES, KtScope.Companion.getALL_NAME_FILTER()));
}
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered
class JetAnonymousSuperMacro : Macro() {
override fun getName() = "anonymousSuper"
@@ -73,7 +73,7 @@ class JetAnonymousSuperMacro : Macro() {
val resolutionScope = expression.getResolutionScope(bindingContext, expression.getResolutionFacade())
return resolutionScope
.getDescriptorsFromAllFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS)
.collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS)
.filter { it is ClassDescriptor && it.modality.isOverridable && (it.kind == ClassKind.CLASS || it.kind == ClassKind.INTERFACE) }
.map { DescriptorToSourceUtils.descriptorToDeclaration(it) as PsiNamedElement? }
.filterNotNull()
@@ -66,7 +66,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.scopes.*
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeProjectionImpl
@@ -399,7 +399,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
SourceElement.NO_SOURCE
)
val validator = CollectingNameValidator { scope.getClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null }
val validator = CollectingNameValidator { scope.findClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null }
val parameterNames = KotlinNameSuggester.suggestNamesForTypeParameters(typeParameterCount, validator)
val typeParameters = (0..typeParameterCount - 1).map {
TypeParameterDescriptorImpl.createWithDefaultBound(
@@ -626,7 +626,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
}
}
val validator = CollectingNameValidator { scope.getClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null }
val validator = CollectingNameValidator { scope.findClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null }
val typeParameterNames = allTypeParametersNotInScope.map { KotlinNameSuggester.suggestNameByName(it.getName().asString(), validator) }
return allTypeParametersNotInScope.zip(typeParameterNames).toMap()
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsStatement
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
@@ -82,7 +82,7 @@ internal fun KotlinType.renderLong(typeParameterNameMap: Map<TypeParameterDescri
internal fun getTypeParameterNamesNotInScope(typeParameters: Collection<TypeParameterDescriptor>, scope: LexicalScope): List<TypeParameterDescriptor> {
return typeParameters.filter { typeParameter ->
val classifier = scope.getClassifier(typeParameter.name, NoLookupLocation.FROM_IDE)
val classifier = scope.findClassifier(typeParameter.name, NoLookupLocation.FROM_IDE)
classifier == null || classifier != typeParameter
}
}
@@ -40,7 +40,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
@@ -151,5 +151,5 @@ fun KotlinType.hasTypeParametersToAdd(functionDescriptor: FunctionDescriptor, co
else -> null
} ?: return true
return typeParametersToAdd.any { scope.getClassifier(it.name, NoLookupLocation.FROM_IDE) != it }
return typeParametersToAdd.any { scope.findClassifier(it.name, NoLookupLocation.FROM_IDE) != it }
}
@@ -47,7 +47,7 @@ import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
import org.jetbrains.kotlin.resolve.scopes.utils.getLocalVariable
import org.jetbrains.kotlin.resolve.scopes.utils.findLocalVariable
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addIfNotNull
@@ -674,7 +674,7 @@ private class ConstructedExpressionWrapperWithIntroduceFeature(
}
val name = suggestName { name ->
resolutionScope.getLocalVariable(Name.identifier(name)) == null && !isNameUsed(name)
resolutionScope.findLocalVariable(Name.identifier(name)) == null && !isNameUsed(name)
}
var declaration = psiFactory.createDeclarationByPattern<KtVariableDeclaration>("val $0 = $1", name, value)
@@ -82,7 +82,7 @@ public class JetChangeSignatureData(
val validator = bodyScope?.let { bodyScope ->
CollectingNameValidator(paramNames) { name ->
val identifier = Name.identifier(name)
bodyScope.collectAllFromMeAndParent { it.getDeclaredVariables(identifier, NoLookupLocation.FROM_IDE) }.isEmpty()
bodyScope.collectAllFromMeAndParent { it.getContributedVariables(identifier, NoLookupLocation.FROM_IDE) }.isEmpty()
}
} ?: CollectingNameValidator(paramNames)
val receiverType = baseDescriptor.getExtensionReceiverParameter()?.getType() ?: return null
@@ -680,7 +680,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
}
}
else if (function instanceof KtFunction) {
VariableDescriptor variable = ScopeUtilsKt.getLocalVariable(parametersScope, Name.identifier(parameterName));
VariableDescriptor variable = ScopeUtilsKt.findLocalVariable(parametersScope, Name.identifier(parameterName));
if (variable != null && !(variable instanceof ValueParameterDescriptor)) {
PsiElement conflictElement = DescriptorToSourceUtils.descriptorToDeclaration(variable);
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.TypeProjection
import org.jetbrains.kotlin.types.TypeProjectionImpl
@@ -52,7 +52,7 @@ class KotlinPullUpData(val sourceClass: KtClassOrObject,
val typeParametersInSourceClassContext by lazy {
sourceClassDescriptor.typeConstructor.parameters +
sourceClass.getResolutionScope(sourceClassContext, resolutionFacade)
.getDescriptorsFromAllFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS)
.collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS)
.filterIsInstance<TypeParameterDescriptor>()
}
@@ -42,8 +42,8 @@ import org.jetbrains.kotlin.resolve.scopes.KtScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.getPackage
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.findPackage
import org.jetbrains.kotlin.resolve.scopes.utils.processForMeAndParent
import org.jetbrains.kotlin.utils.addIfNotNull
import java.util.*
@@ -110,13 +110,13 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
val name = target.name
when (target) {
is ClassDescriptor -> {
val classifier = topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE)
val classifier = topLevelScope.findClassifier(name, NoLookupLocation.FROM_IDE)
if (classifier?.importableFqName == targetFqName) return true
}
is FunctionDescriptor -> {
topLevelScope.processForMeAndParent {
if (it.getDeclaredFunctions(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == targetFqName }) {
if (it.getContributedFunctions(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == targetFqName }) {
return true
}
}
@@ -124,7 +124,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
is PropertyDescriptor -> {
topLevelScope.processForMeAndParent {
if (it.getDeclaredVariables(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == targetFqName }) {
if (it.getContributedVariables(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == targetFqName }) {
return true
}
}
@@ -154,8 +154,8 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
// check there is an explicit import of a class/package with the same name already
val conflict = when (target) {
is ClassDescriptor -> topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE)
is PackageViewDescriptor -> topLevelScope.getPackage(name)
is ClassDescriptor -> topLevelScope.findClassifier(name, NoLookupLocation.FROM_IDE)
is PackageViewDescriptor -> topLevelScope.findPackage(name)
else -> null
}
if (conflict != null && imports.any {
@@ -173,7 +173,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
&& when (target) {
// 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 *
is ClassDescriptor -> topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE) == null
is ClassDescriptor -> topLevelScope.findClassifier(name, NoLookupLocation.FROM_IDE) == null
is FunctionDescriptor, is PropertyDescriptor -> true
else -> error("Unknown kind of descriptor to import:$target")
}
@@ -250,7 +250,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
.filter { importedClass ->
isVisible(importedClass)
// check that class is really imported
&& topLevelScope.getClassifier(importedClass.name, NoLookupLocation.FROM_IDE) == importedClass
&& topLevelScope.findClassifier(importedClass.name, NoLookupLocation.FROM_IDE) == importedClass
// and not yet imported explicitly
&& imports.all { it.importPath != ImportPath(importedClass.importableFqName!!, false) }
}
@@ -292,7 +292,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
// check if there is a conflicting class imported with * import
// (not with explicit import - explicit imports are checked before this method invocation)
val classifier = topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE)
val classifier = topLevelScope.findClassifier(name, NoLookupLocation.FROM_IDE)
if (classifier != null && detectNeededImports(listOf(classifier)).isNotEmpty()) {
return ImportDescriptorResult.FAIL
}
@@ -320,7 +320,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
if (importsToCheck.isNotEmpty()) {
val topLevelScope = resolutionFacade.getFileResolutionScope(file)
for (classFqName in importsToCheck) {
val classifier = topLevelScope.getClassifier(classFqName.shortName(), NoLookupLocation.FROM_IDE)
val classifier = topLevelScope.findClassifier(classFqName.shortName(), NoLookupLocation.FROM_IDE)
if (classifier?.importableFqName != classFqName) {
addImport(classFqName, false) // restore explicit import
}