aboutsummaryrefslogtreecommitdiff
path: root/doc-tool/src/dotty/tools/dottydoc/util/Traversing.scala
blob: a3b60fa44aef68c18875a474c4955be4794b3bf3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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")
  }
}