@@ -14,6 +14,7 @@ import util.Stats
14
14
import Decorators ._
15
15
import scala .util .control .NonFatal
16
16
import ast .Trees ._
17
+ import ast .tpd
17
18
import parsing .Parsers .OutlineParser
18
19
import reporting .trace
19
20
@@ -118,7 +119,9 @@ class SymbolLoaders {
118
119
scope : Scope = EmptyScope )(implicit ctx : Context ): Unit = {
119
120
120
121
val completer = new SourcefileLoader (src)
121
- if (ctx.settings.scansource.value) {
122
+ if (ctx.settings.scansource.value && ctx.run != null ) {
123
+ System .out.print(i " scanning $src ... " )
124
+ System .out.flush()
122
125
if (src.exists && ! src.isDirectory) {
123
126
val filePath = owner.ownersIterator.takeWhile(! _.isRoot).map(_.name.toTermName).toList
124
127
@@ -160,6 +163,7 @@ class SymbolLoaders {
160
163
161
164
val unit = new CompilationUnit (ctx.run.getSource(src.path))
162
165
enterScanned(unit)(ctx.run.runContext.fresh.setCompilationUnit(unit))
166
+ System .out.println(" done" )
163
167
}
164
168
}
165
169
else enterClassAndModule(owner, name, completer, scope = scope)
@@ -338,15 +342,8 @@ abstract class SymbolLoader extends LazyType {
338
342
postProcess(root.scalacLinkedClass.denot)
339
343
}
340
344
}
341
- }
342
-
343
- class ClassfileLoader (val classfile : AbstractFile ) extends SymbolLoader {
344
-
345
- override def sourceFileOrNull : AbstractFile = classfile
346
345
347
- def description (implicit ctx : Context ) = " class file " + classfile.toString
348
-
349
- def rootDenots (rootDenot : ClassDenotation )(implicit ctx : Context ): (ClassDenotation , ClassDenotation ) = {
346
+ protected def rootDenots (rootDenot : ClassDenotation )(implicit ctx : Context ): (ClassDenotation , ClassDenotation ) = {
350
347
val linkedDenot = rootDenot.scalacLinkedClass.denot match {
351
348
case d : ClassDenotation => d
352
349
case d =>
@@ -368,6 +365,13 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
368
365
if (rootDenot is ModuleClass ) (linkedDenot, rootDenot)
369
366
else (rootDenot, linkedDenot)
370
367
}
368
+ }
369
+
370
+ class ClassfileLoader (val classfile : AbstractFile ) extends SymbolLoader {
371
+
372
+ override def sourceFileOrNull : AbstractFile = classfile
373
+
374
+ def description (implicit ctx : Context ) = " class file " + classfile.toString
371
375
372
376
override def doComplete (root : SymDenotation )(implicit ctx : Context ): Unit =
373
377
load(root)
@@ -393,6 +397,20 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
393
397
class SourcefileLoader (val srcfile : AbstractFile ) extends SymbolLoader {
394
398
def description (implicit ctx : Context ) = " source file " + srcfile.toString
395
399
override def sourceFileOrNull = srcfile
396
- def doComplete (root : SymDenotation )(implicit ctx : Context ): Unit =
400
+ def doComplete (root : SymDenotation )(implicit ctx : Context ): Unit = {
397
401
ctx.run.enterRoots(srcfile)
402
+ if (ctx.settings.YretainTrees .value) {
403
+ val (classRoot, moduleRoot) = rootDenots(root.asClass)
404
+ classRoot.classSymbol.treeOrProvider = treeProvider
405
+ moduleRoot.classSymbol.treeOrProvider = treeProvider
406
+ }
407
+ }
408
+ object treeProvider extends tpd.TreeProvider {
409
+ def computeTrees (implicit ctx : Context ): List [tpd.Tree ] = {
410
+ var units = new CompilationUnit (ctx.run.getSource(srcfile.path)) :: Nil
411
+ for (phase <- ctx.allPhases; if phase.isTyper)
412
+ units = phase.runOn(units)
413
+ units.map(_.tpdTree)
414
+ }
415
+ }
398
416
}
0 commit comments