@@ -6,7 +6,8 @@ import Contexts._, Periods._, Symbols._
6
6
import io .PlainFile
7
7
import util .{SourceFile , NoSource , Stats , SimpleMap }
8
8
import reporting .Reporter
9
- import java .io .FileWriter
9
+ import java .io .{BufferedWriter , OutputStreamWriter }
10
+ import scala .reflect .io .VirtualFile
10
11
11
12
class Run (comp : Compiler )(implicit ctx : Context ) {
12
13
@@ -21,8 +22,12 @@ class Run(comp: Compiler)(implicit ctx: Context) {
21
22
}
22
23
}
23
24
24
- def compile (fileNames : List [String ]): Unit = Stats .monitorHeartBeat {
25
+ def compile (fileNames : List [String ]): Unit = {
25
26
val sources = fileNames map getSource
27
+ compileSources(sources)
28
+ }
29
+
30
+ def compileSources (sources : List [SourceFile ]) = Stats .monitorHeartBeat {
26
31
if (sources forall (_.exists)) {
27
32
units = sources map (new CompilationUnit (_))
28
33
for (phase <- ctx.allPhases)
@@ -31,12 +36,11 @@ class Run(comp: Compiler)(implicit ctx: Context) {
31
36
}
32
37
33
38
def compile (sourceCode : String ): Unit = {
34
- val tmpFile = java.io.File .createTempFile(" dotty-source-tmp" , " .scala" )
35
- tmpFile.createNewFile()
36
- val writer = new FileWriter (tmpFile)
39
+ val virtualFile = new VirtualFile (sourceCode) // use source code as name as it's used for equals
40
+ val writer = new BufferedWriter (new OutputStreamWriter (virtualFile.output, " UTF-8" )) // buffering is still advised by javadoc
37
41
writer.write(sourceCode)
38
42
writer.close()
39
- compile (List (tmpFile.getAbsolutePath ))
43
+ compileSources (List (new SourceFile (virtualFile) ))
40
44
}
41
45
42
46
/** Print summary; return # of errors encountered */
0 commit comments