12
12
import dotty .tools .dotc .core .Contexts ;
13
13
import dotty .tools .dotc .util .SourceFile ;
14
14
import dotty .tools .io .AbstractFile ;
15
+ import dotty .tools .io .PlainFile ;
16
+ import dotty .tools .io .Path ;
17
+ import dotty .tools .io .Streamable ;
15
18
import scala .collection .mutable .ListBuffer ;
16
19
import scala .jdk .javaapi .CollectionConverters ;
17
20
import scala .io .Codec ;
20
23
import xsbti .compile .Output ;
21
24
22
25
import java .io .IOException ;
26
+ import java .io .InputStream ;
27
+ import java .io .OutputStream ;
23
28
import java .util .Comparator ;
24
29
import java .util .Collections ;
25
30
import java .util .HashMap ;
@@ -60,19 +65,20 @@ private static VirtualFile asVirtualFile(SourceFile sourceFile, DelegatingReport
60
65
return lookup .computeIfAbsent (sourceFile .file (), path -> {
61
66
reportMissingFile (reporter , sourceFile );
62
67
if (sourceFile .file ().jpath () != null )
63
- return new BasicPathBasedFile (sourceFile );
68
+ return new FallbackPathBasedFile (sourceFile );
64
69
else
65
- return new PlaceholderVirtualFile (sourceFile );
70
+ return new FallbackVirtualFile (sourceFile );
66
71
});
67
72
}
68
73
69
74
private static void reportMissingFile (DelegatingReporter reporter , SourceFile sourceFile ) {
70
75
String underline = String .join ("" , Collections .nCopies (sourceFile .path ().length (), "^" ));
71
76
String message =
72
- sourceFile .path () + ": Missing virtual file\n " +
77
+ sourceFile .path () + ": Missing Zinc virtual file\n " +
73
78
underline + "\n " +
74
79
" Falling back to placeholder for the given source file (of class " + sourceFile .getClass ().getName () + ")\n " +
75
- " This is likely a bug in incremental compilation for the Scala 3 compiler. Please report it to the Scala 3 maintainers." ;
80
+ " This is likely a bug in incremental compilation for the Scala 3 compiler.\n " +
81
+ " Please report it to the Scala 3 maintainers at https://github.com/lampepfl/dotty/issues." ;
76
82
reporter .reportBasicWarning (message );
77
83
}
78
84
@@ -91,9 +97,19 @@ synchronized public void run(VirtualFile[] sources, AnalysisCallback callback, L
91
97
lookup .put (abstractFile , source );
92
98
}
93
99
94
- DelegatingReporter reporter = new DelegatingReporter (delegate , (self , sourceFile ) ->
95
- asVirtualFile (sourceFile , self , lookup ).id ()
96
- );
100
+ DelegatingReporter reporter = new DelegatingReporter (delegate , sourceFile -> {
101
+ // TODO: possible situation here where we use -from-tasty and TASTy source files but
102
+ // the reporter log is associated to a Scala source file?
103
+
104
+ // Zinc will use the output of this function to possibly lookup a mapped virtual file,
105
+ // e.g. convert `${ROOT}/Foo.scala` to `/path/to/Foo.scala` if it exists in the lookup map.
106
+ VirtualFile vf = lookup .get (sourceFile .file ());
107
+ if (vf != null )
108
+ return vf .id ();
109
+ else
110
+ // follow Zinc, which uses the path of the source file as a fallback.
111
+ return sourceFile .path ();
112
+ });
97
113
98
114
IncrementalCallback incCallback = new IncrementalCallback (callback , sourceFile ->
99
115
asVirtualFile (sourceFile , reporter , lookup )
@@ -137,11 +153,28 @@ synchronized public void run(VirtualFile[] sources, AnalysisCallback callback, L
137
153
}
138
154
139
155
private static AbstractFile asDottyFile (VirtualFile virtualFile ) {
140
- if (virtualFile instanceof PathBasedFile )
141
- return new ZincPlainFile ((PathBasedFile ) virtualFile );
156
+ if (virtualFile instanceof PathBasedFile ) {
157
+ java .nio .file .Path path = ((PathBasedFile ) virtualFile ).toPath ();
158
+ return new PlainFile (new Path (path ));
159
+ }
142
160
143
161
try {
144
- return new ZincVirtualFile (virtualFile );
162
+ return new dotty .tools .io .VirtualFile (virtualFile .name (), virtualFile .id ()) {
163
+ {
164
+ // fill in the content
165
+ try (OutputStream output = output ()) {
166
+ try (InputStream input = virtualFile .input ()) {
167
+ Streamable .Bytes bytes = new Streamable .Bytes () {
168
+ @ Override
169
+ public InputStream inputStream () {
170
+ return input ;
171
+ }
172
+ };
173
+ output .write (bytes .toByteArray ());
174
+ }
175
+ }
176
+ }
177
+ };
145
178
} catch (IOException e ) {
146
179
throw new IllegalArgumentException ("invalid file " + virtualFile .name (), e );
147
180
}
0 commit comments