From 8006f16e46ae2860d3fae45b36e37e82a3886f57 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 19 Nov 2014 13:59:30 +0300 Subject: [PATCH] Minor code refactorings --- .../jet/plugin/util/extensionsUtils.kt | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/util/extensionsUtils.kt b/idea/src/org/jetbrains/jet/plugin/util/extensionsUtils.kt index 4ec329bdf9c..64c7024d2b4 100644 --- a/idea/src/org/jetbrains/jet/plugin/util/extensionsUtils.kt +++ b/idea/src/org/jetbrains/jet/plugin/util/extensionsUtils.kt @@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.types.Variance import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsUtil import org.jetbrains.jet.lang.resolve.name.Name +import org.jetbrains.jet.utils.addIfNotNull import java.util.HashSet public fun CallableDescriptor.isExtensionCallable(receivers: Collection, @@ -52,13 +53,8 @@ public fun CallableDescriptor.isExtensionCallable( return false } - val types = SmartCastUtils.getSmartCastVariants(receiver, bindingContext, dataFlowInfo) - - for (type in types) { - if (checkReceiverResolution(receiver, type, this)) return true - } - - return false + return SmartCastUtils.getSmartCastVariants(receiver, bindingContext, dataFlowInfo) + .any { checkReceiverResolution(receiver, it, this) } } private fun checkReceiverResolution(receiverArgument: ReceiverValue, receiverType: JetType, callableDescriptor: CallableDescriptor): Boolean { @@ -73,7 +69,8 @@ private fun checkReceiverResolution(receiverArgument: ReceiverValue, receiverTyp return false } - val typeNamesInReceiver = collectUsedTypeNames(receiverParameter.getType()) + val typeNamesInReceiver = HashSet() + typeNamesInReceiver.addUsedTypeNames(receiverParameter.getType()) val constraintSystem = ConstraintSystemImpl() val typeVariables = LinkedHashMap() @@ -88,18 +85,12 @@ private fun checkReceiverResolution(receiverArgument: ReceiverValue, receiverTyp return constraintSystem.getStatus().isSuccessful() && ConstraintsUtil.checkBoundsAreSatisfied(constraintSystem, true) } -private fun collectUsedTypeNames(jetType: JetType): Set { - val typeNames = HashSet() - +private fun MutableSet.addUsedTypeNames(jetType: JetType) { val descriptor = jetType.getConstructor().getDeclarationDescriptor() - if (descriptor != null) { - typeNames.add(descriptor.getName()) - } + addIfNotNull(descriptor?.getName()) for (argument in jetType.getArguments()) { - typeNames.addAll(collectUsedTypeNames(argument.getType())) + addUsedTypeNames(argument.getType()) } - - return typeNames }