@@ -5,7 +5,8 @@ import java.io.File
5
5
import java .nio .charset .StandardCharsets .UTF_8
6
6
import java .nio .file .{Files , Path => JPath }
7
7
8
- import scala .io .{Codec , Source }
8
+ import scala .io .Source
9
+ import scala .jdk .StreamConverters ._
9
10
import scala .reflect .ClassTag
10
11
import scala .util .Using .resource
11
12
import scala .util .chaining .given
@@ -27,9 +28,9 @@ extension (str: String) def dropExtension =
27
28
str.reverse.dropWhile(_ != '.' ).drop(1 ).reverse
28
29
29
30
private
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)
33
34
34
35
private object Unthrown extends ControlThrowable
35
36
@@ -44,8 +45,8 @@ def assertThrows[T <: Throwable: ClassTag](p: T => Boolean)(body: => Any): Unit
44
45
case NonFatal (other) => throw AssertionError (s " Wrong exception: expected ${implicitly[ClassTag [T ]]} but was ${other.getClass.getName}" ).tap(_.addSuppressed(other))
45
46
end assertThrows
46
47
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 )))
49
50
50
51
// Inspect the first 10 of the given lines for compiler options of the form
51
52
// `// scalac: args`, `/* scalac: args`, ` * scalac: args`.
@@ -63,4 +64,4 @@ def toolArgsParse(lines: List[String]): List[String] = {
63
64
// but avoid picking up comments like "% scalac ./a.scala" and "$ scalac a.scala"
64
65
}.map(stripped).headOption
65
66
args.map(dotc.config.CommandLineParser .tokenize).getOrElse(Nil )
66
- }
67
+ }
0 commit comments