Skip to content

Commit 7719fec

Browse files
committed
Address review
1 parent 3afe1a5 commit 7719fec

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ package dotty.tools
22
package dotc
33
package util
44

5-
import scala.collection.mutable.ArrayBuffer
65
import dotty.tools.io._
7-
import java.util.regex.Pattern
8-
import java.io.IOException
9-
import scala.internal.Chars._
106
import Spans._
11-
import scala.io.Codec
127
import core.Contexts._
8+
9+
import scala.io.Codec
10+
import scala.internal.Chars._
1311
import scala.annotation.internal.sharable
14-
import java.util.concurrent.atomic.AtomicInteger
1512
import scala.collection.mutable
13+
import scala.collection.mutable.ArrayBuffer
1614

15+
import java.io.IOException
16+
import java.nio.charset.StandardCharsets
1717
import java.util.Optional
18+
import java.util.concurrent.atomic.AtomicInteger
19+
import java.util.regex.Pattern
1820

1921
object ScriptSourceFile {
2022
@sharable private val headerPattern = Pattern.compile("""^(::)?!#.*(\r|\n|\r\n)""", Pattern.MULTILINE)
@@ -212,7 +214,7 @@ object SourceFile {
212214
def fromId(id: Int): SourceFile = sourceOfChunk(id >> ChunkSizeLog)
213215

214216
def virtual(name: String, content: String, maybeIncomplete: Boolean = false) =
215-
val src = new SourceFile(new VirtualFile(name, content.getBytes("UTF-8")), scala.io.Codec.UTF8)
217+
val src = new SourceFile(new VirtualFile(name, content.getBytes(StandardCharsets.UTF_8)), scala.io.Codec.UTF8)
216218
src._maybeInComplete = maybeIncomplete
217219
src
218220

compiler/test/dotty/tools/dotc/printing/PrintingTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import reporting.TestReporter
1010
import java.io._
1111
import java.nio.file.{Path => JPath}
1212
import java.lang.System.{lineSeparator => EOL}
13+
import java.nio.charset.StandardCharsets
1314

1415
import interfaces.Diagnostic.INFO
1516
import dotty.tools.io.Directory
@@ -35,7 +36,7 @@ class PrintingTest {
3536
e.printStackTrace()
3637
}
3738

38-
val actualLines = byteStream.toString("UTF-8").linesIterator
39+
val actualLines = byteStream.toString(StandardCharsets.UTF_8.name).linesIterator
3940
FileDiff.checkAndDump(path.toString, actualLines.toIndexedSeq, checkFilePath)
4041
}
4142

compiler/test/dotty/tools/repl/ReplTest.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import vulpix.FileDiff
66

77
import java.lang.System.{lineSeparator => EOL}
88
import java.io.{ByteArrayOutputStream, File => JFile, PrintStream}
9+
import java.nio.charset.StandardCharsets
10+
911
import scala.io.Source
1012
import scala.util.Using
11-
1213
import scala.collection.mutable.ArrayBuffer
1314

1415
import dotty.tools.dotc.reporting.MessageRendering
@@ -26,11 +27,11 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By
2627
"-color:never",
2728
"-Yerased-terms",
2829
),
29-
new PrintStream(out, true, "UTF-8")
30+
new PrintStream(out, true, StandardCharsets.UTF_8.name)
3031
) with MessageRendering {
3132
/** Get the stored output from `out`, resetting the buffer */
3233
def storedOutput(): String = {
33-
val output = stripColor(out.toString("UTF-8"))
34+
val output = stripColor(out.toString(StandardCharsets.UTF_8.name))
3435
out.reset()
3536
output
3637
}
@@ -77,11 +78,11 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By
7778
}
7879

7980
val expectedOutput =
80-
Using(Source.fromFile(f, "UTF-8"))(_.getLines().flatMap(filterEmpties).toList).get
81+
Using(Source.fromFile(f, StandardCharsets.UTF_8.name))(_.getLines().flatMap(filterEmpties).toList).get
8182
val actualOutput = {
8283
resetToInitial()
8384

84-
val lines = Using(Source.fromFile(f, "UTF-8"))(_.getLines.toList).get
85+
val lines = Using(Source.fromFile(f, StandardCharsets.UTF_8.name))(_.getLines.toList).get
8586
assert(lines.head.startsWith(prompt),
8687
s"""Each file has to start with the prompt: "$prompt"""")
8788
val inputRes = lines.filter(_.startsWith(prompt))

compiler/test/dotty/tools/vulpix/FileDiff.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package dotty.tools.vulpix
22

33
import scala.io.Source
44
import scala.util.Using
5+
56
import java.io.File
67
import java.lang.System.{lineSeparator => EOL}
78
import java.nio.file.{Files, Paths}
9+
import java.nio.charset.StandardCharsets
10+
811

912
object FileDiff {
1013
def diffMessage(expectFile: String, actualFile: String): String =
@@ -18,7 +21,7 @@ object FileDiff {
1821
def check(sourceTitle: String, outputLines: Seq[String], checkFile: String): Option[String] = {
1922
val checkLines =
2023
if (!(new File(checkFile)).exists) Nil
21-
else Using(Source.fromFile(checkFile, "UTF-8"))(_.getLines().toList).get
24+
else Using(Source.fromFile(checkFile, StandardCharsets.UTF_8.name))(_.getLines().toList).get
2225

2326
if (!matches(outputLines, checkLines)) Some(
2427
s"""|Output from '$sourceTitle' did not match check file. Actual output:

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package dotty
22
package tools
33
package vulpix
44

5-
import java.io.{File => JFile}
5+
import java.io.{File => JFile, IOException}
66
import java.lang.System.{lineSeparator => EOL}
77
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
88
import java.nio.file.{Files, NoSuchFileException, Path, Paths}
9+
import java.nio.charset.StandardCharsets
910
import java.text.SimpleDateFormat
1011
import java.util.{HashMap, Timer, TimerTask}
1112
import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors}
@@ -451,7 +452,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
451452
def compileWithJavac(fs: Array[String]) = if (fs.nonEmpty) {
452453
val fullArgs = Array(
453454
"javac",
454-
"-encoding", "UTF-8",
455+
"-encoding", StandardCharsets.UTF_8.name,
455456
) ++ flags.javacFlags ++ fs
456457

457458
val process = Runtime.getRuntime.exec(fullArgs)
@@ -607,9 +608,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
607608
if checkFiles.contains(file) then
608609
val checkFile = checkFiles(file)
609610
val actual = {
610-
val source = Source.fromFile(file, "UTF-8")
611+
val source = Source.fromFile(file, StandardCharsets.UTF_8.name)
611612
val lines = source.getLines().toList
612-
source.close()
613+
try source.close()
614+
catch
615+
case _: IOException => // ignore file close errors
613616
lines
614617
}
615618
diffTest(testSource, checkFile, actual, reporters, logger)
@@ -695,7 +698,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
695698
val errorMap = new HashMap[String, Integer]()
696699
var expectedErrors = 0
697700
files.filter(isSourceFile).foreach { file =>
698-
Using(Source.fromFile(file, "UTF-8")) { source =>
701+
Using(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source =>
699702
source.getLines.zipWithIndex.foreach { case (line, lineNbr) =>
700703
val errors = line.toSeq.sliding("// error".length).count(_.unwrap == "// error")
701704
if (errors > 0)

0 commit comments

Comments
 (0)