@@ -5,7 +5,8 @@ import java.io.File
55import java .nio .charset .StandardCharsets .UTF_8
66import java .nio .file .{Files , Path => JPath }
77
8- import scala .io .{Codec , Source }
8+ import scala .io .Source
9+ import scala .jdk .StreamConverters ._
910import scala .reflect .ClassTag
1011import scala .util .Using .resource
1112import scala .util .chaining .given
@@ -27,9 +28,9 @@ extension (str: String) def dropExtension =
2728 str.reverse.dropWhile(_ != '.' ).drop(1 ).reverse
2829
2930private
30- def withFile [T ](file : File )(action : Source => T )( using Codec ) : T = resource(Source .fromFile(file))(action)
31- def readLines (f : File )( using codec : Codec = Codec . UTF8 ) : List [String ] = withFile(f)(_.getLines.toList)
32- def readFile (f : File )( using codec : Codec = Codec . UTF8 ) : String = withFile(f)(_.mkString)
31+ def withFile [T ](file : File )(action : Source => T ): T = resource(Source .fromFile(file, UTF_8 .name ))(action)
32+ def readLines (f : File ): List [String ] = withFile(f)(_.getLines.toList)
33+ def readFile (f : File ): String = withFile(f)(_.mkString)
3334
3435private object Unthrown extends ControlThrowable
3536
@@ -44,8 +45,8 @@ def assertThrows[T <: Throwable: ClassTag](p: T => Boolean)(body: => Any): Unit
4445 case NonFatal (other) => throw AssertionError (s " Wrong exception: expected ${implicitly[ClassTag [T ]]} but was ${other.getClass.getName}" ).tap(_.addSuppressed(other))
4546end assertThrows
4647
47- def toolArgsFor (files : List [JPath ])( using codec : Codec = Codec . UTF8 ) : List [String ] =
48- files.flatMap(path => toolArgsParse(readLines (path.toFile )))
48+ def toolArgsFor (files : List [JPath ]): List [String ] =
49+ files.flatMap(path => toolArgsParse(Files .lines (path, UTF_8 ).limit( 10 ).toScala( List )))
4950
5051// Inspect the first 10 of the given lines for compiler options of the form
5152// `// scalac: args`, `/* scalac: args`, ` * scalac: args`.
@@ -63,4 +64,4 @@ def toolArgsParse(lines: List[String]): List[String] = {
6364 // but avoid picking up comments like "% scalac ./a.scala" and "$ scalac a.scala"
6465 }.map(stripped).headOption
6566 args.map(dotc.config.CommandLineParser .tokenize).getOrElse(Nil )
66- }
67+ }
0 commit comments