diff options
Diffstat (limited to 'doc-tool/src/dotty/tools/dottydoc/util/traversing.scala')
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/util/traversing.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/util/traversing.scala b/doc-tool/src/dotty/tools/dottydoc/util/traversing.scala new file mode 100644 index 000000000..9c2e3bf54 --- /dev/null +++ b/doc-tool/src/dotty/tools/dottydoc/util/traversing.scala @@ -0,0 +1,43 @@ +package dotty.tools.dottydoc +package util + +object traversing { + import model._ + + def mutateEntities(e: Entity)(trans: Entity => Unit): Unit = e match { + case e: Entity with Members => + trans(e) + e.members.map(mutateEntities(_)(trans)) + case e: Entity => trans(e) + } + + def relativePath(from: Entity, to: Entity) = { + val offset = from match { + case v: Val if v.implicitlyAddedFrom.isDefined => 3 + case d: Def if d.implicitlyAddedFrom.isDefined => 3 + case _: Val | _: Def => 2 + case _ => 1 + } + + "../" * (from.path.length - offset) + + to.path.mkString("", "/", ".html") + } + + + def rootPackages(pkgs: Map[String, Package]): List[String] = { + var currentDepth = Int.MaxValue + var packs = List.empty[String] + + for (key <- pkgs.keys) { + val keyDepth = key.split("\\.").length + packs = + if (keyDepth < currentDepth) { + currentDepth = keyDepth + key :: Nil + } else if (keyDepth == currentDepth) { + key :: packs + } else packs + } + packs + } +} |