aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-05-06 10:29:46 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-08-19 15:37:23 +0200
commitf084357c79d9c1ee9783ca07b9cfb84fb725328a (patch)
tree9c5dcb55087cd9cd4cb4f4df1fee4becedd35d46
parent2010a932329075ea1b2a0779fb96e442bc53232f (diff)
downloaddotty-f084357c79d9c1ee9783ca07b9cfb84fb725328a.tar.gz
dotty-f084357c79d9c1ee9783ca07b9cfb84fb725328a.tar.bz2
dotty-f084357c79d9c1ee9783ca07b9cfb84fb725328a.zip
Add implicit method `flat` to `Entity`
This method can be used when pickling the `currentEntity` on each page
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala3
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala25
-rw-r--r--dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala1
3 files changed, 27 insertions, 2 deletions
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala
index 29d7aef5a..f74e904ea 100644
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala
@@ -9,6 +9,7 @@ case class EntityPage(entity: Entity, packages: Map[String, Package]) {
import CustomTags._
import model.pickling._
import prickle._
+ import util.internal.setters._
private def relPath(to: String, from: Entity) =
"../" * from.path.length + to
@@ -68,7 +69,7 @@ case class EntityPage(entity: Entity, packages: Map[String, Package]) {
)
),
script(
- raw(s"""|UnparsedIndex.currentEntity = ${Pickle.intoString(entity)};
+ raw(s"""|UnparsedIndex.currentEntity = ${Pickle.intoString(entity.flat)};
|dotty.tools.dottydoc.js.DottyDocJS()
| .main(document.getElementById("entity-container"));
""".stripMargin)
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala
index b491fb161..798d54041 100644
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/util/mutate.scala
@@ -36,4 +36,29 @@ object setters {
e.parent = to
case _ => ()
}
+
+ implicit class FlattenedEntity(val ent: Entity) extends AnyVal {
+ /** Returns a flat copy if anything was changed (Entity with Members) else
+ * the identity
+ */
+ def flat: Entity = {
+ def flattenMember: Entity => Entity = {
+ case e: PackageImpl => e.copy(members = Nil)
+ case e: ObjectImpl => e.copy(members = Nil)
+ case e: CaseClassImpl => e.copy(members = Nil)
+ case e: ClassImpl => e.copy(members = Nil)
+ case e: TraitImpl => e.copy(members = Nil)
+ case other => other
+ }
+
+ ent match {
+ case e: PackageImpl => e.copy(members = e.members.map(flattenMember))
+ case e: ObjectImpl => e.copy(members = e.members.map(flattenMember))
+ case e: CaseClassImpl => e.copy(members = e.members.map(flattenMember))
+ case e: ClassImpl => e.copy(members = e.members.map(flattenMember))
+ case e: TraitImpl => e.copy(members = e.members.map(flattenMember))
+ case other => other
+ }
+ }
+ }
}
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 f151722c9..4707fccff 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
@@ -7,7 +7,6 @@ import dotc.core.Contexts.Context
import dotc.core.Symbols.Symbol
import dotc.core.{ Flags => DottyFlags }
import dotc.ast.Trees._
-import DottyFlags.FlagSet
object factories {
import dotty.tools.dotc.ast.tpd._