@@ -4,24 +4,31 @@ package core
4
4
5
5
import java .io .{IOException , File }
6
6
import java .nio .channels .ClosedByInterruptException
7
+
7
8
import scala .compat .Platform .currentTime
9
+ import scala .util .control .NonFatal
10
+
8
11
import dotty .tools .io .{ ClassPath , ClassRepresentation , AbstractFile }
12
+
13
+ import dotty .tools .backend .jvm .DottyBackendInterface .symExtensions
14
+
9
15
import config .Config
10
16
import Contexts ._ , Symbols ._ , Flags ._ , SymDenotations ._ , Types ._ , Scopes ._ , Names ._
11
17
import NameOps ._
12
- import StdNames .str
18
+ import StdNames ._
13
19
import Decorators ._
14
20
import classfile .ClassfileParser
15
- import util .Stats
16
21
import Decorators ._
17
- import scala .util .control .NonFatal
22
+
23
+ import util .Stats
24
+ import reporting .trace
25
+
18
26
import ast .Trees ._
27
+ import ast .desugar
28
+
19
29
import parsing .JavaParsers .OutlineJavaParser
20
30
import parsing .Parsers .OutlineParser
21
- import reporting .trace
22
- import ast .desugar
23
31
24
- import dotty .tools .backend .jvm .DottyBackendInterface .symExtensions
25
32
26
33
object SymbolLoaders {
27
34
import ast .untpd ._
@@ -178,27 +185,37 @@ object SymbolLoaders {
178
185
* Note: We do a name-base comparison here because the method is called before we even
179
186
* have ReflectPackage defined.
180
187
*/
181
- def binaryOnly (owner : Symbol , name : String )(using Context ): Boolean =
182
- name == " package " &&
183
- (owner.fullName.toString == " scala " || owner.fullName.toString == " scala.reflect " )
188
+ def binaryOnly (owner : Symbol , name : TermName )(using Context ): Boolean =
189
+ name == nme. PACKAGEkw &&
190
+ (owner == defn. ScalaPackageClass || owner == defn. ReflectPackageClass )
184
191
185
192
/** Initialize toplevel class and module symbols in `owner` from class path representation `classRep`
186
193
*/
187
194
def initializeFromClassPath (owner : Symbol , classRep : ClassRepresentation )(using Context ): Unit =
188
195
((classRep.binary, classRep.source): @ unchecked) match {
189
- case (Some (bin), Some (src)) if needCompile(bin, src) && ! binaryOnly(owner, classRep.name ) =>
196
+ case (Some (bin), Some (src)) if needCompile(bin, src) && ! binaryOnly(owner, nameOf( classRep) ) =>
190
197
if (ctx.settings.verbose.value) report.inform(" [symloader] picked up newer source file for " + src.path)
191
- enterToplevelsFromSource(owner, classRep.name , src)
198
+ enterToplevelsFromSource(owner, nameOf( classRep) , src)
192
199
case (None , Some (src)) =>
193
200
if (ctx.settings.verbose.value) report.inform(" [symloader] no class, picked up source file for " + src.path)
194
- enterToplevelsFromSource(owner, classRep.name , src)
201
+ enterToplevelsFromSource(owner, nameOf( classRep) , src)
195
202
case (Some (bin), _) =>
196
- enterClassAndModule(owner, classRep.name , ctx.platform.newClassLoader(bin))
203
+ enterClassAndModule(owner, nameOf( classRep) , ctx.platform.newClassLoader(bin))
197
204
}
198
205
199
206
def needCompile (bin : AbstractFile , src : AbstractFile ): Boolean =
200
207
src.lastModified >= bin.lastModified
201
208
209
+ private def nameOf (classRep : ClassRepresentation ): TermName = {
210
+ while (true ) {
211
+ val len = classRep.nameChars(nameCharBuffer)
212
+ if (len == - 1 ) nameCharBuffer = new Array [Char ](nameCharBuffer.length * 2 )
213
+ else return termName(nameCharBuffer, 0 , len)
214
+ }
215
+ throw new IllegalStateException ()
216
+ }
217
+ private var nameCharBuffer = new Array [Char ](256 )
218
+
202
219
/** Load contents of a package
203
220
*/
204
221
class PackageLoader (_sourceModule : TermSymbol , classPath : ClassPath )
0 commit comments