scala.tools.nsc.doc.model.IndexModelFactory.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala-compiler Show documentation
Show all versions of scala-compiler Show documentation
Compiler for the Scala Programming Language
The newest version!
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/
package scala
package tools.nsc
package doc
package model
import scala.collection._
object IndexModelFactory {
def makeIndex(universe: Universe): Index = new Index {
lazy val (firstLetterIndex, hasDeprecatedMembers): (Map[Char, SymbolMap], Boolean) = {
object result extends mutable.HashMap[Char,SymbolMap] {
var deprecated = false
/* symbol name ordering */
implicit def orderingMap = math.Ordering.String
def addMember(d: MemberEntity) = {
val firstLetter = {
val ch = d.name.head.toLower
if(ch.isLetterOrDigit) ch else '_'
}
val letter = this.get(firstLetter).getOrElse {
immutable.SortedMap[String, SortedSet[MemberEntity]]()
}
val members = letter.get(d.name).getOrElse {
SortedSet.empty[MemberEntity](Ordering.by { _.toString })
} + d
if (!deprecated && members.find(_.deprecation.isDefined).isDefined)
deprecated = true
this(firstLetter) = letter + (d.name -> members)
}
}
//@scala.annotation.tailrec // TODO
def gather(owner: DocTemplateEntity): Unit =
for(m <- owner.members if m.inDefinitionTemplates.isEmpty || m.inDefinitionTemplates.head == owner)
m match {
case tpl: DocTemplateEntity =>
result.addMember(tpl)
gather(tpl)
case non: MemberEntity if !non.isConstructor =>
result.addMember(non)
case x @ _ =>
}
gather(universe.rootPackage)
(result.toMap, result.deprecated)
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy