aboutsummaryrefslogtreecommitdiff
path: root/doc-tool/src
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-01-18 17:45:42 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-01-31 14:32:39 +0100
commite4ecaa0d977661954a7c686e3fe8eca2d71dba82 (patch)
tree970fcd7d112b8fb21ce39656225d2c0aa8d27b7f /doc-tool/src
parent6c07096250f18add02fbd8573211e4004872b9c9 (diff)
downloaddotty-e4ecaa0d977661954a7c686e3fe8eca2d71dba82.tar.gz
dotty-e4ecaa0d977661954a7c686e3fe8eca2d71dba82.tar.bz2
dotty-e4ecaa0d977661954a7c686e3fe8eca2d71dba82.zip
Harmonize package objects and packages in Doc AST
Diffstat (limited to 'doc-tool/src')
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala1
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/core/PackageObjectsPhase.scala35
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/model/entities.scala2
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/model/internal.scala1
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/model/java.scala3
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/model/json.scala1
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/model/references.scala1
7 files changed, 43 insertions, 1 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala b/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala
index af4aaae4f..55b079adf 100644
--- a/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala
@@ -25,6 +25,7 @@ class DocCompiler extends Compiler {
List(new DocASTPhase),
List(DocMiniTransformations(new UsecasePhase,
new DocstringPhase,
+ new PackageObjectsPhase,
new LinkReturnTypes,
new LinkParamListTypes,
new LinkImplicitlyAddedTypes,
diff --git a/doc-tool/src/dotty/tools/dottydoc/core/PackageObjectsPhase.scala b/doc-tool/src/dotty/tools/dottydoc/core/PackageObjectsPhase.scala
new file mode 100644
index 000000000..adcadb0ba
--- /dev/null
+++ b/doc-tool/src/dotty/tools/dottydoc/core/PackageObjectsPhase.scala
@@ -0,0 +1,35 @@
+package dotty.tools
+package dottydoc
+package core
+
+import dotty.tools.dotc.core.Symbols.Symbol
+import dotc.core.Contexts.Context
+import dotc.ast.tpd
+
+import model._
+import model.internal._
+import util.syntax._
+import transform.DocMiniPhase
+
+class PackageObjectsPhase extends DocMiniPhase {
+
+ override def transformPackage(implicit ctx: Context) = { case pkg: PackageImpl =>
+ pkg
+ .members
+ .collect { case o: Object if o.symbol.isPackageObject => o }
+ .headOption
+ .map { obj =>
+ pkg.copy(
+ members = obj.members ++ pkg.members,
+ superTypes = obj.superTypes,
+ comment = obj.comment
+ )
+ }
+ .getOrElse(pkg)
+ }
+
+ override def transformObject(implicit ctx: Context) = { case obj: Object =>
+ if (obj.symbol.isPackageObject) NonEntity
+ else obj
+ }
+}
diff --git a/doc-tool/src/dotty/tools/dottydoc/model/entities.scala b/doc-tool/src/dotty/tools/dottydoc/model/entities.scala
index a40666e0d..613788964 100644
--- a/doc-tool/src/dotty/tools/dottydoc/model/entities.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/model/entities.scala
@@ -84,7 +84,7 @@ trait ImplicitlyAddedEntity extends Entity {
def implicitlyAddedFrom: Option[Reference]
}
-trait Package extends Entity with Members {
+trait Package extends Entity with Members with SuperTypes {
val kind = "package"
}
diff --git a/doc-tool/src/dotty/tools/dottydoc/model/internal.scala b/doc-tool/src/dotty/tools/dottydoc/model/internal.scala
index 5bc410706..ac789f29f 100644
--- a/doc-tool/src/dotty/tools/dottydoc/model/internal.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/model/internal.scala
@@ -17,6 +17,7 @@ object internal {
name: String,
var members: List[Entity],
path: List[String],
+ superTypes: List[MaterializableLink] = Nil,
var comment: Option[Comment] = None
) extends Package with Impl
diff --git a/doc-tool/src/dotty/tools/dottydoc/model/java.scala b/doc-tool/src/dotty/tools/dottydoc/model/java.scala
index 8e493f889..189012e18 100644
--- a/doc-tool/src/dotty/tools/dottydoc/model/java.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/model/java.scala
@@ -52,6 +52,7 @@ object java {
"path" -> ent.path.asJava,
"members" -> ent.members.map(_.asJava()).asJava,
"comment" -> ent.comment.map(_.asJava).asJava,
+ "superTypes" -> ent.superTypes,
"hasVisibleMembers" -> ent.hasVisibleMembers
) ++ extras).asJava
}
@@ -234,6 +235,8 @@ object java {
"title" -> title,
"scala" -> ref
).asJava
+
+ case EmptyReference => ???
}
}
diff --git a/doc-tool/src/dotty/tools/dottydoc/model/json.scala b/doc-tool/src/dotty/tools/dottydoc/model/json.scala
index 145728f8a..766f0c147 100644
--- a/doc-tool/src/dotty/tools/dottydoc/model/json.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/model/json.scala
@@ -63,6 +63,7 @@ object json {
s"""{"args":${ref.args.map(refToJson).mkString("[",",","]")},"returnValue":${refToJson(ref.returnValue)},"kind": "FunctionReference"}"""
case ref: TupleReference =>
s"""{"args":${ref.args.map(refToJson).mkString("[",",","]")},"kind": "TupleReference"}"""
+ case EmptyReference => ???
}
implicit class ReferenceJson(val ref: Reference) extends AnyVal { def json: String = refToJson(ref) }
diff --git a/doc-tool/src/dotty/tools/dottydoc/model/references.scala b/doc-tool/src/dotty/tools/dottydoc/model/references.scala
index 766b2a340..02304b302 100644
--- a/doc-tool/src/dotty/tools/dottydoc/model/references.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/model/references.scala
@@ -11,6 +11,7 @@ object references {
final case class BoundsReference(low: Reference, high: Reference) extends Reference
final case class NamedReference(title: String, ref: Reference, isByName: Boolean = false, isRepeated: Boolean = false) extends Reference
final case class ConstantReference(title: String) extends Reference
+ final case object EmptyReference extends Reference
/** Use MaterializableLink for entities that need be picklable */
sealed trait MaterializableLink { def title: String }