@@ -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 */
@@ -400,6 +400,9 @@ object Symbols {
400
400
401
401
implicit def eqSymbol : Eq [Symbol , Symbol ] = Eq
402
402
403
+ /** Tree attachment containing the identifiers in a tree as a sorted array */
404
+ val Ids = new Property .Key [Array [String ]]
405
+
403
406
/** A Symbol represents a Scala definition/declaration or a package.
404
407
* @param coord The coordinates of the symbol (a position or an index)
405
408
* @param id A unique identifier of the symbol (unique per ContextBase)
@@ -652,7 +655,7 @@ object Symbols {
652
655
}
653
656
else tpd.EmptyTree
654
657
case tree : Tree @ unchecked =>
655
- tree
658
+ if (id.isEmpty || mightContain( tree, id)) tree else tpd. EmptyTree
656
659
}
657
660
}
658
661
@@ -661,6 +664,22 @@ object Symbols {
661
664
private [dotc] def treeOrProvider_= (t : TreeOrProvider )(implicit ctx : Context ): Unit =
662
665
myTree = t
663
666
667
+ private def mightContain (tree : Tree , id : String )(implicit ctx : Context ): Boolean = {
668
+ val ids = tree.getAttachment(Ids ) match {
669
+ case Some (ids) => ids
670
+ case None =>
671
+ val idSet = mutable.SortedSet [String ]()
672
+ tree.foreachSubTree {
673
+ case tree : tpd.RefTree => idSet += tree.name.toString
674
+ case _ =>
675
+ }
676
+ val ids = idSet.toArray
677
+ tree.putAttachment(Ids , ids)
678
+ ids
679
+ }
680
+ ids.binarySearch(id) >= 0
681
+ }
682
+
664
683
/** The source or class file from which this class was generated, null if not applicable. */
665
684
override def associatedFile (implicit ctx : Context ): AbstractFile =
666
685
if (assocFile != null || (this .owner is PackageClass ) || this .isEffectiveRoot) assocFile
0 commit comments