aboutsummaryrefslogtreecommitdiff
path: root/dottydoc
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-06-25 11:24:32 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-08-19 15:37:28 +0200
commit81a86be75dd45f6e3eae4bb5fdd016058738c497 (patch)
treee7632094cd1f288cdb3bf2513a7786b68c0498ff /dottydoc
parent76413f003945140e5b502e6ad7b8fb058e6e6ade (diff)
downloaddotty-81a86be75dd45f6e3eae4bb5fdd016058738c497.tar.gz
dotty-81a86be75dd45f6e3eae4bb5fdd016058738c497.tar.bz2
dotty-81a86be75dd45f6e3eae4bb5fdd016058738c497.zip
Materialize parameter list references
Diffstat (limited to 'dottydoc')
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/core/DocPhase.scala15
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/model/parsers.scala45
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala7
-rw-r--r--dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala17
4 files changed, 61 insertions, 23 deletions
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/DocPhase.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/DocPhase.scala
index 71d33950e..522b224d1 100644
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/DocPhase.scala
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/DocPhase.scala
@@ -11,7 +11,7 @@ import dotc.core.Phases.Phase
import dotc.core.Symbols.Symbol
class DocPhase extends Phase {
- import model.parsers.{ WikiParser, ReturnTypeParser }
+ import model.parsers.{ WikiParser, ReturnTypeLinker, ParamListLinker }
import model._
import model.factories._
import model.internal._
@@ -24,7 +24,10 @@ class DocPhase extends Phase {
def phaseName = "docphase"
private[this] val commentParser = new WikiParser
- private[this] val returnLinker = new ReturnTypeParser
+ private[this] val linkers =
+ new ReturnTypeLinker ::
+ new ParamListLinker ::
+ Nil
/** Saves the commentParser function for later evaluation, for when the AST has been filled */
def track(symbol: Symbol, ctx: Context)(op: => Entity) = {
@@ -59,11 +62,11 @@ class DocPhase extends Phase {
def addedFromSymbol(sym: Symbol): List[Entity] = {
val defs = sym.info.membersBasedOnFlags(Flags.Method, Flags.Synthetic | Flags.Private).map { meth =>
track(meth.symbol, ctx) {
- DefImpl(meth.symbol.name.decode.toString, Nil, path(meth.symbol), returnType(meth.info), typeParams(meth.symbol), Nil/*paramLists(???)*/)
+ DefImpl(meth.symbol.name.decode.toString, Nil, path(meth.symbol), returnType(meth.info), typeParams(meth.symbol), paramLists(meth.info))
}
}.toList
- val vals = sym.info.fields.map { value =>
+ val vals = sym.info.fields.filterNot(_.symbol.is(Flags.Private | Flags.Synthetic)).map { value =>
track(value.symbol, ctx) {
ValImpl(value.symbol.name.decode.toString, Nil, path(value.symbol), returnType(value.info))
}
@@ -104,7 +107,7 @@ class DocPhase extends Phase {
/** def */
case d: DefDef =>
- DefImpl(d.name.decode.toString, flags(d), path(d.symbol), returnType(d.tpt.tpe), typeParams(d.symbol), paramLists(d))
+ DefImpl(d.name.decode.toString, flags(d), path(d.symbol), returnType(d.tpt.tpe), typeParams(d.symbol), paramLists(d.symbol.info))
/** val */
case v: ValDef if !v.symbol.is(Flags.ModuleVal) =>
@@ -164,7 +167,7 @@ class DocPhase extends Phase {
// (3) Set returntypes to correct entities
- returnLinker.link(packages)
+ for (linker <- linkers) linker.link(packages)
// (3) Create documentation template from docstrings, with internal links
println("Generating documentation, this might take a while...")
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/parsers.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/parsers.scala
index d73f8fe9f..2c163b1e6 100644
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/model/parsers.scala
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/parsers.scala
@@ -84,16 +84,9 @@ object parsers {
def clear(): Unit = commentCache = Map.empty
}
- class ReturnTypeParser extends MemberLookup {
- def link(packs: Map[String, Package]): Unit =
- for (pack <- packs.values) mutateEntities(pack) {
- case ent: ReturnValue =>
- setReturnValue(ent, returnValue(ent, ent, packs))
- case _ => ()
- }
-
- private def returnValue(ent: Entity, rv: ReturnValue, packs: Map[String, Package]): Reference =
- rv.returnValue match {
+ sealed trait TypeLinker extends MemberLookup {
+ protected def linkReference(ent: Entity, rv: Reference, packs: Map[String, Package]): Reference =
+ rv match {
case rv @ TypeReference(_, UnsetLink(t, query), tps) =>
val inlineToHtml = InlineToHtml(ent)
val title = inlineToHtml(t)
@@ -113,7 +106,37 @@ object parsers {
}
rv.copy(tpeLink = target, paramLinks = tpTargets)
- case _ => rv.returnValue
+ case rv @ OrTypeReference(left, right) =>
+ rv.copy(left = linkReference(ent, left, packs), right = linkReference(ent, right, packs))
+ case rv @ AndTypeReference(left, right) =>
+ rv.copy(left = linkReference(ent, left, packs), right = linkReference(ent, right, packs))
+ case rv @ NamedReference(_, ref) => rv.copy(ref = linkReference(ent, ref, packs))
+ case _ => rv
+ }
+
+ def link(packs: Map[String, Package]): Unit
+ }
+
+ class ReturnTypeLinker extends TypeLinker {
+ def link(packs: Map[String, Package]): Unit =
+ for (pack <- packs.values) mutateEntities(pack) {
+ case ent: ReturnValue =>
+ setReturnValue(ent, linkReference(ent, ent.returnValue, packs))
+ case _ => ()
+ }
+ }
+
+ class ParamListLinker extends TypeLinker {
+ def link(packs: Map[String, Package]): Unit =
+ for (pack <- packs.values) mutateEntities(pack) {
+ case ent: Def =>
+ val newParamLists = for {
+ list <- ent.paramLists
+ newList = list.map(linkReference(ent, _, packs))
+ } yield newList.asInstanceOf[List[NamedReference]]
+
+ setParamLists(ent, newParamLists)
+ case _ => ()
}
}
}
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala
index e6f1e6245..4ce94459d 100644
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala
@@ -4,7 +4,7 @@ package internal
object setters {
import model._
- import comment.{ Comment, MaterializableLink, Reference }
+ import comment.{ Comment, MaterializableLink, Reference, NamedReference }
import internal._
def setComment(ent: Entity, to: Option[Comment]) = ent match {
@@ -24,6 +24,11 @@ object setters {
case _ => ()
}
+ def setParamLists(ent: Entity, refs: List[List[NamedReference]]) = ent match {
+ case x: DefImpl => x.paramLists = refs
+ case _ => ()
+ }
+
def setParent(ent: Entity, to: Entity): Unit = ent match {
case e: ClassImpl =>
e.parent = to
diff --git a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala
index eb0f54480..c2c7f9940 100644
--- a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala
+++ b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala
@@ -107,11 +107,18 @@ object factories {
case _ => Nil
}
- def paramLists(t: DefDef)(implicit ctx: Context): List[List[NamedReference]] = {
- def getParams(xs: List[ValDef]): List[NamedReference] =
- xs.map(vd => NamedReference(vd.name.decode.toString, returnType(vd.tpt.tpe)))
-
- t.vparamss.map(getParams)
+ def paramLists(tpe: Type)(implicit ctx: Context): List[List[NamedReference]] = tpe match {
+ case pt: PolyType =>
+ paramLists(pt.resultType)
+
+ case mt: MethodType =>
+ mt.paramNames.zip(mt.paramTypes).map { case (name, tpe) =>
+ NamedReference(name.decode.toString, returnType(tpe))
+ } :: paramLists(mt.resultType)
+
+ case annot: AnnotatedType => paramLists(annot.tpe)
+ case (_: PolyParam | _: RefinedType | _: TypeRef | _: ThisType |
+ _: ExprType | _: OrType | _: AndType) => Nil // return types should not be in the paramlist
}
def superTypes(t: Tree)(implicit ctx: Context): List[MaterializableLink] = t.symbol.denot match {