diff options
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 474958b86..592b7b55f 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -208,6 +208,10 @@ object Types { final def forallParts(p: Type => Boolean)(implicit ctx: Context): Boolean = !existsPart(!p(_)) + /** Performs operation on all parts of this type */ + final def foreachPart(p: Type => Unit)(implicit ctx: Context): Unit = + new ForeachAccumulator(p).apply((), this) + /** The parts of this type which are type or term refs */ final def namedParts(implicit ctx: Context): collection.Set[NamedType] = namedPartsWith(alwaysTrue) @@ -218,9 +222,6 @@ object Types { def namedPartsWith(p: NamedType => Boolean)(implicit ctx: Context): collection.Set[NamedType] = new NamedPartsAccumulator(p).apply(mutable.LinkedHashSet(), this) - // needed? - //final def foreach(f: Type => Unit): Unit = ??? - /** Map function `f` over elements of an AndType, rebuilding with function `g` */ def mapReduceAnd[T](f: Type => T)(g: (T, T) => T)(implicit ctx: Context): T = stripTypeVar match { case AndType(tp1, tp2) => g(tp1.mapReduceAnd(f)(g), tp2.mapReduceAnd(f)(g)) @@ -2571,6 +2572,11 @@ object Types { def apply(x: Boolean, tp: Type) = x || p(tp) || foldOver(x, tp) } + class ForeachAccumulator(p: Type => Unit)(implicit ctx: Context) extends TypeAccumulator[Unit] { + override def stopAtStatic = false + def apply(x: Unit, tp: Type): Unit = foldOver(p(tp), tp) + } + class NamedPartsAccumulator(p: NamedType => Boolean)(implicit ctx: Context) extends TypeAccumulator[mutable.Set[NamedType]] { override def stopAtStatic = false def maybeAdd(x: mutable.Set[NamedType], tp: NamedType) = if (p(tp)) x += tp else x |