Add contract to checkWithAttachment
- This way it is more convenient to use with null checks
This commit is contained in:
committed by
Roman Golyshev
parent
0ff45f1cc4
commit
8fd16f4a39
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.utils
|
||||
|
||||
import com.intellij.openapi.diagnostic.Attachment
|
||||
import com.intellij.openapi.diagnostic.ExceptionWithAttachments
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttachments {
|
||||
private val attachments = mutableListOf<Attachment>()
|
||||
@@ -27,7 +29,10 @@ open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttac
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun checkWithAttachment(value: Boolean, lazyMessage: () -> String, attachments: (KotlinExceptionWithAttachments) -> Unit = {}) {
|
||||
contract { returns() implies(value) }
|
||||
|
||||
if (!value) {
|
||||
val e = KotlinExceptionWithAttachments(lazyMessage())
|
||||
attachments(e)
|
||||
|
||||
Reference in New Issue
Block a user