@@ -21,15 +21,15 @@ import StdNames._
21
21
import NameOps ._
22
22
import NameKinds .LazyImplicitName
23
23
import ast .tpd
24
- import tpd .{Tree , TreeProvider }
24
+ import tpd .{Tree , TreeProvider , TreeOps }
25
25
import ast .TreeTypeMap
26
26
import Constants .Constant
27
27
import reporting .diagnostic .Message
28
28
import Denotations .{ Denotation , SingleDenotation , MultiDenotation }
29
29
import collection .mutable
30
30
import io .AbstractFile
31
31
import language .implicitConversions
32
- import util .{NoSource , DotClass }
32
+ import util .{NoSource , DotClass , Property }
33
33
import scala .collection .JavaConverters ._
34
34
35
35
/** Creation methods for symbols */
@@ -402,6 +402,9 @@ object Symbols {
402
402
403
403
implicit def eqSymbol : Eq [Symbol , Symbol ] = Eq
404
404
405
+ /** Tree attachment containing the identifiers in a tree as a sorted array */
406
+ val Ids = new Property .Key [Array [String ]]
407
+
405
408
/** A Symbol represents a Scala definition/declaration or a package.
406
409
* @param coord The coordinates of the symbol (a position or an index)
407
410
* @param id A unique identifier of the symbol (unique per ContextBase)
@@ -654,7 +657,7 @@ object Symbols {
654
657
}
655
658
else tpd.EmptyTree
656
659
case tree : Tree @ unchecked =>
657
- tree
660
+ if (id.isEmpty || mightContain( tree, id)) tree else tpd. EmptyTree
658
661
}
659
662
}
660
663
@@ -663,6 +666,22 @@ object Symbols {
663
666
private [dotc] def treeOrProvider_= (t : TreeOrProvider )(implicit ctx : Context ): Unit =
664
667
myTree = t
665
668
669
+ private def mightContain (tree : Tree , id : String )(implicit ctx : Context ): Boolean = {
670
+ val ids = tree.getAttachment(Ids ) match {
671
+ case Some (ids) => ids
672
+ case None =>
673
+ val idSet = mutable.SortedSet [String ]()
674
+ tree.foreachSubTree {
675
+ case tree : tpd.RefTree => idSet += tree.name.toString
676
+ case _ =>
677
+ }
678
+ val ids = idSet.toArray
679
+ tree.putAttachment(Ids , ids)
680
+ ids
681
+ }
682
+ ids.binarySearch(id) >= 0
683
+ }
684
+
666
685
/** The source or class file from which this class was generated, null if not applicable. */
667
686
override def associatedFile (implicit ctx : Context ): AbstractFile =
668
687
if (assocFile != null || (this .owner is PackageClass ) || this .isEffectiveRoot) assocFile
0 commit comments