@@ -490,57 +490,51 @@ object Implicits {
490
490
* the package was accessed in some way previously.
491
491
*/
492
492
class suggestions (qualifies : TermRef => Boolean ) with
493
- private type RootRef = TermRef | ThisType
494
-
495
- private def symbolOf (ref : RootRef )(given Context ) = ref match
496
- case ref : TermRef => ref.symbol
497
- case ref : ThisType => ref.cls
498
-
499
493
private val seen = mutable.Set [TermRef ]()
500
494
501
- private def lookInside (root : Symbol )(given ctx : Context ): Boolean =
495
+ private def lookInside (root : Symbol )(given Context ): Boolean =
502
496
if root.is(Package ) then root.isTerm && root.isCompleted
503
497
else ! root.name.is(FlatName )
504
498
&& ! root.name.lastPart.contains('$' )
505
499
&& root.is(ModuleVal , butNot = JavaDefined )
506
500
507
- def nestedRoots (ref : RootRef )(given Context ): List [Symbol ] =
501
+ def nestedRoots (site : Type )(given Context ): List [Symbol ] =
508
502
val seenNames = mutable.Set [Name ]()
509
- ref.widen .baseClasses.flatMap { bc =>
503
+ site .baseClasses.flatMap { bc =>
510
504
bc.info.decls.filter { dcl =>
511
505
lookInside(dcl)
512
506
&& ! seenNames.contains(dcl.name)
513
507
&& { seenNames += dcl.name; true }
514
508
}
515
509
}
516
510
517
- private def rootsStrictlyIn (ref : RootRef )(given ctx : Context ): List [TermRef ] =
518
- val refSym = symbolOf(ref)
511
+ private def rootsStrictlyIn (ref : Type )(given Context ): List [TermRef ] =
512
+ val site = ref.widen
513
+ val refSym = site.typeSymbol
519
514
val nested =
520
- if refSym == defn.EmptyPackageClass // Don't search the empty package, either as enclosing package ...
521
- || refSym == defn.EmptyPackageVal // ... or as a member of _root_.
522
- || refSym == defn.JavaPackageVal // As an optimization, don't search java...
523
- || refSym == defn.JavaLangPackageVal // ... or java.lang.
524
- then Nil
525
- else if refSym.is(Package ) || refSym.isPackageObject then
526
- refSym.info.decls.filter(lookInside)
515
+ if refSym.is(Package ) then
516
+ if refSym == defn.EmptyPackageClass // Don't search the empty package
517
+ || refSym == defn.JavaPackageClass // As an optimization, don't search java...
518
+ || refSym == defn.JavaLangPackageClass // ... or java.lang.
519
+ then Nil
520
+ else refSym.info.decls.filter(lookInside)
527
521
else
528
522
if ! refSym.is(Touched ) then refSym.ensureCompleted() // JavaDefined is reliably known only after completion
529
523
if refSym.is(JavaDefined ) then Nil
530
- else nestedRoots(ref )
524
+ else nestedRoots(site )
531
525
nested
532
526
.map(mbr => TermRef (ref, mbr.asTerm))
533
527
.flatMap(rootsIn)
534
528
.toList
535
529
536
- private def rootsIn (ref : TermRef )(given ctx : Context ): List [TermRef ] =
530
+ private def rootsIn (ref : TermRef )(given Context ): List [TermRef ] =
537
531
if seen.contains(ref) then Nil
538
532
else
539
533
implicits.println(i " search for suggestions in ${ref.symbol.fullName}" )
540
534
seen += ref
541
535
ref :: rootsStrictlyIn(ref)
542
536
543
- private def rootsOnPath (tp : Type )(given ctx : Context ): List [TermRef ] = tp match
537
+ private def rootsOnPath (tp : Type )(given Context ): List [TermRef ] = tp match
544
538
case ref : TermRef => rootsIn(ref) ::: rootsOnPath(ref.prefix)
545
539
case _ => Nil
546
540
@@ -549,15 +543,12 @@ object Implicits {
549
543
val defined =
550
544
if ctx.owner.isClass then
551
545
if ctx.owner eq ctx.outer.owner then Nil
552
- else ctx.owner.thisType match
553
- case ref : TermRef => rootsStrictlyIn(ref)
554
- case ref : ThisType => rootsStrictlyIn(ref)
555
- case _ => Nil
556
- else if ctx.scope eq ctx.outer.scope then Nil
546
+ else rootsStrictlyIn(ctx.owner.thisType)
557
547
else
558
- ctx.scope
559
- .filter(lookInside(_))
560
- .flatMap(sym => rootsIn(sym.termRef))
548
+ if ctx.scope eq ctx.outer.scope then Nil
549
+ else ctx.scope
550
+ .filter(lookInside(_))
551
+ .flatMap(sym => rootsIn(sym.termRef))
561
552
val imported =
562
553
if ctx.importInfo eq ctx.outer.importInfo then Nil
563
554
else ctx.importInfo.sym.info match
@@ -593,7 +584,7 @@ object Implicits {
593
584
catch
594
585
case ex : Throwable =>
595
586
if ctx.settings.Ydebug .value then
596
- println(" caught exceptioon when searching for suggestions" )
587
+ println(" caught exception when searching for suggestions" )
597
588
ex.printStackTrace()
598
589
Nil
599
590
finally timer.cancel()
0 commit comments