aboutsummaryrefslogtreecommitdiff
path: root/doc-tool
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-01-19 16:38:48 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-01-31 14:32:40 +0100
commit384f5a0dba5c2102327015c67781462ba475e43a (patch)
tree895076c663f35006b9069d0433f1b1ab1678655b /doc-tool
parent821b3faa52dff3850016c4620ee0cef6f7b3897f (diff)
downloaddotty-384f5a0dba5c2102327015c67781462ba475e43a.tar.gz
dotty-384f5a0dba5c2102327015c67781462ba475e43a.tar.bz2
dotty-384f5a0dba5c2102327015c67781462ba475e43a.zip
Link companions in doc AST
Diffstat (limited to 'doc-tool')
-rw-r--r--doc-tool/resources/_layouts/doc.html3
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala1
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala2
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/core/LinkCompanionsPhase.scala46
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala12
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/model/entities.scala18
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/model/internal.scala12
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/model/java.scala16
8 files changed, 92 insertions, 18 deletions
diff --git a/doc-tool/resources/_layouts/doc.html b/doc-tool/resources/_layouts/doc.html
index c9dc8da39..b6c9a7053 100644
--- a/doc-tool/resources/_layouts/doc.html
+++ b/doc-tool/resources/_layouts/doc.html
@@ -16,7 +16,8 @@ layout: main
<a href="{{ site.baseurl }}/api/{{ pkg.path | join: "/" }}/index.html">{{ pkg.name }}</a>
</li>
{% for member in pkg.children %}
- {% if member.kind != "package" %}
+ {% if member.kind == "object" and member.hasCompanion %}
+ {% elsif member.kind != "package" %}
<li class="index-entity">
<a href="{{ site.baseurl }}/api/{{ member.path | join: "/" }}.html">{{ member.kind }} {{ member.name }}</a>
</li>
diff --git a/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala b/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala
index 55b079adf..081883597 100644
--- a/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala
@@ -30,6 +30,7 @@ class DocCompiler extends Compiler {
new LinkParamListTypes,
new LinkImplicitlyAddedTypes,
new LinkSuperTypes,
+ new LinkCompanions,
new AlternateConstructors,
new SortMembers))
)
diff --git a/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala b/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala
index f8ffdc0aa..411818614 100644
--- a/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala
@@ -111,7 +111,7 @@ class DocASTPhase extends Phase {
/** class / case class */
case c @ TypeDef(n, rhs) if c.symbol.isClass =>
//TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well
- (c.symbol, annotations(c.symbol), n.show, collectMembers(rhs), flags(c), path(c.symbol), typeParams(c.symbol), constructors(c.symbol), superTypes(c), None) match {
+ (c.symbol, annotations(c.symbol), n.show, collectMembers(rhs), flags(c), path(c.symbol), typeParams(c.symbol), constructors(c.symbol), superTypes(c), None, Nil) match {
case x if c.symbol.is(Flags.CaseClass) => CaseClassImpl.tupled(x)
case x => ClassImpl.tupled(x)
}
diff --git a/doc-tool/src/dotty/tools/dottydoc/core/LinkCompanionsPhase.scala b/doc-tool/src/dotty/tools/dottydoc/core/LinkCompanionsPhase.scala
new file mode 100644
index 000000000..82bd90da0
--- /dev/null
+++ b/doc-tool/src/dotty/tools/dottydoc/core/LinkCompanionsPhase.scala
@@ -0,0 +1,46 @@
+package dotty.tools
+package dottydoc
+package core
+
+import dotc.core.Contexts.Context
+import dotc.ast.tpd
+
+import transform.DocMiniPhase
+import model.internal._
+import model._
+import model.factories._
+import dotty.tools.dotc.core.Symbols.Symbol
+import util.syntax._
+
+class LinkCompanions extends DocMiniPhase {
+ private def linkCompanions(ent: Entity)(implicit ctx: Context): ent.type = {
+ ent.children.groupBy(_.name).foreach {
+ case (_, List(x1: Companion, x2: Companion)) => {
+ x1.companionPath = x2.path
+ x2.companionPath = x1.path
+ }
+ case _ => ()
+ }
+ ent
+ }
+
+ override def transformPackage(implicit ctx: Context) = { case ent: PackageImpl =>
+ linkCompanions(ent)
+ }
+
+ override def transformClass(implicit ctx: Context) = { case ent: ClassImpl =>
+ linkCompanions(ent)
+ }
+
+ override def transformCaseClass(implicit ctx: Context) = { case ent: CaseClassImpl =>
+ linkCompanions(ent)
+ }
+
+ override def transformObject(implicit ctx: Context) = { case ent: ObjectImpl =>
+ linkCompanions(ent)
+ }
+
+ override def transformTrait(implicit ctx: Context) = { case ent: TraitImpl =>
+ linkCompanions(ent)
+ }
+}
diff --git a/doc-tool/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala b/doc-tool/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala
index a35da579e..1cfcec09a 100644
--- a/doc-tool/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala
@@ -121,7 +121,8 @@ object transform {
cls.typeParams,
cls.constructors,
cls.superTypes,
- cls.comment
+ cls.comment,
+ cls.companionPath
)
}
case cc: CaseClass => transformEntity(cc, _.caseClassTransformation) { cc =>
@@ -135,7 +136,8 @@ object transform {
cc.typeParams,
cc.constructors,
cc.superTypes,
- cc.comment
+ cc.comment,
+ cc.companionPath
)
}
case trt: Trait => transformEntity(trt, _.traitTransformation) { trt =>
@@ -149,7 +151,8 @@ object transform {
trt.typeParams,
trt.traitParams,
trt.superTypes,
- trt.comment
+ trt.comment,
+ trt.companionPath
)
}
case obj: Object => transformEntity(obj, _.objectTransformation) { obj =>
@@ -161,7 +164,8 @@ object transform {
obj.modifiers,
obj.path,
obj.superTypes,
- obj.comment
+ obj.comment,
+ obj.companionPath
)
}
case df: Def => transformEntity(df, _.defTransformation) { df =>
diff --git a/doc-tool/src/dotty/tools/dottydoc/model/entities.scala b/doc-tool/src/dotty/tools/dottydoc/model/entities.scala
index 613788964..7027a72eb 100644
--- a/doc-tool/src/dotty/tools/dottydoc/model/entities.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/model/entities.scala
@@ -80,6 +80,14 @@ trait Constructors {
def constructors: List[List[ParamList]]
}
+trait Companion extends Entity {
+ def hasCompanion: Boolean = companionPath ne Nil
+
+ def companionPath: List[String]
+
+ def companionPath_=(xs: List[String]): Unit
+}
+
trait ImplicitlyAddedEntity extends Entity {
def implicitlyAddedFrom: Option[Reference]
}
@@ -94,20 +102,20 @@ trait TypeAlias extends Entity with Modifiers {
def isAbstract: Boolean = !alias.isDefined
}
-trait Class extends Entity with Modifiers with TypeParams with Constructors with SuperTypes with Members {
+trait Class extends Entity with Modifiers with TypeParams with Constructors with SuperTypes with Members with Companion {
val kind = "class"
}
-trait CaseClass extends Entity with Modifiers with TypeParams with Constructors with SuperTypes with Members {
+trait CaseClass extends Entity with Modifiers with TypeParams with Constructors with SuperTypes with Members with Companion {
override val kind = "case class"
}
-trait Trait extends Entity with Modifiers with TypeParams with SuperTypes with Members {
+trait Trait extends Entity with Modifiers with TypeParams with SuperTypes with Members with Companion {
def traitParams: List[ParamList]
override val kind = "trait"
}
-trait Object extends Entity with Modifiers with SuperTypes with Members {
+trait Object extends Entity with Modifiers with SuperTypes with Members with Companion {
override val kind = "object"
}
@@ -137,6 +145,8 @@ sealed trait NonEntity extends Package with TypeAlias with Class with CaseClass
val typeParams = Nil
val traitParams = Nil
val alias = None
+ val companionPath = Nil
+ def companionPath_=(xs: List[String]) = ()
}
final case object NonEntity extends NonEntity
diff --git a/doc-tool/src/dotty/tools/dottydoc/model/internal.scala b/doc-tool/src/dotty/tools/dottydoc/model/internal.scala
index ac789f29f..fe21a0a0a 100644
--- a/doc-tool/src/dotty/tools/dottydoc/model/internal.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/model/internal.scala
@@ -41,7 +41,8 @@ object internal {
typeParams: List[String] = Nil,
constructors: List[List[ParamList]] = Nil,
superTypes: List[MaterializableLink] = Nil,
- var comment: Option[Comment] = None
+ var comment: Option[Comment] = None,
+ var companionPath: List[String] = Nil
) extends Class with Impl
final case class CaseClassImpl(
@@ -54,7 +55,8 @@ object internal {
typeParams: List[String] = Nil,
constructors: List[List[ParamList]] = Nil,
superTypes: List[MaterializableLink] = Nil,
- var comment: Option[Comment] = None
+ var comment: Option[Comment] = None,
+ var companionPath: List[String] = Nil
) extends CaseClass with Impl
final case class TraitImpl(
@@ -67,7 +69,8 @@ object internal {
typeParams: List[String] = Nil,
traitParams: List[ParamList] = Nil,
superTypes: List[MaterializableLink] = Nil,
- var comment: Option[Comment] = None
+ var comment: Option[Comment] = None,
+ var companionPath: List[String] = Nil
) extends Trait with Impl
final case class ObjectImpl(
@@ -78,7 +81,8 @@ object internal {
modifiers: List[String],
path: List[String],
superTypes: List[MaterializableLink] = Nil,
- var comment: Option[Comment] = None
+ var comment: Option[Comment] = None,
+ var companionPath: List[String] = Nil
) extends Object with Impl
final case class DefImpl(
diff --git a/doc-tool/src/dotty/tools/dottydoc/model/java.scala b/doc-tool/src/dotty/tools/dottydoc/model/java.scala
index a9ae0dbee..6b4e8b06d 100644
--- a/doc-tool/src/dotty/tools/dottydoc/model/java.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/model/java.scala
@@ -71,7 +71,9 @@ object java {
"comment" -> ent.comment.map(_.asJava).asJava,
"isPrivate" -> ent.isPrivate,
"isProtected" -> ent.isProtected,
- "hasVisibleMembers" -> ent.hasVisibleMembers
+ "hasVisibleMembers" -> ent.hasVisibleMembers,
+ "hasCompanion" -> ent.hasCompanion,
+ "companionPath" -> ent.companionPath.asJava
) ++ extras).asJava
}
@@ -88,7 +90,9 @@ object java {
"comment" -> ent.comment.map(_.asJava).asJava,
"isPrivate" -> ent.isPrivate,
"isProtected" -> ent.isProtected,
- "hasVisibleMembers" -> ent.hasVisibleMembers
+ "hasVisibleMembers" -> ent.hasVisibleMembers,
+ "hasCompanion" -> ent.hasCompanion,
+ "companionPath" -> ent.companionPath.asJava
) ++ extras).asJava
}
@@ -105,7 +109,9 @@ object java {
"comment" -> ent.comment.map(_.asJava).asJava,
"isPrivate" -> ent.isPrivate,
"isProtected" -> ent.isProtected,
- "hasVisibleMembers" -> ent.hasVisibleMembers
+ "hasVisibleMembers" -> ent.hasVisibleMembers,
+ "hasCompanion" -> ent.hasCompanion,
+ "companionPath" -> ent.companionPath.asJava
) ++ extras).asJava
}
@@ -121,7 +127,9 @@ object java {
"comment" -> ent.comment.map(_.asJava).asJava,
"isPrivate" -> ent.isPrivate,
"isProtected" -> ent.isProtected,
- "hasVisibleMembers" -> ent.hasVisibleMembers
+ "hasVisibleMembers" -> ent.hasVisibleMembers,
+ "hasCompanion" -> ent.hasCompanion,
+ "companionPath" -> ent.companionPath.asJava
) ++ extras).asJava
}