Skip to content

Commit

Permalink
Removed even more redundant information from the models
Browse files Browse the repository at this point in the history
  • Loading branch information
szeiger committed Oct 19, 2010
1 parent 6728066 commit 8a4bd7c
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 47 deletions.
8 changes: 4 additions & 4 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ of the Scala source code; put everything on one line):
extradoc -doc-format:json -P:continuations:enable \
src\actors src\library\scala src\swing src\continuations\library

For Scala 2.8.0, this results in a JSON file of 80 MB which compresses very
nicely down to 2 MB (with 7zip). Extradoc requires quite a bit of memory to
build its JSON models. You should have a heap size of at least 1.5 GB (2 GB
recommended) to build the Scala library documentation in JSON format.
For Scala 2.8.0, this results in a JSON file of 18 MB which compresses very
nicely down to less than 800 kB (with 7zip). Extradoc requires quite a bit of
memory to build its JSON models. You should have a heap size of at least 1.5
GB (2 GB recommended) to build the Scala library documentation in JSON format.

Example: Building an Extradoc Explorer site for the Scala library, with a
proper title and linked sources (assuming the output directory doc-test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ a:hover, a:active {
}

#navigation ul.packages > li > table {
background-color: white;
display: block;
padding: 6px 0;
margin: 0;
Expand Down Expand Up @@ -470,6 +471,10 @@ a:hover, a:active {
border-radius: 6px;
}

#content_model ol.array > li > div.html {
margin: 0.5em 0;
}

