Minor refactoring
This commit is contained in:
@@ -121,11 +121,11 @@ private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope {
|
|||||||
override fun getClassifier(name: Name, location: LookupLocation) = lexicalScope.getClassifier(name, location)
|
override fun getClassifier(name: Name, location: LookupLocation) = lexicalScope.getClassifier(name, location)
|
||||||
|
|
||||||
override fun getPackage(name: Name): PackageViewDescriptor? {
|
override fun getPackage(name: Name): PackageViewDescriptor? {
|
||||||
return lexicalScope.findFirstFromMeAndParent { (it as? ImportingScope)?.getPackage(name) }
|
return lexicalScope.findFirstFromImportingScopes { it.getPackage(name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
|
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
|
||||||
return lexicalScope.collectAllFromMeAndParent { (it as? ImportingScope)?.getDeclaredVariables(name, location) ?: emptyList() }
|
return lexicalScope.collectAllFromImportingScopes { it.getDeclaredVariables(name, location) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
override fun getFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||||
@@ -135,27 +135,19 @@ private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope {
|
|||||||
override fun getLocalVariable(name: Name) = lexicalScope.getLocalVariable(name)
|
override fun getLocalVariable(name: Name) = lexicalScope.getLocalVariable(name)
|
||||||
|
|
||||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||||
return lexicalScope.collectAllFromMeAndParent {
|
return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(receiverTypes, name, location) }
|
||||||
(it as? ImportingScope)?.getSyntheticExtensionProperties(receiverTypes, name, location) ?: emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||||
return lexicalScope.collectAllFromMeAndParent {
|
return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionFunctions(receiverTypes, name, location) }
|
||||||
(it as? ImportingScope)?.getSyntheticExtensionFunctions(receiverTypes, name, location) ?: emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
|
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
|
||||||
return lexicalScope.collectAllFromMeAndParent {
|
return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(receiverTypes) }
|
||||||
(it as? ImportingScope)?.getSyntheticExtensionProperties(receiverTypes) ?: emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
|
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
|
||||||
return lexicalScope.collectAllFromMeAndParent {
|
return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionFunctions(receiverTypes) }
|
||||||
(it as? ImportingScope)?.getSyntheticExtensionFunctions(receiverTypes) ?: emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContainingDeclaration() = lexicalScope.ownerDescriptor
|
override fun getContainingDeclaration() = lexicalScope.ownerDescriptor
|
||||||
@@ -271,6 +263,16 @@ inline fun <T: Any> LexicalScope.findFirstFromMeAndParent(fetch: (LexicalScope)
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun <T: Any> LexicalScope.collectAllFromImportingScopes(
|
||||||
|
collect: (ImportingScope) -> Collection<T>
|
||||||
|
): Collection<T> {
|
||||||
|
return collectAllFromMeAndParent { if (it is ImportingScope) collect(it) else emptyList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T: Any> LexicalScope.findFirstFromImportingScopes(fetch: (ImportingScope) -> T?): T? {
|
||||||
|
return findFirstFromMeAndParent { if (it is ImportingScope) fetch(it) else null }
|
||||||
|
}
|
||||||
|
|
||||||
fun LexicalScope.addImportScope(importScope: KtScope): LexicalScope {
|
fun LexicalScope.addImportScope(importScope: KtScope): LexicalScope {
|
||||||
if (this is ImportingScope) {
|
if (this is ImportingScope) {
|
||||||
return importScope.memberScopeAsImportingScope(this)
|
return importScope.memberScopeAsImportingScope(this)
|
||||||
|
|||||||
@@ -40,9 +40,8 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
|
|||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.findFirstFromMeAndParent
|
import org.jetbrains.kotlin.resolve.scopes.utils.findFirstFromImportingScopes
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
|
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -281,7 +280,7 @@ public class ShortenReferences(val options: (KtElement) -> Options = { Options.D
|
|||||||
val targetByName = if (target is ClassifierDescriptor)
|
val targetByName = if (target is ClassifierDescriptor)
|
||||||
scope.getClassifier(name, NoLookupLocation.FROM_IDE)
|
scope.getClassifier(name, NoLookupLocation.FROM_IDE)
|
||||||
else
|
else
|
||||||
scope.findFirstFromMeAndParent { (it as? ImportingScope)?.getPackage(name) }
|
scope.findFirstFromImportingScopes { it.getPackage(name) }
|
||||||
val canShortenNow = targetByName?.asString() == target.asString()
|
val canShortenNow = targetByName?.asString() == target.asString()
|
||||||
|
|
||||||
processQualifiedElement(type, target, canShortenNow)
|
processQualifiedElement(type, target, canShortenNow)
|
||||||
|
|||||||
+4
-8
@@ -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.calls.model.isReallySuccess
|
||||||
import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden
|
import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent
|
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromImportingScopes
|
||||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
|
|
||||||
@@ -89,13 +89,9 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection()
|
|||||||
|
|
||||||
private fun conflictingSyntheticExtension(descriptor: PropertyDescriptor, importingScope: ImportingScope): SyntheticJavaPropertyDescriptor? {
|
private fun conflictingSyntheticExtension(descriptor: PropertyDescriptor, importingScope: ImportingScope): SyntheticJavaPropertyDescriptor? {
|
||||||
val extensionReceiverType = descriptor.extensionReceiverParameter?.type ?: return null
|
val extensionReceiverType = descriptor.extensionReceiverParameter?.type ?: return null
|
||||||
return importingScope
|
return importingScope.collectAllFromImportingScopes {
|
||||||
.collectAllFromMeAndParent {
|
it.getSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE)
|
||||||
(it as? ImportingScope)
|
}.firstIsInstanceOrNull<SyntheticJavaPropertyDescriptor>()
|
||||||
?.getSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE)
|
|
||||||
?: emptyList()
|
|
||||||
}
|
|
||||||
.firstIsInstanceOrNull<SyntheticJavaPropertyDescriptor>()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isSameAsSynthetic(declaration: KtProperty, syntheticProperty: SyntheticJavaPropertyDescriptor): Boolean {
|
private fun isSameAsSynthetic(declaration: KtProperty, syntheticProperty: SyntheticJavaPropertyDescriptor): Boolean {
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
|
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromImportingScopes
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent
|
|
||||||
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
|
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||||
@@ -180,12 +179,11 @@ public class RedundantSamConstructorInspection : AbstractKotlinInspection() {
|
|||||||
|
|
||||||
// SAM adapters for member functions
|
// SAM adapters for member functions
|
||||||
val resolutionScope = functionCall.getResolutionScope(bindingContext, functionCall.getResolutionFacade())
|
val resolutionScope = functionCall.getResolutionScope(bindingContext, functionCall.getResolutionFacade())
|
||||||
val syntheticExtensions = resolutionScope.collectAllFromMeAndParent {
|
val syntheticExtensions = resolutionScope.collectAllFromImportingScopes {
|
||||||
(it as? ImportingScope)?.getSyntheticExtensionFunctions(
|
it.getSyntheticExtensionFunctions(
|
||||||
containingClass.defaultType.singletonList(),
|
containingClass.defaultType.singletonList(),
|
||||||
functionResolvedCall.resultingDescriptor.name,
|
functionResolvedCall.resultingDescriptor.name,
|
||||||
NoLookupLocation.FROM_IDE
|
NoLookupLocation.FROM_IDE)
|
||||||
) ?: emptyList()
|
|
||||||
}
|
}
|
||||||
for (syntheticExtension in syntheticExtensions) {
|
for (syntheticExtension in syntheticExtensions) {
|
||||||
val samAdapter = syntheticExtension as? SamAdapterExtensionFunctionDescriptor ?: continue
|
val samAdapter = syntheticExtension as? SamAdapterExtensionFunctionDescriptor ?: continue
|
||||||
|
|||||||
Reference in New Issue
Block a user