Package-level declarations

Types

Link copied to clipboard

Base exception for all design-by-contract violations.

Link copied to clipboard
interface HasInvariant

Interface for classes that support invariant checks.

Link copied to clipboard

Exception thrown when an invariant check fails.

Link copied to clipboard

Exception thrown when a postcondition check fails.

Link copied to clipboard

Exception thrown when a precondition check fails.

Functions

Link copied to clipboard
inline fun <T : HasInvariant> T.checkInvariant(messageExpr: () -> String): T
inline fun <T : HasInvariant> T.checkInvariant(message: String): T

Validate the invariant condition immediately if invariant checks are enabled.

inline fun <T : HasInvariant, R> T.checkInvariant(message: String, block: T.() -> R): R

Execute block and validate the invariant condition before and after execution.

Link copied to clipboard
inline fun postcondition(check: Boolean, messageExpr: () -> String)
inline fun postcondition(message: String, check: Boolean)

Validate that check is true.

inline fun postcondition(checkExpr: () -> Boolean, messageExpr: () -> String)
inline fun postcondition(message: String, checkExpr: () -> Boolean)

Validate that checkExpr returns true when postcondition checks are enabled.

Link copied to clipboard
inline fun postconditionFailed(messageExpr: () -> String): Nothing
inline fun postconditionFailed(message: String): Nothing

Throw a PostConditionException unconditionally.

Link copied to clipboard
inline fun <T> postconditionNotNull(obj: T?, messageExpr: () -> String): T
inline fun <T> postconditionNotNull(obj: T?, exception: String): T

Validate that obj is not null.

Link copied to clipboard
inline fun precondition(check: Boolean, messageExpr: () -> String)
inline fun precondition(check: Boolean, exception: String)

Validate that check is true.

inline fun precondition(checkExpr: () -> Boolean, messageExpr: () -> String)
inline fun precondition(message: String, checkExpr: () -> Boolean)

Validate that checkExpr returns true when precondition checks are enabled.

Link copied to clipboard
inline fun preconditionFailed(messageExpr: () -> String): Nothing
inline fun preconditionFailed(exception: String): Nothing

Throw a PreConditionException unconditionally.

Link copied to clipboard
inline fun <T> preconditionNotNull(obj: T?, messageExpr: () -> String): T
inline fun <T> preconditionNotNull(obj: T?, exception: String): T

Validate that obj is not null.