diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2011-02-23 19:05:01 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2011-02-23 19:05:01 +0000 |
commit | 633025cabd833cab9b3252ed9ac826437ad9cd88 (patch) | |
tree | 0ca95579a936282f935b33b694264b16534441c4 /src/compiler | |
parent | ed971ecabae07e60621ea8b4138eda7585ad3537 (diff) | |
download | scala-633025cabd833cab9b3252ed9ac826437ad9cd88.tar.gz scala-633025cabd833cab9b3252ed9ac826437ad9cd88.tar.bz2 scala-633025cabd833cab9b3252ed9ac826437ad9cd88.zip |
[scaladoc] Fixes the way default values and ann...
[scaladoc] Fixes the way default values and annotations are output in
Scaladoc. Closes #4167. No review.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/html/page/Template.scala | 153 |
1 files changed, 88 insertions, 65 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala index 2bbd537481..b333817dc6 100644 --- a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala +++ b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala @@ -42,7 +42,7 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { /* for body, there is a special case for AnyRef, otherwise AnyRef appears like a package/object * this problem should be fixed, this implementation is just a patch */ - val body = + val body = { <body class={ if (tpl.isTrait || tpl.isClass || tpl.qualifiedName == "scala.AnyRef") "type" else "value" } onload="windowTitle();"> { if (tpl.isRootPackage || tpl.inTemplate.isRootPackage) @@ -135,6 +135,7 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { <div id="tooltip" ></div> </body> + } def boundsToString(hi: Option[TypeEntity], lo: Option[TypeEntity]): String = { def bound0(bnd: Option[TypeEntity], pre: String): String = bnd match { @@ -144,7 +145,7 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { bound0(hi, "<:") ++ bound0(lo, ">:") } - def tparamsToString(tpss: List[TypeParam]): String = + def tparamsToString(tpss: List[TypeParam]): String = { if (tpss.isEmpty) "" else { def tparam0(tp: TypeParam): String = tp.variance + tp.name + boundsToString(tp.hi, tp.lo) @@ -154,10 +155,11 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { } "[" + tparams0(tpss) + "]" } + } - def defParamsToString(d: MemberEntity with Def):String = { - val namess = for( ps <- d.valueParams ) yield - for( p <- ps ) yield p.resultType.name + def defParamsToString(d: MemberEntity with Def): String = { + val namess = + for( ps <- d.valueParams; p <- ps ) yield p.resultType.name tparamsToString(d.typeParams) + namess.foldLeft("") { (s,names) => s + (names mkString("(",",",")")) } } @@ -174,7 +176,7 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { </li> } - def memberToCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = + def memberToCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = { mbr match { case dte: DocTemplateEntity if isSelf => // comment of class itself @@ -200,19 +202,22 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { </xml:group> } } + } - def memberToUseCaseCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = + def memberToUseCaseCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = { mbr match { case nte: NonTemplateMemberEntity if nte.isUseCase => inlineToHtml(comment.Text("[use case] ")) case _ => NodeSeq.Empty } + } - def memberToShortCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = + def memberToShortCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = { if (mbr.comment.isEmpty) NodeSeq.Empty else <p class="shortcomment cmt">{ memberToUseCaseCommentHtml(mbr, isSelf) }{ inlineToHtml(mbr.comment.get.short) }</p> + } def memberToInlineCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = <p class="comment cmt">{ inlineToHtml(mbr.comment.get.short) }</p> @@ -313,18 +318,7 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { annotations: { mbr.annotations.map { annot => <xml:group> - <span class="name">@{ templateToHtml(annot.annotationClass) }</span>{ - def paramsToHtml(vls: List[ValueArgument]): NodeSeq = - vls map { vl => - <span>{ - vl.parameter match { - case Some(p) => Text(p.name + " = ") - case None => NodeSeq.Empty - } - }{ treeToHtml(vl.value) }</span> - } - <span class="params">({ paramsToHtml(annot.arguments) })</span> - } + <span class="name">@{ templateToHtml(annot.annotationClass) }</span>{ argumentsToHtml(annot.arguments) } </xml:group> } } @@ -386,16 +380,18 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { } } - def kindToString(mbr: MemberEntity): String = mbr match { - case tpl: DocTemplateEntity => docEntityKindToString(tpl) - case ctor: Constructor => "new" - case tme: MemberEntity => - ( if (tme.isImplicit) "implicit " else "" ) + - ( if (tme.isDef) "def" - else if (tme.isVal) "val" - else if (tme.isLazyVal) "lazy val" - else if (tme.isVar) "var" - else "type") + def kindToString(mbr: MemberEntity): String = { + mbr match { + case tpl: DocTemplateEntity => docEntityKindToString(tpl) + case ctor: Constructor => "new" + case tme: MemberEntity => + ( if (tme.isImplicit) "implicit " else "" ) + + ( if (tme.isDef) "def" + else if (tme.isVal) "val" + else if (tme.isLazyVal) "lazy val" + else if (tme.isVar) "var" + else "type") + } } def boundsToHtml(hi: Option[TypeEntity], lo: Option[TypeEntity], hasLinks: Boolean): NodeSeq = { @@ -455,12 +451,16 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { def paramsToHtml(vlsss: List[List[ValueParam]]): NodeSeq = { def param0(vl: ValueParam): NodeSeq = // notice the }{ in the next lines, they are necessary to avoid a undesired withspace in output - <span name={ vl.name }>{ Text(vl.name + ": ") }{ typeToHtml(vl.resultType, hasLinks) }{ - if(!vl.defaultValue.isEmpty) { - treeToHtml(vl.defaultValue.get); + <span name={ vl.name }> + { Text(vl.name) } + { Text(": ") ++ typeToHtml(vl.resultType, hasLinks) } + { + vl.defaultValue match { + case Some(v) => Text(" = ") ++ treeToHtml(v) + case None => NodeSeq.Empty + } } - else NodeSeq.Empty - }</span> + </span> def params0(vlss: List[ValueParam]): NodeSeq = vlss match { case Nil => NodeSeq.Empty @@ -510,17 +510,42 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { case _ => <h4 class="signature">{ inside(hasLinks = true) }</h4> } + } /** */ - def treeToHtml(defVal:TreeEntity):NodeSeq = { + def treeToHtml(tree: TreeEntity): NodeSeq = { + + /** Makes text good looking in the html page : newlines and basic indentation, + * You must change this function if you want to improve pretty printing of default Values + */ + def codeStringToXml(text: String): NodeSeq = { + var goodLookingXml: NodeSeq = NodeSeq.Empty + var indent = 0 + for(c<-text) c match { + case '{' => indent+=1 + goodLookingXml ++= Text("{") + case '}' => indent-=1 + goodLookingXml ++= Text("}") + case '\n' => + goodLookingXml++= <br/> ++ indentation + case _ => goodLookingXml ++= Text(c.toString) + } + def indentation:NodeSeq = { + var indentXml = NodeSeq.Empty + for (x <- 1 to indent) indentXml ++= Text(" ") + indentXml + } + goodLookingXml + } + var index = 0 - val str = defVal.expression + val str = tree.expression val length = str.length var myXml: NodeSeq = NodeSeq.Empty - for( (from, (member, to)) <- defVal.refEntity.toSeq) { + for( (from, (member, to)) <- tree.refEntity.toSeq) { if (index < from) { - myXml ++= stringToXml(str.substring(index,from)) + myXml ++= codeStringToXml(str.substring(index,from)) index = from } if (index == from) { @@ -542,36 +567,34 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { case _ => "" } - if (index <= length-1) myXml ++= stringToXml(str.substring(index, length )) + if (index <= length-1) + myXml ++= codeStringToXml(str.substring(index, length )) - Text(" =") ++ - { - if(length< 7) <span class="symbol">{ myXml }</span> - else <span class="defval" name={ myXml }>{ " ..." }</span> - } + if(length < 36) + <span class="symbol">{ myXml }</span> + else + <span class="defval" name={ myXml }>{ "..." }</span> } - /** Makes text good looking in the html page : newlines and basic indentation, - * You must change this function if you want to improve pretty printing of default Values - */ - def stringToXml(text: String): NodeSeq = { - var goodLookingXml: NodeSeq = NodeSeq.Empty - var indent = 0 - for(c<-text) c match { - case '{' => indent+=1 - goodLookingXml ++= Text("{") - case '}' => indent-=1 - goodLookingXml ++= Text("}") - case '\n' => - goodLookingXml++= <br/> ++ indentation - case _ => goodLookingXml ++= Text(c.toString) + def argumentsToHtml(argss: List[ValueArgument]): NodeSeq = { + def argumentsToHtml0(argss: List[ValueArgument]): NodeSeq = argss match { + case Nil => NodeSeq.Empty + case arg :: Nil => argumentToHtml(arg) + case arg :: args => argumentToHtml(arg) ++ xml.Text(", ") ++ argumentsToHtml0(args) } - def indentation:NodeSeq = { - var indentXml = NodeSeq.Empty - for (x<- 1 to indent) indentXml ++= Text(" ") - indentXml - } - goodLookingXml + <span class="args">({ argumentsToHtml0(argss) })</span> + } + + def argumentToHtml(arg: ValueArgument): NodeSeq = { + <span> + { + arg.parameter match { + case Some(param) => Text(param.name + " = ") + case None => NodeSeq.Empty + } + } + { treeToHtml(arg.value) } + </span> } } |