Added utility functions for synthetic extensions in scope

This commit is contained in:
Valentin Kipyatkov
2015-10-25 12:34:07 +03:00
parent c09cf63424
commit ed6f845377
4 changed files with 29 additions and 21 deletions
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromImportingScopes
import org.jetbrains.kotlin.resolve.scopes.utils.collectSyntheticExtensionProperties
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
@@ -56,7 +56,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
val owner = getterOrSetter.getContainingDeclaration() as? ClassDescriptor ?: return null
val originalGetterOrSetter = getterOrSetter.original
return resolutionScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(listOf(owner.defaultType)) }
return resolutionScope.collectSyntheticExtensionProperties(listOf(owner.defaultType))
.filterIsInstance<SyntheticJavaPropertyDescriptor>()
.firstOrNull { originalGetterOrSetter == it.getMethod || originalGetterOrSetter == it.setMethod }
}
@@ -117,6 +117,18 @@ public fun LexicalScope.findFunction(name: Name, location: LookupLocation, predi
return null
}
public fun LexicalScope.collectSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes, name, location) }
public fun LexicalScope.collectSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes, name, location) }
public fun LexicalScope.collectSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
= collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes) }
public fun LexicalScope.collectSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
= collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes) }
public fun LexicalScope.takeSnapshot(): LexicalScope = if (this is LexicalWritableScope) takeSnapshot() else this
public fun LexicalScope.asKtScope(): KtScope {
@@ -153,21 +165,17 @@ private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope {
override fun getLocalVariable(name: Name) = lexicalScope.findLocalVariable(name)
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes, name, location) }
}
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= lexicalScope.collectSyntheticExtensionProperties(receiverTypes, name, location)
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes, name, location) }
}
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= lexicalScope.collectSyntheticExtensionFunctions(receiverTypes, name, location)
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes) }
}
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
= lexicalScope.collectSyntheticExtensionProperties(receiverTypes)
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes) }
}
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
= lexicalScope.collectSyntheticExtensionFunctions(receiverTypes)
override fun getContainingDeclaration() = lexicalScope.ownerDescriptor
@@ -37,8 +37,9 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
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.collectDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.collectSyntheticExtensionFunctions
import org.jetbrains.kotlin.resolve.scopes.utils.collectSyntheticExtensionProperties
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.types.KotlinType
@@ -307,13 +308,13 @@ public class ReferenceVariantsHelper(
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) {
for (extension in resolutionScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes) }) {
for (extension in resolutionScope.collectSyntheticExtensionProperties(receiverTypes)) {
process(extension)
}
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) {
for (extension in resolutionScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes) }) {
for (extension in resolutionScope.collectSyntheticExtensionFunctions(receiverTypes)) {
process(extension)
}
}
@@ -50,7 +50,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromImportingScopes
import org.jetbrains.kotlin.resolve.scopes.utils.collectSyntheticExtensionProperties
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
@@ -89,9 +89,8 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection()
private fun conflictingSyntheticExtension(descriptor: PropertyDescriptor, importingScope: ImportingScope): SyntheticJavaPropertyDescriptor? {
val extensionReceiverType = descriptor.extensionReceiverParameter?.type ?: return null
return importingScope.collectAllFromImportingScopes {
it.getContributedSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE)
}.firstIsInstanceOrNull<SyntheticJavaPropertyDescriptor>()
return importingScope.collectSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE)
.firstIsInstanceOrNull<SyntheticJavaPropertyDescriptor>()
}
private fun isSameAsSynthetic(declaration: KtProperty, syntheticProperty: SyntheticJavaPropertyDescriptor): Boolean {