Improve assertion message

This commit is contained in:
Alexey Sedunov
2014-10-22 19:18:37 +04:00
parent d5e80cae1b
commit c0901ec8a6
@@ -14,19 +14,20 @@ import org.jetbrains.jet.lang.psi.JetClassBody
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.* import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.*
import org.jetbrains.jet.lang.psi.JetExpression import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.utils.addToStdlib.singletonOrEmptyList 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( public class CreateCallableFromUsageFix(
originalExpression: JetExpression, originalExpression: JetExpression,
val callableInfos: List<CallableInfo>) : CreateFromUsageFixBase(originalExpression) { val callableInfos: List<CallableInfo>) : CreateFromUsageFixBase(originalExpression) {
{ {
if (callableInfos.size > 1) { if (callableInfos.size > 1) {
val callableInfo = callableInfos.first() val receiverSet = callableInfos.mapTo(HashSet<TypeInfo>()) { it.receiverTypeInfo }
if (receiverSet.size > 1) throw AssertionError("All functions must have common receiver: $receiverSet")
val receiver = callableInfo.receiverTypeInfo val possibleContainerSet = callableInfos.mapTo(HashSet<List<JetElement>>()) { it.possibleContainers }
if (!callableInfos.all { it.receiverTypeInfo == receiver }) throw AssertionError("All functions must have common receiver") if (possibleContainerSet.size > 1) throw AssertionError("All functions must have common containers: $possibleContainerSet")
val containers = callableInfo.possibleContainers
if (!callableInfos.all { it.possibleContainers == containers }) throw AssertionError("All functions must have common containers")
} }
} }
@@ -43,7 +44,7 @@ public class CreateCallableFromUsageFix(
} }
override fun invoke(project: Project, editor: Editor?, file: JetFile?) { 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() val callableBuilder = CallableBuilderConfiguration(callableInfos, element as JetExpression, file!!, editor!!).createBuilder()