All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.peanuuutz.fork.ui.inspection.Inspector.kt Maven / Gradle / Ivy

The newest version!
package net.peanuuutz.fork.ui.inspection

import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

interface Inspector {
    fun push(phase: String)

    fun push(inspectable: Inspectable) {
        push(inspectable.name)
    }

    fun pop()

    fun reset()
}

inline fun  Inspector.inspect(
    phase: String,
    block: () -> R
): R {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }

    push(phase)
    val result = block()
    pop()
    return result
}

inline fun  Inspector.inspect(
    inspectable: Inspectable,
    block: () -> R
): R {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }

    push(inspectable)
    val result = block()
    pop()
    return result
}

fun Inspector.swap(phase: String) {
    pop()
    push(phase)
}

fun Inspector.swap(inspectable: Inspectable) {
    pop()
    push(inspectable)
}

var debugInspector: Boolean = true




© 2015 - 2024 Weber Informatics LLC | Privacy Policy