<commit_before>package dotty.dokka

import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.util.chaining._
import org.jetbrains.dokka.base.translators.documentables.{DefaultPageCreator, PageContentBuilder}
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder$DocumentableContentBuilder
import org.jetbrains.dokka.base.signatures.SignatureProvider
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.dokka.model._
import org.jetbrains.dokka.pages._
import collection.JavaConverters._
import org.jetbrains.dokka.model.properties._
import org.jetbrains.dokka.base.transformers.documentables.CallableExtensions
import org.jetbrains.dokka.DokkaConfiguration$DokkaSourceSet
import org.jetbrains.dokka.base.resolvers.anchors._
import org.jetbrains.dokka.model.doc._
import dotty.dokka.model.api._
import dotty.dokka.model.api.Kind
import dotty.dokka.model.api.Link

type DocBuilder = ScalaPageContentBuilder#ScalaDocumentableContentBuilder

class ScalaPageCreator(
  commentsToContentConverter: CommentsToContentConverter,
  signatureProvider: SignatureProvider,
)(using ctx: DocContext)
  extends DefaultPageCreator(commentsToContentConverter, signatureProvider, ctx.logger):

  private val contentBuilder =
    ScalaPageContentBuilder(commentsToContentConverter, signatureProvider)

  override def pageForModule(m: DModule): ModulePageNode = super.pageForModule(m)

  private def updatePageNameForMember(page: PageNode, p: Member) =
    val name = page.getName

    page.modified(name, page.getChildren)

  private def pagesForMembers(p: Member): Seq[PageNode] =
    p.allMembers.filter(_.origin == Origin.DefinedWithin).collect {
      case f: DFunction => updatePageNameForMember(pageForFunction(f), f)
      case c: DClass => updatePageNameForMember(pageForDClass(c), c)
    }

  override def pageForPackage(p: DPackage): PackagePageNode =
    val originalPage = super.pageForPackage(p)
    val originalPages: Seq[PageNode] = originalPage.getChildren.asScala.toList
    val allPage: Seq[PageNode] = originalPages ++ pagesForMembers(p)
    originalPage.modified(p.getName, allPage.asJava)

  override def pageForClasslike(c: DClasslike): ClasslikePageNode = c match {
      case clazz: DClass => pageForDClass(clazz)
      case other => throw UnsupportedOperationException("Only DClass classlike is supported.")
    }

  def pageForDClass(c: DClass): ClasslikePageNode = {
    val constructors = c.getConstructors

    val ext = c.get(ClasslikeExtension)

    val name = if c.kind == Kind.Object && ext.companion.isDefined then c.getName + "$" else c.getName

    ClasslikePageNode(
      name,
      contentForClasslike(c),
      JSet(c.getDri),
      c,
      (constructors.asScala.map(pageForFunction) ++
      c.getClasslikes.asScala.map(pageForClasslike) ++
      c.getFunctions.asScala.map(pageForFunction) ++
      pagesForMembers(c)).asJava,
      List.empty.asJava
    )

  }

  override def pageForFunction(f: DFunction) = super.pageForFunction(f)

  override def contentForModule(m: DModule) = {
    def buildBlock = (builder: DocBuilder) => builder
      .group(kind = ContentKind.Cover) { gbuilder => gbuilder
        .cover(m.getName)()
        .descriptionIfNotEmpty(m)
      }
      .addChildren(contentForComments(m).asScala.toSeq)
      .groupingBlock(
        "Packages",
        List("" -> m.getPackages.asScala.toList),
        kind = ContentKind.Packages,
        sourceSets = m.getSourceSets.asScala.toSet
      )(
        (bdr, elem) => bdr
      ) { (bdr, elem) => bdr
        .driLink(elem.getName, elem.getDri)
      }

    contentBuilder.contentForDocumentable(m, buildBlock = buildBlock)
  }

  override def contentForPackage(p: DPackage) = {
    def buildBlock = (builder: DocBuilder) => builder
      .group(kind = ContentKind.Cover) { gbuilder => gbuilder
        .cover(p.getName)()
        .descriptionIfNotEmpty(p)
      }
      .documentableFilter()
      .group(styles = Set(ContentStyle.TabbedContent)) { b => b
        .contentForScope(p)<commit_msg>Do not render empty packages in package list<commit_after>package dotty.dokka

import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.util.chaining._
import org.jetbrains.dokka.base.translators.documentables.{DefaultPageCreator, PageContentBuilder}
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder$DocumentableContentBuilder
import org.jetbrains.dokka.base.signatures.SignatureProvider
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.dokka.model._
import org.jetbrains.dokka.pages._
import collection.JavaConverters._
import org.jetbrains.dokka.model.properties._
import org.jetbrains.dokka.base.transformers.documentables.CallableExtensions
import org.jetbrains.dokka.DokkaConfiguration$DokkaSourceSet
import org.jetbrains.dokka.base.resolvers.anchors._
import org.jetbrains.dokka.model.doc._
import dotty.dokka.model.api._
import dotty.dokka.model.api.Kind
import dotty.dokka.model.api.Link

type DocBuilder = ScalaPageContentBuilder#ScalaDocumentableContentBuilder

class ScalaPageCreator(
  commentsToContentConverter: CommentsToContentConverter,
  signatureProvider: SignatureProvider,
)(using ctx: DocContext)
  extends DefaultPageCreator(commentsToContentConverter, signatureProvider, ctx.logger):

  private val contentBuilder =
    ScalaPageContentBuilder(commentsToContentConverter, signatureProvider)

  override def pageForModule(m: DModule): ModulePageNode = super.pageForModule(m)

  private def updatePageNameForMember(page: PageNode, p: Member) =
    val name = page.getName

    page.modified(name, page.getChildren)

  private def pagesForMembers(p: Member): Seq[PageNode] =
    p.allMembers.filter(_.origin == Origin.DefinedWithin).collect {
      case f: DFunction => updatePageNameForMember(pageForFunction(f), f)
      case c: DClass => updatePageNameForMember(pageForDClass(c), c)
    }

  override def pageForPackage(p: DPackage): PackagePageNode =
    val originalPage = super.pageForPackage(p)
    val originalPages: Seq[PageNode] = originalPage.getChildren.asScala.toList
    val allPage: Seq[PageNode] = originalPages ++ pagesForMembers(p)
    originalPage.modified(p.getName, allPage.asJava)

  override def pageForClasslike(c: DClasslike): ClasslikePageNode = c match {
      case clazz: DClass => pageForDClass(clazz)
      case other => throw UnsupportedOperationException("Only DClass classlike is supported.")
    }

  def pageForDClass(c: DClass): ClasslikePageNode = {
    val constructors = c.getConstructors

    val ext = c.get(ClasslikeExtension)

    val name = if c.kind == Kind.Object && ext.companion.isDefined then c.getName + "$" else c.getName

    ClasslikePageNode(
      name,
      contentForClasslike(c),
      JSet(c.getDri),
      c,
      (constructors.asScala.map(pageForFunction) ++
      c.getClasslikes.asScala.map(pageForClasslike) ++
      c.getFunctions.asScala.map(pageForFunction) ++
      pagesForMembers(c)).asJava,
      List.empty.asJava
    )

  }

  override def pageForFunction(f: DFunction) = super.pageForFunction(f)

  override def contentForModule(m: DModule) = {
    def buildBlock = (builder: DocBuilder) => builder
      .group(kind = ContentKind.Cover) { gbuilder => gbuilder
        .cover(m.getName)()
        .descriptionIfNotEmpty(m)
      }
      .addChildren(contentForComments(m).asScala.toSeq)
      .groupingBlock(
        "Packages",
        List("" -> m.getPackages.asScala.toList.filter(_.allMembers.nonEmpty)),
        kind = ContentKind.Packages,
        sourceSets = m.getSourceSets.asScala.toSet
      )(
        (bdr, elem) => bdr
      ) { (bdr, elem) => bdr
        .driLink(elem.getName, elem.getDri)
      }

    contentBuilder.contentForDocumentable(m, buildBlock = buildBlock)
  }

  override def contentForPackage(p: DPackage) = {
    def buildBlock = (builder: DocBuilder) => builder
      .group(kind = ContentKind.Cover) { gbuilder => gbuilder
        .cover(p.getName)()
        .descriptionIfNotEmpty(p)
      }
      .documentableFilter()
      .group(styles = Set(ContentStyle.TabbedContent)) { b => b
        .contentForScope(p)
{'fraction_non_alphanumeric': 0.10055144902029801, 'fraction_numerical': 0.0, 'mean_word_length': 4.271490414347557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3107244', 'n_tokens_mistral': 2685, 'n_tokens_neox': 2615, 'n_words': 460}