From c0901ec8a615c9125d2809062ae023a30dc0ff88 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Wed, 22 Oct 2014 19:18:37 +0400 Subject: [PATCH] Improve assertion message --- .../createFunction/CreateCallableFromUsageFix.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateCallableFromUsageFix.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateCallableFromUsageFix.kt index 1cd49e4f456..4210c01c134 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateCallableFromUsageFix.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateCallableFromUsageFix.kt @@ -14,19 +14,20 @@ import org.jetbrains.jet.lang.psi.JetClassBody import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.* import org.jetbrains.jet.lang.psi.JetExpression import org.jetbrains.jet.utils.addToStdlib.singletonOrEmptyList +import org.jetbrains.jet.utils.addToStdlib.singletonOrEmptyList +import java.util.HashSet +import org.jetbrains.jet.lang.psi.JetElement public class CreateCallableFromUsageFix( originalExpression: JetExpression, val callableInfos: List) : CreateFromUsageFixBase(originalExpression) { { if (callableInfos.size > 1) { - val callableInfo = callableInfos.first() + val receiverSet = callableInfos.mapTo(HashSet()) { it.receiverTypeInfo } + if (receiverSet.size > 1) throw AssertionError("All functions must have common receiver: $receiverSet") - val receiver = callableInfo.receiverTypeInfo - if (!callableInfos.all { it.receiverTypeInfo == receiver }) throw AssertionError("All functions must have common receiver") - - val containers = callableInfo.possibleContainers - if (!callableInfos.all { it.possibleContainers == containers }) throw AssertionError("All functions must have common containers") + val possibleContainerSet = callableInfos.mapTo(HashSet>()) { it.possibleContainers } + if (possibleContainerSet.size > 1) throw AssertionError("All functions must have common containers: $possibleContainerSet") } } @@ -43,7 +44,7 @@ public class CreateCallableFromUsageFix( } override fun invoke(project: Project, editor: Editor?, file: JetFile?) { - val callableInfo = callableInfos.firstOrNull() ?: return + val callableInfo = callableInfos.first() val callableBuilder = CallableBuilderConfiguration(callableInfos, element as JetExpression, file!!, editor!!).createBuilder()