Permalink
Browse files

SI-7261 Implicit conversion of BooleanSetting to Boolean and BooleanFlag

This allows a more compact expression `if (settings.debug)` instead of
`if (settings.debug.value)` and similarly `render(..., printIds = settings.uniqid, ...)`.
  • Loading branch information...
1 parent 79b18cc commit e073975997a5291cbe76ea15e797a6783bb4d544 @som-snytt som-snytt committed with paulp Mar 25, 2013
@@ -163,6 +163,8 @@ trait Printers { self: Universe =>
import scala.language.implicitConversions
implicit def booleanToBooleanFlag(value: Boolean): BooleanFlag = BooleanFlag(Some(value))
implicit def optionToBooleanFlag(value: Option[Boolean]): BooleanFlag = BooleanFlag(value)
+ import scala.reflect.internal.settings.MutableSettings
+ implicit def settingToBooleanFlag(setting: MutableSettings#BooleanSetting): BooleanFlag = BooleanFlag(Some(setting.value))
}
/** @group Printers */
@@ -49,3 +49,8 @@ abstract class MutableSettings extends AbsSettings {
def XfullLubs: BooleanSetting
def breakCycles: BooleanSetting
}
+object MutableSettings {
+ import scala.language.implicitConversions
+ /** Support the common use case, `if (settings.debug) println("Hello, martin.")` */
+ @inline implicit def reflectSettingToBoolean(s: MutableSettings#BooleanSetting): Boolean = s.value
+}

0 comments on commit e073975

Please sign in to comment.