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

dotty.tools.scaladoc.ScalaModuleProvider.scala Maven / Gradle / Ivy

There is a newer version: 3.6.0-RC1-bin-20240917-6e852d2-NIGHTLY
Show newest version
package dotty.tools.scaladoc

import dotty.tools.scaladoc.tasty.ScaladocTastyInspector
import scala.jdk.CollectionConverters._
import transformers._

case class Module(rootPackage: Member, members: Map[DRI, Member])

object ScalaModuleProvider:
  def mkModule()(using ctx: DocContext): Module =
    val (result, rootDoc) = ScaladocTastyInspector.loadDocs()
    val (rootPck, rest) = result.partition(_.name == "API")
    val (emptyPackages, nonemptyPackages) = (rest ++ rootPck.flatMap(_.members))
      .filter(p => p.members.nonEmpty || p.docs.nonEmpty).sortBy(_.name)
      .partition(_.name == "")

    val groupedMembers =
      def groupMembers(ms: List[Member], n: Int = 0): List[Member] =
        ms.groupBy(_.name.split('.')(n)).values.map {
          case m :: ms if m.name.count(_ == '.') == n =>
            m.withMembers(groupMembers(ms, n + 1) ++ m.members)
          case ms =>
            groupMembers(ms, n + 1) match
              case m :: Nil => m
              case ms =>
                val name = ms.head.name.split('.').take(n + 1).mkString(".")
                Member(
                  name = name,
                  fullName = name,
                  dri = DRI(location = name),
                  kind = Kind.Package,
                  members = ms,
                )
        }.toList.sortBy(_.name)
      groupMembers(nonemptyPackages).reverse

    val packageMembers = groupedMembers ++ emptyPackages.flatMap(_.members)

    def flattenMember(m: Member): Seq[(DRI, Member)] = (m.dri -> m) +: m.members.flatMap(flattenMember)

    val topLevelPackage =
      Member("API", "", site.apiPageDRI, Kind.RootPackage, members = packageMembers, docs = rootDoc)

    val original = Module(topLevelPackage, flattenMember(topLevelPackage).toMap)

    val transformers = List(
      ImplicitMembersExtensionTransformer(),
      InheritanceInformationTransformer(),
      SealedMarksGraphTransformer()
    )
    transformers.foldLeft(original)((module, transformer) => transformer.apply(module))




© 2015 - 2024 Weber Informatics LLC | Privacy Policy