All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dotty.tools.dottydoc.util.traversing.scala Maven / Gradle / Ivy

There is a newer version: 3.0.0-M1-bin-20201029-1f433d5-NIGHTLY
Show newest version
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[Package] = {
    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.map(pkgs.apply)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy