Skip to content

Commit

Permalink
Merge pull request #364 from xuwei-k/convertToNewSyntax-scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n authored Dec 26, 2023
2 parents be7a2e3 + 2fd1770 commit 3a21efa
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ danglingParentheses.preset = true
trailingCommas = preserve

runner.dialect = Scala212Source3

rewrite.scala3.convertToNewSyntax = true
runner.dialectOverride.allowSignificantIndentation = false
runner.dialectOverride.allowAsForImportRename = false
runner.dialectOverride.allowStarWildcardImport = false
runner.dialectOverride.allowPostfixStarVarargSplices = false
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ThisBuild / publishTo := {
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

def commonSettings: Seq[Setting[_]] = Seq(
def commonSettings: Seq[Setting[?]] = Seq(
scalaVersion := scala212,
compile / javacOptions ++= Seq("-Xlint", "-Xlint:-serial"),
crossScalaVersions := Seq(scala212, scala213, scala3),
Expand Down
6 changes: 3 additions & 3 deletions io/src/main/scala/sbt/internal/io/Retry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ private[sbt] object Retry {
try System.getProperty("sbt.io.retry.limit", defaultLimit.toString).toInt
catch { case NonFatal(_) => defaultLimit }
}
private[sbt] def apply[@specialized T](f: => T, excludedExceptions: Class[_ <: IOException]*): T =
private[sbt] def apply[@specialized T](f: => T, excludedExceptions: Class[? <: IOException]*): T =
apply(f, limit, excludedExceptions: _*)
private[sbt] def apply[@specialized T](
f: => T,
limit: Int,
excludedExceptions: Class[_ <: IOException]*,
excludedExceptions: Class[? <: IOException]*,
): T = apply(f, limit, 100, excludedExceptions: _*)
private[sbt] def apply[@specialized T](
f: => T,
limit: Int,
sleepInMillis: Long,
excludedExceptions: Class[_ <: IOException]*,
excludedExceptions: Class[? <: IOException]*,
): T = {
require(limit >= 1, "limit must be 1 or higher: was: " + limit)
def filter(e: Exception): Boolean = excludedExceptions match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private[sbt] final class WatchState private (
}

/** Retrieve events from the `WatchService` */
private[sbt] def pollEvents(): Iterable[(Path, WatchEvent[_])] = {
private[sbt] def pollEvents(): Iterable[(Path, WatchEvent[?])] = {
val events = service.pollEvents()
events.toIterable.flatMap { case (k, evs) =>
evs.map((k.watchable().asInstanceOf[Path], _))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private[sbt] class LegacyFileTreeRepository(logger: WatchLogger, watchService: W
private[this] val handle =
observable.addObserver((event: FileEvent[FileAttributes]) => {
val attributes = event match {
case _: Deletion[_] => NonExistent
case _: Deletion[?] => NonExistent
case _ => event.attributes
}
val events: Seq[FileEvent[FileAttributes]] = fileCache.update(event.path, attributes)
Expand Down
10 changes: 5 additions & 5 deletions io/src/main/scala/sbt/internal/nio/PollingWatchService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ private[sbt] class PollingWatchService(delay: FiniteDuration, timeSource: TimeSo
()
}
override def isValid: Boolean = true
override def pollEvents(): JList[WatchEvent[_]] =
pollEventsImpl.asInstanceOf[JList[WatchEvent[_]]]
override def pollEvents(): JList[WatchEvent[?]] =
pollEventsImpl.asInstanceOf[JList[WatchEvent[?]]]
override def reset(): Boolean = events.synchronized {
events.clear()
true
Expand Down Expand Up @@ -181,9 +181,9 @@ private[sbt] class PollingWatchService(delay: FiniteDuration, timeSource: TimeSo
Some(this)
}
event match {
case _: Creation[_] if acceptCreate => offer(event)
case _: Deletion[_] if acceptDelete => offer(event)
case _: Update[_] if acceptModify => offer(event)
case _: Creation[?] if acceptCreate => offer(event)
case _: Deletion[?] if acceptDelete => offer(event)
case _: Update[?] if acceptModify => offer(event)
case _ => None
}
}
Expand Down
14 changes: 7 additions & 7 deletions io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object IO {
* If the location cannot be determined, an error is generated.
* Note that for JDK 11 onwards, a module will return a jrt path.
*/
def classLocationPath(cl: Class[_]): NioPath = {
def classLocationPath(cl: Class[?]): NioPath = {
val u = classLocation(cl)
val p = u.getProtocol match {
case FileScheme => Option(toFile(u).toPath)
Expand All @@ -87,7 +87,7 @@ object IO {
* If the location cannot be determined or it is not a file, an error is generated.
* Note that for JDK 11 onwards, the returned module path cannot be expressed as `File`, so it will return `None`.
*/
def classLocationFileOption(cl: Class[_]): Option[File] = {
def classLocationFileOption(cl: Class[?]): Option[File] = {
val u = classLocation(cl)
urlAsFile(u)
}
Expand All @@ -109,7 +109,7 @@ object IO {
"classLocationFile may not work on JDK 11. Use classfileLocation, classLocationFileOption, or classLocationPath instead.",
"1.3.0"
)
def classLocationFile(cl: Class[_]): File =
def classLocationFile(cl: Class[?]): File =
classLocationFileOption(cl).getOrElse(sys.error(s"Unable to create File from $cl"))

/**
Expand All @@ -128,7 +128,7 @@ object IO {
* If the location cannot be determined or it is not a file, an error is generated.
* Note that for JDK 11 onwards, a module will return a jrt URL such as `jrt:/java.base`.
*/
def classLocation(cl: Class[_]): URL = {
def classLocation(cl: Class[?]): URL = {
def localcl: Option[URL] =
Option(cl.getProtectionDomain.getCodeSource) flatMap { codeSource =>
Option(codeSource.getLocation)
Expand Down Expand Up @@ -187,7 +187,7 @@ object IO {
* Returns a URL for the classfile containing the given class
* If the location cannot be determined, an error is generated.
*/
def classfileLocation(cl: Class[_]): URL = {
def classfileLocation(cl: Class[?]): URL = {
val clsfile = s"${cl.getName.replace('.', '/')}.class"
def localcl: Option[URL] =
Option(cl.getClassLoader) flatMap { classLoader =>
Expand Down Expand Up @@ -1232,7 +1232,7 @@ object IO {
*/
def objectInputStream(wrapped: InputStream, loader: ClassLoader): ObjectInputStream =
new ObjectInputStream(wrapped) {
override def resolveClass(osc: ObjectStreamClass): Class[_] = {
override def resolveClass(osc: ObjectStreamClass): Class[?] = {
val c = Class.forName(osc.getName, false, loader)
if (c eq null) super.resolveClass(osc) else c
}
Expand Down Expand Up @@ -1491,7 +1491,7 @@ object IO {
setModifiedTimeOrFalse(targetFile, math.max(last, 0L))
}

private val excludeFileNotFound: immutable.Seq[Class[_ <: IOException]] = List(
private val excludeFileNotFound: immutable.Seq[Class[? <: IOException]] = List(
classOf[FileNotFoundException]
)
}
2 changes: 1 addition & 1 deletion io/src/test/scala/sbt/internal/io/RetrySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.util.concurrent.atomic.AtomicInteger
import org.scalatest.flatspec.AnyFlatSpec

final class RetrySpec extends AnyFlatSpec {
private val noExcluded: List[Class[_ <: IOException]] = List[Class[_ <: IOException]]()
private val noExcluded: List[Class[? <: IOException]] = List[Class[? <: IOException]]()
"retry" should "throw first exception after number of failures" in {
val i = new AtomicInteger()
def throww(): Any = throw new IOException(i.incrementAndGet().toString)
Expand Down
34 changes: 17 additions & 17 deletions io/src/test/scala/sbt/internal/io/SourceModificationWatchSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,16 @@ private[sbt] trait EventMonitorSpec { self: AnyFlatSpec with Matchers =>
}

def watchTest(
monitor: FileEventMonitor[FileEvent[_]],
filter: FileEvent[_] => Boolean,
check: Seq[FileEvent[_]] => Boolean
monitor: FileEventMonitor[FileEvent[?]],
filter: FileEvent[?] => Boolean,
check: Seq[FileEvent[?]] => Boolean
)(modifier: => Unit): Boolean = {
modifier
val events = monitor.poll(maxWait * 2, filter)
check(events)
}

def watchTest(base: File, filter: FileEvent[_] => Boolean, check: Seq[FileEvent[_]] => Boolean)(
def watchTest(base: File, filter: FileEvent[?] => Boolean, check: Seq[FileEvent[?]] => Boolean)(
modifier: => Unit
): Boolean = {
val globs = base.toPath.toRealPath().toFile.scalaSourceGlobs
Expand Down Expand Up @@ -496,7 +496,7 @@ private[sbt] trait EventMonitorSpec { self: AnyFlatSpec with Matchers =>
object EventMonitorSpec {
type Event = FileEvent[FileAttributes]
val AllPass: Any => Boolean = ((_: Any) => true).label("AllPass")
val NonEmpty: Seq[FileEvent[_]] => Boolean = ((_: Seq[FileEvent[_]]).nonEmpty).label("NonEmpty")
val NonEmpty: Seq[FileEvent[?]] => Boolean = ((_: Seq[FileEvent[?]]).nonEmpty).label("NonEmpty")
private implicit class LabeledFunction[T, R](val f: T => R) extends AnyVal {
def label(string: String): T => R = new (T => R) {
override def apply(t: T): R = f(t)
Expand All @@ -514,33 +514,33 @@ object EventMonitorSpec {
realPath(path.getParent, fileName.map(newFileName.resolve) orElse Some(newFileName))
}
}
def pathFilter(path: Path): FileEvent[_] => Boolean = {
def pathFilter(path: Path): FileEvent[?] => Boolean = {
val real = realPath(path)
((_: FileEvent[_]).path == real).label(s"PathFilter($real)")
((_: FileEvent[?]).path == real).label(s"PathFilter($real)")
}
def contains(path: Path): Seq[FileEvent[_]] => Boolean = {
def contains(path: Path): Seq[FileEvent[?]] => Boolean = {
val real = realPath(path)
((_: Seq[FileEvent[_]]).exists(_.path == real)).label(s"Contains($real)")
((_: Seq[FileEvent[?]]).exists(_.path == real)).label(s"Contains($real)")
}
def excludes(path: Path): Seq[FileEvent[_]] => Boolean = {
def excludes(path: Path): Seq[FileEvent[?]] => Boolean = {
val real = realPath(path)
((s: Seq[FileEvent[_]]) => s.nonEmpty && s.forall(_.path != real)).label(s"Excludes($real)")
((s: Seq[FileEvent[?]]) => s.nonEmpty && s.forall(_.path != real)).label(s"Excludes($real)")
}
def includesOnly(path: Path): Seq[FileEvent[_]] => Boolean = {
def includesOnly(path: Path): Seq[FileEvent[?]] => Boolean = {
val real = realPath(path)
((s: Seq[FileEvent[_]]) => s.nonEmpty && s.forall(_.path == real)).label(s"IncludesOnly($real)")
((s: Seq[FileEvent[?]]) => s.nonEmpty && s.forall(_.path == real)).label(s"IncludesOnly($real)")
}
def isDeletion(path: Path): FileEvent[_] => Boolean = {
def isDeletion(path: Path): FileEvent[?] => Boolean = {
val real = realPath(path)
(_: FileEvent[_]) match {
(_: FileEvent[?]) match {
case Deletion(p, _) if p == real => true
case _ => false
}
}
def hasDeletion(path: Path): Seq[FileEvent[_]] => Boolean = {
def hasDeletion(path: Path): Seq[FileEvent[?]] => Boolean = {
val real = realPath(path)
val deletion = isDeletion(real)
((_: Seq[FileEvent[_]]).exists(deletion)).label(s"HasDeletion($real)")
((_: Seq[FileEvent[?]]).exists(deletion)).label(s"HasDeletion($real)")
}

trait Logger extends WatchLogger
Expand Down
4 changes: 2 additions & 2 deletions io/src/test/scala/sbt/io/IOSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.nio.file.Files

object IOSpecification extends Properties("IO") {
property("IO.classLocationPath able to determine containing directories") = forAll(classes) {
(c: Class[_]) =>
(c: Class[?]) =>
Try(IO.classLocationPath(c)).toOption.exists {
case jar if jar.getFileName.toString.endsWith(".jar") =>
Files.isRegularFile(jar)
Expand All @@ -28,7 +28,7 @@ object IOSpecification extends Properties("IO") {
}
}

implicit def classes: Gen[Class[_]] =
implicit def classes: Gen[Class[?]] =
Gen.oneOf(
this.getClass,
classOf[java.lang.Integer],
Expand Down
4 changes: 2 additions & 2 deletions project/HouseRulesPluglin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ object HouseRulesPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements

override def projectSettings: Seq[Def.Setting[_]] = baseSettings
override def projectSettings: Seq[Def.Setting[?]] = baseSettings

lazy val baseSettings: Seq[Def.Setting[_]] = Seq(
lazy val baseSettings: Seq[Def.Setting[?]] = Seq(
scalacOptions ++= Seq("-encoding", "utf8"),
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked"),
scalacOptions += "-language:higherKinds",
Expand Down

0 comments on commit 3a21efa

Please sign in to comment.