diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/DocGenerator.scala | 258 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/DocUtil.scala | 106 |
2 files changed, 174 insertions, 190 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/DocGenerator.scala b/src/compiler/scala/tools/nsc/doc/DocGenerator.scala index ae1c8d4bb2..b3c5d56b60 100644 --- a/src/compiler/scala/tools/nsc/doc/DocGenerator.scala +++ b/src/compiler/scala/tools/nsc/doc/DocGenerator.scala @@ -1,23 +1,27 @@ -package scala.tools.nsc.doc; +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL + * @author Sean McDirmid + */ +// $Id: $ -import scala.tools.nsc._; -import java.io._; -import scala.tools.nsc.models._; -import scala.collection.immutable._; -import scala.xml._; - -abstract class DocGenerator extends Models { - import global._; - import DocUtil._; - def outdir : String; - def contentFrame = "contentFrame"; - def classesFrame = "classesFrame"; - def modulesFrame = "modulesFrame"; - def emptyMap = ListMap.Empty[Kind,TreeSet[HasTree]]; +package scala.tools.nsc.doc +import java.io.{File, FileWriter} +import scala.collection.immutable._ +import scala.tools.nsc._ +import scala.tools.nsc.models._ +import scala.xml._ - override def acceptPrivate = false; +abstract class DocGenerator extends Models { + import global._ + import DocUtil._ + def outdir: String + def contentFrame = "contentFrame" + def classesFrame = "classesFrame" + def modulesFrame = "modulesFrame" + def emptyMap = ListMap.Empty[Kind, TreeSet[HasTree]] + override def acceptPrivate = false abstract class Frame extends UrlContext { def path : String; // relative to outdir @@ -31,25 +35,25 @@ abstract class DocGenerator extends Models { ct = ct + (if (idx != -1) "../" else ""); idx = idx + (if (idx == -1) 0 else 1); } - ct; + ct } - def body : NodeSeq; - def title : String; - def save(nodes : NodeSeq) = { - val path0 = outdir + "/" + path + ".html"; - System.err.println("Writing to " + path0); - val file = new File(path0); - val parent = file.getParentFile(); - if (!parent.exists()) parent.mkdirs(); - val writer = new FileWriter(file); - val str = dtype + "\n" + nodes.toString(); - writer.write(str, 0, str.length()); - writer.close(); + def body: NodeSeq + def title: String + def save(nodes: NodeSeq) = { + val path0 = outdir + "/" + path + ".html" + System.err.println("Writing to " + path0) + val file = new File(path0) + val parent = file.getParentFile() + if (!parent.exists()) parent.mkdirs() + val writer = new FileWriter(file) + val str = dtype + "\n" + nodes.toString() + writer.write(str, 0, str.length()) + writer.close() } - def urlFor(sym : Symbol, target : String) : NodeSeq = - aref(urlFor(sym), target, sym.nameString); + def urlFor(sym: Symbol, target: String): NodeSeq = + aref(urlFor(sym), target, sym.nameString) def urlFor0(sym : Symbol, orig : Symbol) : String = { (if (sym == NoSymbol) { @@ -84,20 +88,20 @@ abstract class DocGenerator extends Models { val x = div0("Scala 2") concat aref("all-classes.html", classesFrame, "All objects and classes"); val y = <P/><B>Packages</B> - <TABLE class="list"><TR><TD style="white-space:nowrap;"> + <table class="list"><tr><TD style="white-space:nowrap;"> { { for (val top <- modules.elements.toList) yield {br(aref(urlFor(top._2), classesFrame, top._2.fullNameString('.')))}; } } - </TD></TR></TABLE>; + </TD></tr></table>; x.concat(y); } } abstract class ListModuleContentFrame extends Frame { - val path = "root-content"; - val title = "All Packages"; - def modules : TreeMap[String,ModuleClassSymbol]; + val path = "root-content" + val title = "All Packages" + def modules : TreeMap[String, ModuleClassSymbol] def body : NodeSeq = { <SPAN><DIV class="page-title"> Scala 2 @@ -124,28 +128,27 @@ abstract class DocGenerator extends Models { abstract class ListClassFrame extends Frame { def classes : ListMap[Kind,TreeSet[HasTree]]; - def navLabel : String; + def navLabel: String def body : NodeSeq = { - val nav = <TABLE class="navigation"><TR><TD valign="top" class="navigation-links"> + val nav = <table class="navigation"><TR><TD valign="top" class="navigation-links"> {aref(path + ".html", contentFrame, navLabel)} - </TD></TR></TABLE><P/>; - + </TD></TR></table><P/>; - val body = <SPAN> { { for (val kind <- KINDS; classes.contains(kind)) yield { - val x = <B>{Text(pluralFor(kind))}</B>; + val body = <span> { { for (val kind <- KINDS; classes.contains(kind)) yield { + val x = <b>{Text(pluralFor(kind))}</b>; - val y = <TABLE class="list"><TR><TD style="white-space;nowrap;"> + val y = <table class="list"><TR><TD style="white-space;nowrap;"> { { for (val mmbr <- classes(kind).toList) yield br(urlFor(mmbr.tree.symbol, contentFrame)); } } - </TD></TR></TABLE>; + </TD></TR></table>; val ret :NodeSeq = x.concat(y); ret; - } } } </SPAN>; + } } } </span>; - nav.concat(body); + nav.concat(body) } } @@ -153,16 +156,16 @@ abstract class DocGenerator extends Models { def extendsFor(mmbr : HasTree) : NodeSeq = mmbr match { case mmbr : ImplMod => if (!mmbr.treey.impl.parents.isEmpty) - <SPAN><dd><code>{Text(" extends ")}</code> + <span><dd><code>{Text(" extends ")}</code> {forType(mmbr.treey.impl.parents.head.tpe)}</dd> { { for (val parent <- mmbr.treey.impl.parents.tail) yield <dd><code>{Text(" with ")}</code> {forType(parent.tpe)}</dd>; - } } </SPAN>; + } } </span>; else NodeSeq.Empty; case _ => NodeSeq.Empty; } - def fullHeader(mmbr : HasTree) : NodeSeq = <SPAN>{ { + def fullHeader(mmbr: HasTree): NodeSeq = <span>{ { if (!mmbr.isInstanceOf[ImplMod]) { <a name = {Utility.escape(mmbr.tree.symbol.nameString)}></a>; } else NodeSeq.Empty; @@ -173,28 +176,27 @@ abstract class DocGenerator extends Models { { typesFor(mmbr) }{ argsFor(mmbr)}{resultFor(mmbr) } </DT> { extendsFor(mmbr) } </DL> { fullComment(mmbr) } <HR/> - { lists(mmbr) } </SPAN>; + { lists(mmbr) } </span>; def lists(mmbr : HasTree) = mmbr match { - case cmod : ImplMod => <SPAN>{ listMembersShort(mmbr) } - { listMembersFull (mmbr) }</SPAN> - case _ => NodeSeq.Empty; + case cmod : ImplMod => <span>{ listMembersShort(mmbr) } + { listMembersFull (mmbr) }</span> + case _ => NodeSeq.Empty } - def listMembersShort(mmbr : HasTree) : NodeSeq = if (mmbr.isInstanceOf[Composite]) { val map = organize(mmbr.asInstanceOf[Composite], emptyMap); - <SPAN> { { + <span> { { for (val kind <- KINDS; map.contains(kind)) yield { - val x = <TABLE cellpadding="3" class="member"> - <TR><TD colspan="2" class="title">{Text(labelFor(kind))} Summary</TD></TR> + val x = <table cellpadding="3" class="member"> + <tr><td colspan="2" class="title">{Text(labelFor(kind))} Summary</td></tr> { { for (val mmbr <- map(kind).toList) yield shortHeader(mmbr); } } - </TABLE>; + </table>; br(x); } - } } </SPAN> + } } </span> } else NodeSeq.Empty; def listMembersFull(mmbr : HasTree) : NodeSeq = if (mmbr.isInstanceOf[Composite]) { @@ -208,42 +210,43 @@ abstract class DocGenerator extends Models { def title = labelFor(kind0) + " " + mmbr.tree.symbol.nameString + " in " + codeFor(mmbrx.kind) + " " + mmbr.tree.symbol.owner.fullNameString('.'); } } - <SPAN> { { + <span> { { for (val kind <- KINDS; map.contains(kind) && kind != OBJECT && kind != CLASS) yield { val header = <table cellpadding="3" class="member-detail"> <tr><td class="member-title">{Text(labelFor(kind))} Detail</td></tr> </table>; - val body = for (val mmbr <- map(kind).toList) yield <SPAN>{fullHeader(mmbr)}</SPAN>; + val body = for (val mmbr <- map(kind).toList) yield <span>{fullHeader(mmbr)}</span>; header.concat(body); } - } } </SPAN>; + } } </span>; } else NodeSeq.Empty; - def shortHeader(mmbr : HasTree) : NodeSeq = { - <TR> - <TD valign="top" class="modifiers"> - { { for (val str <- stringsFor(mmbr.mods)) yield <CODE>{(Text(str + " "))}</CODE>; } } - </TD> - <TD class="signature"> - <CODE>{Text(codeFor(mmbr.kind))}</CODE> - <EM>{urlFor(mmbr.tree.symbol, contentFrame)}</EM> + def shortHeader(mmbr: HasTree): NodeSeq = { + <tr> + <td valign="top" class="modifiers"> + { { for (val str <- stringsFor(mmbr.mods)) yield <code>{(Text(str + " "))}</code>; } } + </td> + <td class="signature"> + <code>{Text(codeFor(mmbr.kind))}</code> + <em>{urlFor(mmbr.tree.symbol, contentFrame)}</em> { typesFor(mmbr) } { argsFor(mmbr) } {resultFor(mmbr) } - <BR>{shortComment(mmbr)}</BR> - </TD> - </TR>; + <br>{shortComment(mmbr)}</br> + </td> + </tr>; } - - def fullComment(mmbr : HasTree) : NodeSeq = { + def fullComment(mmbr: HasTree): NodeSeq = { if (comments.contains(mmbr.tree.symbol)) - comment(comments(mmbr.tree.symbol), false) else NodeSeq.Empty; - }; - def shortComment(mmbr : HasTree) : NodeSeq = { + comment(comments(mmbr.tree.symbol), false) else NodeSeq.Empty + } + + def shortComment(mmbr: HasTree): NodeSeq = { if (comments.contains(mmbr.tree.symbol)) - comment(comments(mmbr.tree.symbol), true) else NodeSeq.Empty; - }; + comment(comments(mmbr.tree.symbol), true) else NodeSeq.Empty + } + def ifT (cond : Boolean, nodes : NodeSeq) = if (cond) nodes else NodeSeq.Empty; def ifT (tree : Tree, nodes : NodeSeq, before : Boolean) = { if (tree != EmptyTree && @@ -254,11 +257,11 @@ abstract class DocGenerator extends Models { } else NodeSeq.Empty; } - def forType(tpe : Type) : NodeSeq = + def forType(tpe: Type): NodeSeq = urlFor(tpe.symbol, contentFrame); - def forTree(tree : Tree) : NodeSeq = tree match { - case vdef : ValDef => + def forTree(tree: Tree): NodeSeq = tree match { + case vdef: ValDef => Text(vdef.symbol.name.toString()).concat(Text(" : ")).concat(forTree(vdef.tpt)); case sel : Select => forTree(sel.qualifier).concat(Text(sel.symbol.nameString)); case tree : AbsTypeDef => @@ -340,14 +343,14 @@ abstract class DocGenerator extends Models { } abstract class ContentFrame extends ContentFrame0 { - def clazz : ImplMod; - def kind : Kind; - def body : NodeSeq = <SPAN>{navigation}{header0}{fullHeader(clazz)}</SPAN>; + def clazz: ImplMod + def kind: Kind + def body: NodeSeq = <span>{navigation}{header0}{fullHeader(clazz)}</span>; - final def path = urlFor0(clazz.tree.symbol,clazz.tree.symbol); + final def path = urlFor0(clazz.tree.symbol,clazz.tree.symbol) - def navigation : NodeSeq = - <TABLE class="navigation"> + def navigation: NodeSeq = + <table class="navigation"> <TR> <TD valign="top" class="navigation-links"> <TABLE><TR> @@ -361,22 +364,18 @@ abstract class DocGenerator extends Models { </TD> </TR> <TR><TD></TD></TR> - </TABLE>; + </table>; - def header0 : NodeSeq = <SPAN> - <HR/> in {aref(urlFor(clazz.tree.symbol.owner), "_self", clazz.tree.symbol.owner.fullNameString('.'))} - <DIV class="entity"> + def header0 : NodeSeq = <span> + <hr/> in {aref(urlFor(clazz.tree.symbol.owner), "_self", clazz.tree.symbol.owner.fullNameString('.'))} + <div class="entity"> {Text(codeFor(kind))} - <SPAN class="entity">{Text(clazz.tree.symbol.nameString)}</SPAN> - </DIV><HR/> - </SPAN>; - - - - + <span class="entity">{Text(clazz.tree.symbol.nameString)}</span> + </div><hr/> + </span> } - def process(units : Iterator[CompilationUnit]) : Unit = { + def process(units: Iterator[CompilationUnit]) : Unit = { var members = emptyMap; var topLevel = ListMap.Empty[ModuleClassSymbol,ListMap[Kind,TreeSet[HasTree]]]; @@ -397,14 +396,14 @@ abstract class DocGenerator extends Models { for (val top <- topLevel.elements) modules0 = modules0.insert(top._1.fullNameString, top._1); modules0; - }; + } new ListModuleFrame { def modules = modules0; - }; + } new ListModuleContentFrame { def modules = modules0; - }; + } new ListClassFrame { def classes = { @@ -446,27 +445,20 @@ abstract class DocGenerator extends Models { } new Frame { - def title = "Scala Library Documentation"; - def body = index; - def path = "index"; - override def hasBody = false; - }; - + def title = "Scala Library Documentation" + def body = index + def path = "index" + override def hasBody = false + } } - - - - - - - def organize(c : Composite, map0 : ListMap[Kind,TreeSet[HasTree]]) = { var map = map0; //System.err.println("MEMBERS: " + c.members.toList); for (val mmbr <- c.members.toList) map = organize0(mmbr, map); map; } + def organize0(mmbr : HasTree, map0 : ListMap[Kind,TreeSet[HasTree]]) = { var map = map0; if (!map.contains(mmbr.kind)) @@ -475,18 +467,16 @@ abstract class DocGenerator extends Models { map = map.update(mmbr.kind, map(mmbr.kind) + mmbr); if (map(mmbr.kind).size == sz) System.err.println(""+mmbr + " not added"); - map; + map } - def parse(str : String) : NodeSeq = { new SpecialNode { - def label = "#PCDATA"; + def label = "#PCDATA" def toString(sb:StringBuffer): StringBuffer = { sb.append(str.trim()); - sb; + sb } - } /* import java.io.StringReader; @@ -496,7 +486,7 @@ abstract class DocGenerator extends Models { if (parsedxml1 == null) Text("BAD_COMMENT???"); else parsedxml1; */ - }; + } def comment(comment : String, isShort : Boolean) : NodeSeq = { var ret : List[Node] = Nil; @@ -520,19 +510,18 @@ abstract class DocGenerator extends Models { if (!isShort) while (tokenizer.hasMoreElements()) { val attr = tokenizer.nextToken(); val div = attr.indexOf(' '); - val tuple = if (div == -1) new Tuple2(attr,""); + val tuple = if (div == -1) new Tuple2(attr,""); else new Tuple2(attr.substring(0, div), attr.substring(div + 1, attr.length())); attributes = attributes ::: (tuple :: Nil); } - if (isShort) <SPAN>{parse(body)}</SPAN>; - else <SPAN><DL><DD>{parse(body)}</DD></DL><DL> + if (isShort) <span>{parse(body)}</span>; + else <span><dl><dd>{parse(body)}</dd></dl><dl> { { for (val attr <- attributes) yield - <DT style="margin-top:10px;"><B>{Text(attr._1 + ":")}</B></DT> - <DD>{(parse(attr._2))}</DD>; - } } </DL></SPAN>; - }; - + <dt style="margin-top:10px;"><b>{Text(attr._1 + ":")}</b></dt> + <dd>{(parse(attr._2))}</dd>; + } } </dl></span>; + } val index = { <frameset cols="25%, 75%"> @@ -546,9 +535,6 @@ abstract class DocGenerator extends Models { val root = <b></b>; - - - - private val JDOC_START = "/**"; - private val JDOC_END = "*/"; + private val JDOC_START = "/**" + private val JDOC_END = "*/" } diff --git a/src/compiler/scala/tools/nsc/doc/DocUtil.scala b/src/compiler/scala/tools/nsc/doc/DocUtil.scala index baadcab546..c71c1f4477 100644 --- a/src/compiler/scala/tools/nsc/doc/DocUtil.scala +++ b/src/compiler/scala/tools/nsc/doc/DocUtil.scala @@ -1,82 +1,80 @@ -package scala.tools.nsc.doc; +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL + * @author Sean McDirmid + */ +// $Id: $ -import scala.xml._; -import scala.collection.immutable._; -import java.io._; +package scala.tools.nsc.doc + +import scala.collection.immutable._ +import scala.xml._ object DocUtil { - def dquote(str : String) : NodeSeq = { - DQUOTE :: Text(str) :: DQUOTE :: Nil; + def dquote(str: String): NodeSeq = + DQUOTE :: Text(str) :: DQUOTE :: Nil - } object DQUOTE extends SpecialNode { - - def toString(sb:StringBuffer) = { - sb.append("\""); sb; + def toString(sb: StringBuffer) = { + sb.append("\""); sb } - def label = "#PCDATA"; - + def label = "#PCDATA" } - def br(nodes: NodeSeq) : NodeSeq = { + + def br(nodes: NodeSeq): NodeSeq = { val x = <BR/>; - nodes.concat(x); + nodes.concat(x) } - - - - mixin abstract class UrlContext { + def relative: String - def relative : String; - def aref(href0: String, target : String, text : String) : NodeSeq = { - val href = Utility.escape(href0); - if (target.indexOf('<') != -1) throw new Error(target); + def aref(href0: String, target: String, text: String): NodeSeq = { + val href = Utility.escape(href0) + if (target.indexOf('<') != -1) throw new Error(target) - val t0 = Text(text); + val t0 = Text(text) - <a href={(relative + href)} target={(target)}>{t0}</a>; + <a href={(relative + href)} target={(target)}>{t0}</a> } + val header = <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> <meta name="generator" content="scaladoc (1.4.0.4)"/> <link rel="stylesheet" type="text/css" href={ relative + "style.css" }/> <script type="text/javascript" src={relative + "script.js"}></script>; - def body0(hasBody : Boolean, nodes : NodeSeq) : NodeSeq = - if (!hasBody) nodes; else <BODY>{nodes}</BODY>; + def body0(hasBody: Boolean, nodes: NodeSeq): NodeSeq = + if (!hasBody) nodes else <body>{nodes}</body>; val dtype = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"; - def page(title : String, body : NodeSeq, hasBody : Boolean) : NodeSeq = - <HTML> - <HEAD><TITLE>{Text(title)}</TITLE> - {header} - </HEAD> - {body0(hasBody, body)} - </HTML>; - + def page(title: String, body: NodeSeq, hasBody: Boolean): NodeSeq = + <html> + <head><title>{Text(title)}</title> + {header} + </head> + {body0(hasBody, body)} + </html> + } // UrlContext + + def div0(title: String): NodeSeq = + <div class="doctitle-larger">{Text(title)}</div>; + + def merge[T](ts0: TreeSet[T], ts1: TreeSet[T]): TreeSet[T] = { + var ts = ts0 + for (val t <- ts1.toList) ts = ts + t + ts } - - - - def div0(title : String) : NodeSeq = <DIV class="doctitle-larger">{Text(title)}</DIV>; - - - def merge[T](ts0 : TreeSet[T], ts1 : TreeSet[T]): TreeSet[T] = { - var ts = ts0; - for (val t <- ts1.toList) ts = ts + t; - ts; - } - def merge[T,S <: Ordered[S]](ts0 : ListMap[T,TreeSet[S]], ts1 : ListMap[T,TreeSet[S]]): - ListMap[T,TreeSet[S]] = { - var ts = ts0; - for (val t <- ts1.elements) { - if (!ts.contains(t._1)) - ts = ts.update(t._1, new TreeSet[S]); - ts = ts.update(t._1, merge(ts(t._1), t._2)); - } - ts; + def merge[T,S <: Ordered[S]](ts0: ListMap[T,TreeSet[S]], ts1: ListMap[T,TreeSet[S]]): + ListMap[T,TreeSet[S]] = { + var ts = ts0 + for (val t <- ts1.elements) { + if (!ts.contains(t._1)) + ts = ts.update(t._1, new TreeSet[S]); + ts = ts.update(t._1, merge(ts(t._1), t._2)); } + ts + } + } |