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

izumi.reflect.internal.fundamentals.platform.assertions.IzAssert.scala Maven / Gradle / Ivy

There is a newer version: 2.3.10
Show newest version
package izumi.reflect.internal.fundamentals.platform.assertions

import izumi.reflect.DebugProperties
import izumi.reflect.internal.fundamentals.platform.strings.IzString.toRichString

import java.util.concurrent.atomic.AtomicBoolean

private[reflect] object IzAssert {
  private[reflect] final def apply(assertion: => Boolean): Unit = apply(assertion, "")
  private[reflect] final def apply(assertion: => Boolean, clue: => Any): Unit = {
    if (statusAsserts()) {
      if (!assertion) throw new IllegalArgumentException(s"IzAssert failed: $clue")
    }
  }

  /** caching is enabled by default for runtime light type tag creation */
  private[this] val enabled: AtomicBoolean = {
    val prop = System.getProperty(DebugProperties.`izumi.reflect.debug.macro.rtti.assertions`).asBoolean().getOrElse(false)
    new AtomicBoolean(prop)
  }
  // for calling within a debugger or tests
  private[reflect] def enableAsserts(): Unit = enabled.set(true)
  private[reflect] def disableAsserts(): Unit = enabled.set(false)
  private[reflect] def statusAsserts(): Boolean = enabled.get()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy