mirror of https://github.com/sbt/sbt.git
use given instead of implicit object
This commit is contained in:
parent
f11d9d76f0
commit
d8705bbac0
|
|
@ -20,10 +20,10 @@ private[sbt] final case class DynamicInput(
|
||||||
forceTrigger: Boolean
|
forceTrigger: Boolean
|
||||||
)
|
)
|
||||||
private[sbt] object DynamicInput {
|
private[sbt] object DynamicInput {
|
||||||
implicit object ordering extends Ordering[DynamicInput] {
|
given ordering: Ordering[DynamicInput] = new Ordering[DynamicInput] {
|
||||||
private given globOrdering: Ordering[Glob] = Glob.ordering
|
private given globOrdering: Ordering[Glob] = Glob.ordering
|
||||||
private implicit object fileStamperOrdering extends Ordering[FileStamper] {
|
val fileStamperOrdering: Ordering[FileStamper] = (left: FileStamper, right: FileStamper) =>
|
||||||
override def compare(left: FileStamper, right: FileStamper): Int = left match {
|
left match {
|
||||||
case FileStamper.Hash =>
|
case FileStamper.Hash =>
|
||||||
right match {
|
right match {
|
||||||
case FileStamper.Hash => 0
|
case FileStamper.Hash => 0
|
||||||
|
|
@ -35,7 +35,6 @@ private[sbt] object DynamicInput {
|
||||||
case _ => 1
|
case _ => 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
override def compare(left: DynamicInput, right: DynamicInput): Int = {
|
override def compare(left: DynamicInput, right: DynamicInput): Int = {
|
||||||
globOrdering.compare(left.glob, right.glob) match {
|
globOrdering.compare(left.glob, right.glob) match {
|
||||||
case 0 => fileStamperOrdering.compare(left.fileStamper, right.fileStamper)
|
case 0 => fileStamperOrdering.compare(left.fileStamper, right.fileStamper)
|
||||||
|
|
|
||||||
|
|
@ -134,13 +134,11 @@ object Watch {
|
||||||
* [[CancelWatch]] is higher priority than [[ContinueWatch]].
|
* [[CancelWatch]] is higher priority than [[ContinueWatch]].
|
||||||
*/
|
*/
|
||||||
object Action {
|
object Action {
|
||||||
implicit object ordering extends Ordering[Action] {
|
given ordering: Ordering[Action] = {
|
||||||
override def compare(left: Action, right: Action): Int = (left, right) match {
|
case (a: ContinueWatch, b: ContinueWatch) => ContinueWatch.ordering.compare(a, b)
|
||||||
case (a: ContinueWatch, b: ContinueWatch) => ContinueWatch.ordering.compare(a, b)
|
case (_: ContinueWatch, _: CancelWatch) => 1
|
||||||
case (_: ContinueWatch, _: CancelWatch) => 1
|
case (a: CancelWatch, b: CancelWatch) => CancelWatch.ordering.compare(a, b)
|
||||||
case (a: CancelWatch, b: CancelWatch) => CancelWatch.ordering.compare(a, b)
|
case (_: CancelWatch, _: ContinueWatch) => -1
|
||||||
case (_: CancelWatch, _: ContinueWatch) => -1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,13 +161,12 @@ object Watch {
|
||||||
/**
|
/**
|
||||||
* A default `Ordering` for [[ContinueWatch]]. [[Trigger]] is higher priority than [[Ignore]].
|
* A default `Ordering` for [[ContinueWatch]]. [[Trigger]] is higher priority than [[Ignore]].
|
||||||
*/
|
*/
|
||||||
implicit object ordering extends Ordering[ContinueWatch] {
|
given ordering: Ordering[ContinueWatch] = (left: ContinueWatch, right: ContinueWatch) =>
|
||||||
override def compare(left: ContinueWatch, right: ContinueWatch): Int = left match {
|
left match {
|
||||||
case ShowOptions => if (right == ShowOptions) 0 else -1
|
case ShowOptions => if (right == ShowOptions) 0 else -1
|
||||||
case Ignore => if (right == Ignore) 0 else 1
|
case Ignore => if (right == Ignore) 0 else 1
|
||||||
case Trigger => if (right == Trigger) 0 else if (right == ShowOptions) 1 else -1
|
case Trigger => if (right == Trigger) 0 else if (right == ShowOptions) 1 else -1
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -182,8 +179,8 @@ object Watch {
|
||||||
* is reflected by the ordering of the case statements in the [[ordering.compare]] method,
|
* is reflected by the ordering of the case statements in the [[ordering.compare]] method,
|
||||||
* e.g. [[Custom]] is higher priority than [[HandleError]].
|
* e.g. [[Custom]] is higher priority than [[HandleError]].
|
||||||
*/
|
*/
|
||||||
implicit object ordering extends Ordering[CancelWatch] {
|
given ordering: Ordering[CancelWatch] = { (left: CancelWatch, right: CancelWatch) =>
|
||||||
override def compare(left: CancelWatch, right: CancelWatch): Int = left match {
|
left match {
|
||||||
// Note that a negative return value means the left CancelWatch is preferred to the right
|
// Note that a negative return value means the left CancelWatch is preferred to the right
|
||||||
// CancelWatch while the inverse is true for a positive return value. This logic could
|
// CancelWatch while the inverse is true for a positive return value. This logic could
|
||||||
// likely be simplified, but the pattern matching approach makes it very clear what happens
|
// likely be simplified, but the pattern matching approach makes it very clear what happens
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue