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