@@ -394,20 +394,13 @@ object Types {
394
394
final def foreachPart (p : Type => Unit , stopAtStatic : Boolean = false )(using Context ): Unit =
395
395
new ForeachAccumulator (p, stopAtStatic).apply((), this )
396
396
397
- /** The parts of this type which are type or term refs */
398
- final def namedParts (using Context ): collection.Set [NamedType ] =
399
- namedPartsWith(alwaysTrue)
400
-
401
397
/** The parts of this type which are type or term refs and which
402
398
* satisfy predicate `p`.
403
399
*
404
400
* @param p The predicate to satisfy
405
- * @param excludeLowerBounds If set to true, the lower bounds of abstract
406
- * types will be ignored.
407
401
*/
408
- def namedPartsWith (p : NamedType => Boolean , excludeLowerBounds : Boolean = false )
409
- (using Context ): collection.Set [NamedType ] =
410
- new NamedPartsAccumulator (p, excludeLowerBounds).apply(mutable.LinkedHashSet (), this )
402
+ def namedPartsWith (p : NamedType => Boolean )(using Context ): List [NamedType ] =
403
+ new NamedPartsAccumulator (p).apply(Nil , this )
411
404
412
405
/** Map function `f` over elements of an AndType, rebuilding with function `g` */
413
406
def mapReduceAnd [T ](f : Type => T )(g : (T , T ) => T )(using Context ): T = stripTypeVar match {
@@ -5538,38 +5531,34 @@ object Types {
5538
5531
override def hash (x : Type ): Int = System .identityHashCode(x)
5539
5532
override def isEqual (x : Type , y : Type ) = x.eq(y)
5540
5533
5541
- class NamedPartsAccumulator (p : NamedType => Boolean , excludeLowerBounds : Boolean = false )
5542
- (using Context ) extends TypeAccumulator [mutable.Set [NamedType ]] {
5543
- override def stopAtStatic : Boolean = false
5544
- def maybeAdd (x : mutable.Set [NamedType ], tp : NamedType ): mutable.Set [NamedType ] = if (p(tp)) x += tp else x
5534
+ class NamedPartsAccumulator (p : NamedType => Boolean )(using Context )
5535
+ extends TypeAccumulator [List [NamedType ]]:
5536
+ def maybeAdd (xs : List [NamedType ], tp : NamedType ): List [NamedType ] = if p(tp) then tp :: xs else xs
5545
5537
val seen = TypeHashSet ()
5546
- def apply (x : mutable. Set [NamedType ], tp : Type ): mutable. Set [NamedType ] =
5547
- if ( seen contains tp) x
5548
- else {
5538
+ def apply (xs : List [NamedType ], tp : Type ): List [NamedType ] =
5539
+ if seen contains tp then xs
5540
+ else
5549
5541
seen.addEntry(tp)
5550
- tp match {
5542
+ tp match
5551
5543
case tp : TypeRef =>
5552
- foldOver(maybeAdd(x , tp), tp)
5544
+ foldOver(maybeAdd(xs , tp), tp)
5553
5545
case tp : ThisType =>
5554
- apply(x , tp.tref)
5546
+ apply(xs , tp.tref)
5555
5547
case NoPrefix =>
5556
- foldOver(x , tp)
5548
+ foldOver(xs , tp)
5557
5549
case tp : TermRef =>
5558
- apply(foldOver(maybeAdd(x , tp), tp), tp.underlying)
5550
+ apply(foldOver(maybeAdd(xs , tp), tp), tp.underlying)
5559
5551
case tp : AppliedType =>
5560
- foldOver(x , tp)
5552
+ foldOver(xs , tp)
5561
5553
case TypeBounds (lo, hi) =>
5562
- if (! excludeLowerBounds) apply(x, lo)
5563
- apply(x, hi)
5554
+ apply(apply(xs, lo), hi)
5564
5555
case tp : ParamRef =>
5565
- apply(x , tp.underlying)
5556
+ apply(xs , tp.underlying)
5566
5557
case tp : ConstantType =>
5567
- apply(x , tp.underlying)
5558
+ apply(xs , tp.underlying)
5568
5559
case _ =>
5569
- foldOver(x, tp)
5570
- }
5571
- }
5572
- }
5560
+ foldOver(xs, tp)
5561
+ end NamedPartsAccumulator
5573
5562
5574
5563
class isGroundAccumulator (using Context ) extends TypeAccumulator [Boolean ] {
5575
5564
def apply (x : Boolean , tp : Type ): Boolean = x && {
0 commit comments