#content_model table.object th.entityhead {
-webkit-border-top-right-radius: 6px;
-moz-border-radius-topright: 6px;
Expand Down Expand Up @@ -540,7 +545,7 @@ a:hover, a:active {
background: #e8e8e8;
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #f8f8f8), color-stop(1, #e8e8e8));
background-image: -moz-linear-gradient(center bottom, #f8f8f8 0%, #e8e8e8 100%);
border-bottom: 1px solid #a0a0a0;
border-bottom: 1px solid #c0c0c0;
overflow: hidden;
white-space: nowrap;
padding: 2px 15px 0px 9px;
Expand Down
17 changes: 13 additions & 4 deletions src/main/resources/com/novocode/extradoc/explorer/js/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,26 @@ View.defaultView = "model";

View.scrollToEntity = function(entity) {
var view = View[View.currentID];
var pos = entity > 0 ? $($("ol.page > li")[entity]).position().top + view.contentJ.scrollTop() - 6 : 0;
var pos = 0;
if(entity > 0) {
var epos = $($("ol.page > li")[entity]).position();
if(epos) {
pos = epos.top;
pos += view.contentJ.scrollTop() - 6;
}
}
view.contentJ.scrollTop(pos);
};

View.showMessage = function(msg) { View.msg.show(t(msg)); }

View.prototype.show = function(node, showing) {
if(node) this.contentJ.empty().append(node);
this.showing = showing;
if(View.currentID == this.id) return;
View[View.currentID].contentJ.css("visibility", "hidden");
View.currentID = this.id;
this.contentJ.css("visibility", "visible");
if(node) this.showing = showing;
};

View.prototype.isShowing = function(showing) {
Expand Down Expand Up @@ -316,7 +323,7 @@ Page.prototype.getModelDOM = function() {
var trE = e("tr", null, tbodyE);
var thE = e("th", { colspan: 2, "class": "entityhead" }, trE);
t(o.name, e("span", null, thE));
t(o.qName, thE);
t(o.qName || "", thE);
}
var is = null;
if(o._isEntity) {
Expand Down Expand Up @@ -512,8 +519,10 @@ function showEntity(params) {
Tab[view].show();
showTitle(page);
if(View[view].isShowing(page+","+entity)) View[view].show();
else if(currentPage && page == currentPage.no && View.currentID == view)
else if(currentPage && page == currentPage.no && View.currentID == view) {
View[view].show();
View.scrollToEntity(entity);
}
else {
Tab[view].setLoading(true);
loadPage(page, entity, view);
Expand Down
10 changes: 4 additions & 6 deletions src/main/resources/com/novocode/extradoc/explorer/js/extradoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var linkKeys = {
"primaryConstructor": true,
"typeParams[]": true,
"inDefinitionTemplates[]": true,
"alsoIn[]": true,
"inheritedFrom[]": true,
"parentTemplates[]": true,
"linearization[]": true,
Expand All @@ -21,7 +22,8 @@ var linkKeys = {
"_links[]": true,
"_refs[]": true,
"valueParams[][]": true,
"e": true
"e": true,
"commentIn": true
};

var mapKeys = { "throws": true };
Expand Down Expand Up @@ -57,7 +59,7 @@ ex.load = function(pageNo, ok, err) {
function resolveObject(o, name) {
var isMap = !!mapKeys[name];
if(!isMap) {
if(o.qName) {
if(o.qName || o.name) {
o._isEntity = true;
if(!o.name) o.name = getEntityName(o);
}
Expand Down Expand Up @@ -85,8 +87,6 @@ function resolveObject(o, name) {
case 'C': o.isCaseClass = true; break;
case 'U': o.isUseCase = true; break;
case 'P': o.isPrimary = true; break;
case 'y': o.isTypeParam = true; break;
case 'R': o.isValueParam = true; break;
case 's': o.isSealed = true; break;
case 'B': o.isAbstract = true; break;
case 'f': o.isFinal = true; break;
Expand Down Expand Up @@ -202,8 +202,6 @@ boolean
"isCaseClass"
"isUseCase"
"isPrimary"
"isTypeParam"
"isValueParam"
"isSealed"
"isAbstract"
"isFinal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ abstract class AbstractJsonFactory(val universe: Universe) { self =>
def prepareModel(universe: Universe) = {
println("Building JSON model")
val (allModels, allModelsReverse) = buildModels(universe)
//markInheritedMembers(allModels, allModelsReverse)
while(allModels.size > allModelsReverse.size) compact(allModels, allModelsReverse)
if(doInline) inline(allModels, allModelsReverse)
if(allModels.keys.max + 1 != allModels.size) renumber(allModels, allModelsReverse)
Expand Down Expand Up @@ -107,6 +108,37 @@ abstract class AbstractJsonFactory(val universe: Universe) { self =>
println("Compacted to "+allModels.size+" global objects ("+allModelsReverse.size+" unique)")
}

/* def markInheritedMembers(allModels: mutable.HashMap[Int, JBase], allModelsReverse: mutable.HashMap[JBase, Int]) {
def forMembers(j: JObject, jIdx: Int)(f: (JObject, JObject, Int) => Unit) {
j("values", new JArray).values ++ j("methods", new JArray).values foreach {
case l: Link => f(allModels(l.target).asInstanceOf[JObject], j, jIdx)
case _ =>
}
}
def forAllMembers(f: (JObject, JObject, Int) => Unit) {
allModels foreach {
case (idx, j: JObject) => forMembers(j, idx)(f)
case _ =>
}
}
forAllMembers { (j, parent, parentIdx) =>
val jDefName = j("definitionName", "..")
if(!(j("inDefinitionTemplates", new JArray).values contains Link(parentIdx))) {
var matches = 0
parent("linearization", new JArray).values.toSeq.reverse foreach {
case Link(t) =>
val possibleParent = allModels(t).asInstanceOf[JObject]
forMembers(possibleParent, t) { (parMember, _, _) =>
if(parMember("definitionName", "") == jDefName) matches += 1
//if(LimitedEquality.isEqual(parMember, j, XXXXX) matches += 1
}
case _ =>
}
j += "inherited" -> ("===> "+matches+" matches")
}
}
} */

def renumber(allModels: mutable.HashMap[Int, JBase], allModelsReverse: mutable.HashMap[JBase, Int]) {
println("Renumbering objects")
val repl = allModels.keys.toSeq.sorted.zipWithIndex.toMap
Expand Down
13 changes: 11 additions & 2 deletions src/main/scala/com/novocode/extradoc/json/HtmlGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import model._
import comment._

import scala.collection._
import scala.xml.{Xhtml, NodeSeq}
import scala.xml.{Xhtml, NodeSeq, Text}

abstract class HtmlGen extends html.HtmlPage {
def path: List[String] = Nil
Expand All @@ -15,7 +15,16 @@ abstract class HtmlGen extends html.HtmlPage {

def ref(e: TemplateEntity): String

def mkString(ns: NodeSeq) = Xhtml.toXhtml(ns)
def mkString(ns: NodeSeq) = ns match {
case Text("no summary matey") => ""
case _ =>
val s = Xhtml.toXhtml(ns).trim
if(s startsWith "<p>") {
if(s.indexOf("</p>") == s.length - 4)
s.substring(3, s.length-4).trim
else s
} else s
}

override def relativeLinkTo(destClass: TemplateEntity): String = "#" + ref(destClass)
}
51 changes: 49 additions & 2 deletions src/main/scala/com/novocode/extradoc/json/JBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object JBase {
}
}

final class JObject extends JBase {
sealed class JObject extends JBase {
private val m = new mutable.HashMap[String, Any]
def += [V](t: (String, V))(implicit cv: CanBeValue[V]) {
//if(m contains t._1) throw new RuntimeException("Cannot overwrite field "+t._1)
Expand Down Expand Up @@ -120,6 +120,10 @@ final class JObject extends JBase {
}
}
def apply(key: String) = m get key
def apply[T : ClassManifest](key: String, default: T) = m get key match {
case Some(v) if implicitly[ClassManifest[T]].erasure.isInstance(v) => v.asInstanceOf[T]
case _ => default
}
}

object JObject {
Expand All @@ -129,9 +133,13 @@ object JObject {
t foreach { case (k,v) => o += k -> v }
o
}
val Empty: JObject = new JObject {
override def += [V](t: (String, V))(implicit cv: CanBeValue[V]) =
throw new RuntimeException("Cannot add to JObject.Empty")
}
}

final class JArray extends JBase {
sealed class JArray extends JBase {
private val a = new mutable.ArrayBuffer[Any]
def += [T](v: T)(implicit cv: CanBeValue[T]) = a += v
def +?= [T](v: T)(implicit cv: CanBeValue[T]) = if(!cv.isEmpty(v)) a += v
Expand Down Expand Up @@ -164,6 +172,7 @@ final class JArray extends JBase {
}
}
def values = a.iterator
def length = a.length
}

object JArray {
Expand All @@ -173,8 +182,46 @@ object JArray {
t foreach { j => a += j }
a
}
val Empty: JArray = new JArray {
override def += [T](v: T)(implicit cv: CanBeValue[T]) =
throw new RuntimeException("Cannot add to JArray.Empty")
}
}

case class Link(target: Int) {
override def toString = target.toString
}

case class LimitedEquality(j: JBase, keys: String*) {
override def hashCode: Int = 0 //TODO optimize

override def equals(o: Any) = o match {
case LimitedEquality(o) => LimitedEquality.isEqual(j, o, keys:_*)
case _ => false
}

}

object LimitedEquality {
def isEqual(a: Any, b: Any, keys: String*): Boolean = (a,b) match {
case (null, null) => true
case (null, _) => false
case (_, null) => false
case (a: JArray, b: JArray) =>
a.length == b.length && (a.values zip b.values forall { case (v,w) => isEqual(v, w, keys:_*) })
case (a: JObject, b: JObject) =>
keys forall { k =>
(a(k), b(k)) match {
case (None, None) => true
case (None, _) => false
case (_, None) => false
case (Some(v), Some(w)) => isEqual(v, w, keys:_*)
}
}
case (a: String, b: String) => a == b
case (a: Int, b: Int) => a == b
case (a: Boolean, b: Boolean) => a == b
case (Link(a), Link(b)) => a == b
case _ => false
}
}
Loading

0 comments on commit 8a4bd7c

Please sign in to comment.