Make all assert inline. Field _Assertions.ENABLED instead of property ASSERTIONS_ENABLED

This commit is contained in:
Ilya Gorbunov
2016-01-29 21:34:52 +03:00
parent c763b592a5
commit dacf25fdec
2 changed files with 9 additions and 7 deletions
@@ -60,7 +60,7 @@ public class FileTreeWalk private constructor(
/** Abstract class that encapsulates directory visiting in some order, beginning from a given [rootDir] */
private abstract class DirectoryState(rootDir: File): WalkState(rootDir) {
init {
if (ASSERTIONS_ENABLED)
if (_Assertions.ENABLED)
assert(rootDir.isDirectory) { "rootDir must be verified to be directory beforehand." }
}
}
@@ -207,7 +207,7 @@ public class FileTreeWalk private constructor(
private var visited: Boolean = false
init {
if (ASSERTIONS_ENABLED)
if (_Assertions.ENABLED)
assert(rootFile.isFile) { "rootFile must be verified to be file beforehand." }
}
@@ -3,15 +3,17 @@
package kotlin
private object _Assertions
internal val ASSERTIONS_ENABLED: Boolean = _Assertions.javaClass.desiredAssertionStatus()
internal object _Assertions {
@JvmField
internal val ENABLED: Boolean = javaClass.desiredAssertionStatus()
}
/**
* Throws an [AssertionError] if the [value] is false
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
*/
public fun assert(value: Boolean) {
@kotlin.internal.InlineOnly
public inline fun assert(value: Boolean) {
assert(value) { "Assertion failed" }
}
@@ -22,7 +24,7 @@ public fun assert(value: Boolean) {
@kotlin.internal.InlineOnly
public inline fun assert(value: Boolean, lazyMessage: () -> Any) {
@Suppress("INVISIBLE_MEMBER_FROM_INLINE")
if (ASSERTIONS_ENABLED) {
if (_Assertions.ENABLED) {
if (!value) {
val message = lazyMessage()
throw AssertionError(message)