@@ -56,15 +56,16 @@ public boolean sourcesRequired() {
56
56
}
57
57
58
58
private static VirtualFile asVirtualFile (SourceFile sourceFile , DelegatingReporter reporter ,
59
- Map <String , VirtualFile > placeholders ) {
60
- if (sourceFile .file () instanceof AbstractZincFile ) {
61
- return ((AbstractZincFile ) sourceFile .file ()).underlying ();
59
+ HashMap <AbstractFile , VirtualFile > lookup , Map <AbstractFile , VirtualFile > placeholders ) {
60
+ VirtualFile maybeCached = lookup .get (sourceFile .file ());
61
+ if (maybeCached != null ) {
62
+ return maybeCached ;
62
63
} else {
63
64
return fallbackVirtualFile (reporter , sourceFile , placeholders );
64
65
}
65
66
}
66
67
67
- private static void reportMissingFile (DelegatingReporter reporter , dotty . tools . dotc . interfaces . SourceFile sourceFile ) {
68
+ private static void reportMissingFile (DelegatingReporter reporter , SourceFile sourceFile ) {
68
69
String underline = String .join ("" , Collections .nCopies (sourceFile .path ().length (), "^" ));
69
70
String message =
70
71
sourceFile .path () + ": Missing virtual file\n " +
@@ -74,12 +75,11 @@ private static void reportMissingFile(DelegatingReporter reporter, dotty.tools.d
74
75
reporter .reportBasicWarning (message );
75
76
}
76
77
77
- private static VirtualFile fallbackVirtualFile (DelegatingReporter reporter ,
78
- dotty .tools .dotc .interfaces .SourceFile sourceFile ,
79
- Map <String , VirtualFile > placeholders ) {
80
- return placeholders .computeIfAbsent (sourceFile .path (), path -> {
78
+ private static VirtualFile fallbackVirtualFile (DelegatingReporter reporter , SourceFile sourceFile ,
79
+ Map <AbstractFile , VirtualFile > placeholders ) {
80
+ return placeholders .computeIfAbsent (sourceFile .file (), path -> {
81
81
reportMissingFile (reporter , sourceFile );
82
- if (sourceFile .jfile ().isPresent () )
82
+ if (sourceFile .file ().jpath () != null )
83
83
return new BasicPathBasedFile (sourceFile );
84
84
else
85
85
return new PlaceholderVirtualFile (sourceFile );
@@ -92,35 +92,30 @@ synchronized public void run(VirtualFile[] sources, AnalysisCallback callback, L
92
92
Arrays .sort (sortedSources , (x0 , x1 ) -> x0 .id ().compareTo (x1 .id ()));
93
93
94
94
ListBuffer <AbstractFile > sourcesBuffer = new ListBuffer <>();
95
- dotty . tools . dotc . util . HashSet <AbstractFile > sourcesSet = new dotty . tools . dotc . util . HashSet <>(8 , 2 );
95
+ HashMap <AbstractFile , VirtualFile > lookup = new HashMap <>(sources . length , 0.25f );
96
96
97
97
for (int i = 0 ; i < sources .length ; i ++) {
98
98
VirtualFile source = sortedSources [i ];
99
99
AbstractFile abstractFile = asDottyFile (source );
100
100
sourcesBuffer .append (abstractFile );
101
- sourcesSet .put (abstractFile );
101
+ lookup .put (abstractFile , source );
102
102
}
103
103
104
- HashMap <String , VirtualFile > placeholders = new HashMap <>();
104
+ HashMap <AbstractFile , VirtualFile > placeholders = new HashMap <>();
105
105
106
106
DelegatingReporter reporter = new DelegatingReporter (delegate , (self , sourceFile ) ->
107
- asVirtualFile (sourceFile , self , placeholders ).id ());
107
+ asVirtualFile (sourceFile , self , lookup , placeholders ).id ());
108
108
109
- IncrementalCallback incCallback = new IncrementalCallback (callback , sourceFile -> {
110
- if (sourceFile instanceof SourceFile ) {
111
- return asVirtualFile (((SourceFile ) sourceFile ), reporter , placeholders );
112
- } else {
113
- return fallbackVirtualFile (reporter , sourceFile , placeholders );
114
- }
115
- });
109
+ IncrementalCallback incCallback = new IncrementalCallback (callback , sourceFile ->
110
+ asVirtualFile (sourceFile , reporter , lookup , placeholders )
111
+ );
116
112
117
113
try {
118
114
log .debug (this ::infoOnCachedCompiler );
119
115
120
116
Contexts .Context initialCtx = initCtx ()
121
117
.fresh ()
122
118
.setReporter (reporter )
123
- .setZincInitialFiles (sourcesSet )
124
119
.setIncCallback (incCallback );
125
120
126
121
Contexts .Context context = setup (args , initialCtx ).map (t -> t ._2 ).getOrElse (() -> initialCtx );
0 commit comments