aboutsummaryrefslogtreecommitdiff
path: root/dottydoc
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-05-31 11:12:40 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-08-19 15:37:24 +0200
commit4b99e29b7de0bb5725d9e63a2c44f9e633685a6e (patch)
tree0ffbc245a9172e4a0dd5813abe97c086a77a1852 /dottydoc
parent23465a357a84c024ba71f671e08ffc67586a662e (diff)
downloaddotty-4b99e29b7de0bb5725d9e63a2c44f9e633685a6e.tar.gz
dotty-4b99e29b7de0bb5725d9e63a2c44f9e633685a6e.tar.bz2
dotty-4b99e29b7de0bb5725d9e63a2c44f9e633685a6e.zip
Change package serialization to go straight to JSON
We'll write a facade in Scala.js to handle the unparsed JS-object
Diffstat (limited to 'dottydoc')
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala61
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/util/OutputWriter.scala14
2 files changed, 68 insertions, 7 deletions
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala
new file mode 100644
index 000000000..02d4ecf02
--- /dev/null
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala
@@ -0,0 +1,61 @@
+package dotty.tools.dottydoc
+package model
+
+import spray.json._
+
+/** This object provides a protocol for serializing the package AST to JSON,
+ * this is supposed to be one-way for performance reasons
+ */
+object json extends DefaultJsonProtocol {
+ import model._
+ import model.comment._
+ import model.internal._
+
+ implicit val commentFormat = jsonFormat2(Comment.apply)
+ implicit val textFormat: JsonFormat[Text] = lazyFormat(jsonFormat(Text, "text"))
+ implicit object InlineJsonFormat extends RootJsonFormat[Inline] {
+ def write(i: Inline) = i match {
+ case i: Text => i.toJson
+ case _ => JsString("could not serialize")
+ }
+ def read(json: JsValue) = ??? // The json serialization is supposed to be one way
+ }
+
+ implicit val matLinkFormat = lazyFormat(jsonFormat(MaterializedLink, "title", "target"))
+ implicit val unsLinkFormat = lazyFormat(jsonFormat(UnsetLink, "title", "query"))
+
+ implicit object MaterializableLinkFormat extends RootJsonFormat[MaterializableLink] {
+ def write(obj: MaterializableLink) = obj match {
+ case obj: MaterializedLink => obj.toJson
+ case obj: UnsetLink => obj.toJson
+ }
+ def read(json: JsValue) = ??? // The json serialization is supposed to be one way
+ }
+
+ implicit object EntityJsonFormat extends RootJsonFormat[Entity] {
+ def write(e: Entity) = e match {
+ case e: PackageImpl => e.toJson
+ case e: ClassImpl => e.toJson
+ case e: CaseClassImpl => e.toJson
+ case e: TraitImpl => e.toJson
+ case e: ObjectImpl => e.toJson
+ case e: DefImpl => e.toJson
+ case e: ValImpl => e.toJson
+ }
+ def read(json: JsValue) = ??? // The json serialization is supposed to be one way
+ }
+
+ implicit object PackageFormat extends RootJsonFormat[Package] {
+ def write(obj: Package) = obj match { case obj: PackageImpl => obj.toJson }
+ def read(json: JsValue) = ??? // The json serialization is supposed to be one way
+ }
+
+ implicit val valFormat: JsonFormat[ValImpl] = lazyFormat(jsonFormat(ValImpl, "name", "modifiers", "path", "returnValue", "comment"))
+ implicit val defFormat: JsonFormat[DefImpl] = lazyFormat(jsonFormat(DefImpl, "name", "modifiers", "path", "returnValue", "comment"))
+ implicit val objFormat: JsonFormat[ObjectImpl] = lazyFormat(jsonFormat(ObjectImpl, "name", "members", "modifiers", "path", "comment"))
+ implicit val traitormat: JsonFormat[TraitImpl] = lazyFormat(jsonFormat(TraitImpl, "name", "members", "modifiers", "path", "comment"))
+ implicit val cclassFormat: JsonFormat[CaseClassImpl] = lazyFormat(jsonFormat(CaseClassImpl, "name", "members", "modifiers", "path", "comment"))
+ implicit val classFormat: JsonFormat[ClassImpl] = lazyFormat(jsonFormat(ClassImpl, "name", "members", "modifiers", "path", "comment"))
+ implicit val packageFormat: JsonFormat[PackageImpl] = lazyFormat(jsonFormat(PackageImpl, "name", "members", "path", "comment"))
+}
+
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/util/OutputWriter.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/util/OutputWriter.scala
index f2a6c7e95..b036a2d3a 100644
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/util/OutputWriter.scala
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/util/OutputWriter.scala
@@ -1,14 +1,13 @@
package dotty.tools.dottydoc
package util
+import java.io.{File => JFile, BufferedInputStream, FileInputStream, FileOutputStream, BufferedOutputStream}
+import html.EntityPage
+import model.Package
+import spray.json._
+import model.json._
class OutputWriter {
- import java.io.{File => JFile, BufferedInputStream, FileInputStream, FileOutputStream, BufferedOutputStream}
- import html.EntityPage
- import model.Package
- import model.pickling._
- import prickle._
-
def write(packs: Map[String, Package], outPath: String): Unit = {
// Write all packages to `outPath`
for (pack <- packs.values) {
@@ -32,7 +31,8 @@ class OutputWriter {
}
// Write full index to outPath
- val pickled = Pickle.intoString(packs)
+ //val pickled = Pickle.intoString(packs)
+ val pickled = packs.toJson
val js = "UnparsedIndex = {}; UnparsedIndex.packages = " + pickled + ";"
println("Writing index.js...")
writeFile(js, outPath + "/", "index.js")