mirror of https://github.com/sbt/sbt.git
Merge pull request #7996 from xuwei-k/enum-sealed-trait
This commit is contained in:
commit
734d06a3c6
|
|
@ -12,11 +12,9 @@ import sbt.internal.util.complete.DefaultParsers._
|
||||||
|
|
||||||
private[sbt] object SizeParser {
|
private[sbt] object SizeParser {
|
||||||
def apply(s: String): Option[Long] = Parser.parse(s, value).toOption
|
def apply(s: String): Option[Long] = Parser.parse(s, value).toOption
|
||||||
private sealed trait SizeUnit
|
private enum SizeUnit {
|
||||||
private case object Bytes extends SizeUnit
|
case Bytes, KiloBytes, MegaBytes, GigaBytes
|
||||||
private case object KiloBytes extends SizeUnit
|
}
|
||||||
private case object MegaBytes extends SizeUnit
|
|
||||||
private case object GigaBytes extends SizeUnit
|
|
||||||
private def parseDouble(s: String): Parser[Either[Double, Long]] =
|
private def parseDouble(s: String): Parser[Either[Double, Long]] =
|
||||||
s.toDoubleOption match {
|
s.toDoubleOption match {
|
||||||
case Some(x) => Parser.success(Left(x))
|
case Some(x) => Parser.success(Left(x))
|
||||||
|
|
@ -36,10 +34,10 @@ private[sbt] object SizeParser {
|
||||||
}
|
}
|
||||||
private val unitParser: Parser[SizeUnit] =
|
private val unitParser: Parser[SizeUnit] =
|
||||||
token("b" | "B" | "g" | "G" | "k" | "K" | "m" | "M").map {
|
token("b" | "B" | "g" | "G" | "k" | "K" | "m" | "M").map {
|
||||||
case "b" | "B" => Bytes
|
case "b" | "B" => SizeUnit.Bytes
|
||||||
case "g" | "G" => GigaBytes
|
case "g" | "G" => SizeUnit.GigaBytes
|
||||||
case "k" | "K" => KiloBytes
|
case "k" | "K" => SizeUnit.KiloBytes
|
||||||
case "m" | "M" => MegaBytes
|
case "m" | "M" => SizeUnit.MegaBytes
|
||||||
}
|
}
|
||||||
private def multiply(left: Either[Double, Long], right: Long): Long = left match {
|
private def multiply(left: Either[Double, Long], right: Long): Long = left match {
|
||||||
case Left(d) => (d * right).toLong
|
case Left(d) => (d * right).toLong
|
||||||
|
|
@ -51,10 +49,10 @@ private[sbt] object SizeParser {
|
||||||
.*) ~ unitParser.?)
|
.*) ~ unitParser.?)
|
||||||
.map { case (number, unit) =>
|
.map { case (number, unit) =>
|
||||||
unit match {
|
unit match {
|
||||||
case None | Some(Bytes) => multiply(number, right = 1L)
|
case None | Some(SizeUnit.Bytes) => multiply(number, right = 1L)
|
||||||
case Some(KiloBytes) => multiply(number, right = 1024L)
|
case Some(SizeUnit.KiloBytes) => multiply(number, right = 1024L)
|
||||||
case Some(MegaBytes) => multiply(number, right = 1024L * 1024)
|
case Some(SizeUnit.MegaBytes) => multiply(number, right = 1024L * 1024)
|
||||||
case Some(GigaBytes) => multiply(number, right = 1024L * 1024 * 1024)
|
case Some(SizeUnit.GigaBytes) => multiply(number, right = 1024L * 1024 * 1024)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,22 +25,17 @@ import xsbti.VirtualFileRef
|
||||||
* A trait that indicates what file stamping implementation should be used to track the state of
|
* A trait that indicates what file stamping implementation should be used to track the state of
|
||||||
* a given file. The two choices are [[FileStamper.Hash]] and [[FileStamper.LastModified]].
|
* a given file. The two choices are [[FileStamper.Hash]] and [[FileStamper.LastModified]].
|
||||||
*/
|
*/
|
||||||
sealed trait FileStamper
|
enum FileStamper {
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides implementations of [[FileStamper]].
|
|
||||||
*/
|
|
||||||
object FileStamper {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Track files using a hash.
|
* Track files using a hash.
|
||||||
*/
|
*/
|
||||||
case object Hash extends FileStamper
|
case Hash
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Track files using the last modified time.
|
* Track files using the last modified time.
|
||||||
*/
|
*/
|
||||||
case object LastModified extends FileStamper
|
case LastModified
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue