use given instead of implicit object

This commit is contained in:
xuwei-k 2024-11-18 17:01:06 +09:00
parent f11d9d76f0
commit d8705bbac0
2 changed files with 12 additions and 16 deletions

View File

@ -20,10 +20,10 @@ private[sbt] final case class DynamicInput(
forceTrigger: Boolean
)
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 implicit object fileStamperOrdering extends Ordering[FileStamper] {
override def compare(left: FileStamper, right: FileStamper): Int = left match {
val fileStamperOrdering: Ordering[FileStamper] = (left: FileStamper, right: FileStamper) =>
left match {
case FileStamper.Hash =>
right match {
case FileStamper.Hash => 0
@ -35,7 +35,6 @@ private[sbt] object DynamicInput {
case _ => 1
}
}
}
override def compare(left: DynamicInput, right: DynamicInput): Int = {
globOrdering.compare(left.glob, right.glob) match {
case 0 => fileStamperOrdering.compare(left.fileStamper, right.fileStamper)

View File

@ -134,13 +134,11 @@ object Watch {
* [[CancelWatch]] is higher priority than [[ContinueWatch]].
*/
object Action {
implicit object ordering extends Ordering[Action] {
override def compare(left: Action, right: Action): Int = (left, right) match {
case (a: ContinueWatch, b: ContinueWatch) => ContinueWatch.ordering.compare(a, b)
case (_: ContinueWatch, _: CancelWatch) => 1
case (a: CancelWatch, b: CancelWatch) => CancelWatch.ordering.compare(a, b)
case (_: CancelWatch, _: ContinueWatch) => -1
}
given ordering: Ordering[Action] = {
case (a: ContinueWatch, b: ContinueWatch) => ContinueWatch.ordering.compare(a, b)
case (_: ContinueWatch, _: CancelWatch) => 1
case (a: CancelWatch, b: CancelWatch) => CancelWatch.ordering.compare(a, b)
case (_: CancelWatch, _: ContinueWatch) => -1
}
}
@ -163,13 +161,12 @@ object Watch {
/**
* A default `Ordering` for [[ContinueWatch]]. [[Trigger]] is higher priority than [[Ignore]].
*/
implicit object ordering extends Ordering[ContinueWatch] {
override def compare(left: ContinueWatch, right: ContinueWatch): Int = left match {
given ordering: Ordering[ContinueWatch] = (left: ContinueWatch, right: ContinueWatch) =>
left match {
case ShowOptions => if (right == ShowOptions) 0 else -1
case Ignore => if (right == Ignore) 0 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,
* e.g. [[Custom]] is higher priority than [[HandleError]].
*/
implicit object ordering extends Ordering[CancelWatch] {
override def compare(left: CancelWatch, right: CancelWatch): Int = left match {
given ordering: Ordering[CancelWatch] = { (left: CancelWatch, right: CancelWatch) =>
left match {
// 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
// likely be simplified, but the pattern matching approach makes it very clear what happens