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)