diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2010-01-20 14:41:58 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2010-01-20 14:41:58 +0000 |
commit | a259a744bb38c1cad070d459c8a59ad6c601cf74 (patch) | |
tree | 9d31c5234c34ba0ec4c40c8bab1c73a874e7f158 /src | |
parent | 61316fdc90863b5e889f5d3dfe00d7ec56cee9cf (diff) | |
download | scala-a259a744bb38c1cad070d459c8a59ad6c601cf74.tar.gz scala-a259a744bb38c1cad070d459c8a59ad6c601cf74.tar.bz2 scala-a259a744bb38c1cad070d459c8a59ad6c601cf74.zip |
[scaladoc] Default values of parameters are doc...
[scaladoc] Default values of parameters are documented. Tags "@author",
"@see", "@since", "@version", and "@deprecated" are displayed in
documentation. Contributed by Pedro Furlanetto, checked by dubochet, no
review.
Diffstat (limited to 'src')
4 files changed, 80 insertions, 8 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 119823ff13..ef60d5bfd7 100644 --- a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala +++ b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala @@ -185,12 +185,56 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { case _ => NodeSeq.Empty } } + { for(comment <- mbr.comment.toList) yield { + <xml:group> + { if(!comment.deprecated.isEmpty) + <div class="block"><ol>deprecated: + { for(body <- comment.deprecated.toList) yield <li>{bodyToHtml(body)}</li> } + </ol></div> + else NodeSeq.Empty + } + { if(mbr.isDeprecated) + <div class="block"><ol>deprecated: + { for(str <- mbr.deprecationMessage.toList) yield <li>{str}</li> } + </ol></div> + else NodeSeq.Empty + } + { if(!comment.version.isEmpty) + <div class="block"><ol>version + { for(body <- comment.version.toList) yield <li>{bodyToHtml(body)}</li> } + </ol></div> + else NodeSeq.Empty + } + { if(!comment.since.isEmpty) + <div class="block"><ol>since + { for(body <- comment.since.toList) yield <li>{bodyToHtml(body)}</li> } + </ol></div> + else NodeSeq.Empty + } + { if(!comment.see.isEmpty) + <div class="block"><ol>see also: + { val seeXml:List[scala.xml.NodeSeq]=(for(see <- comment.see ) yield <li>{bodyToHtml(see)}</li> ) + seeXml.reduceLeft(_ ++ Text(", ") ++ _) + } + </ol></div> + else NodeSeq.Empty + } + { if(!comment.authors.isEmpty) + <div class="block"><ol>authors: + { val authorsXml:List[scala.xml.NodeSeq]=(for(author <- comment.authors ) yield <li>{bodyToHtml(author)}</li> ) + authorsXml.reduceLeft(_ ++ Text(", ") ++ _) + } + </ol></div> + else NodeSeq.Empty + } + </xml:group> + }} { tpl.companion match { - case Some(companion) => + case Some(companion) if isSelf => <div class="block"> Go to: <a href={relativeLinkTo(companion)}>companion</a> </div> - case None => + case _ => NodeSeq.Empty } } @@ -237,7 +281,13 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { }{ def paramsToHtml(vlsss: List[List[ValueParam]]): NodeSeq = { def param0(vl: ValueParam): NodeSeq = - <span name={ vl.name }>{ vl.name + ": " }{ typeToHtml(vl.resultType, hasLinks) }</span> + // 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) { + Text(" = ") ++ <span class="default">{vl.defaultValue.get}</span> + } + else NodeSeq.Empty + }</span> def params0(vlss: List[ValueParam]): NodeSeq = vlss match { case Nil => NodeSeq.Empty case vl :: Nil => param0(vl) diff --git a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.css b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.css index 517c767241..9cd3c15180 100644 --- a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.css +++ b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.css @@ -125,6 +125,10 @@ div.members > ol > li { font-weight: bold; } +.signature .symbol .params .default { + font-style: italic; +} + #values .signature .name { color: #142556; } @@ -181,6 +185,11 @@ div.fullcomment .block { border-bottom: 1px solid black; } +div.fullcomment div.block ol li p, +div.fullcomment div.block ol li { + display:inline +} + div.fullcomment .block + .block { border-top: none; } diff --git a/src/compiler/scala/tools/nsc/doc/model/Entity.scala b/src/compiler/scala/tools/nsc/doc/model/Entity.scala index d7ef2b866d..00ea8b9939 100644 --- a/src/compiler/scala/tools/nsc/doc/model/Entity.scala +++ b/src/compiler/scala/tools/nsc/doc/model/Entity.scala @@ -45,6 +45,7 @@ trait MemberEntity extends Entity { def flags: List[Paragraph] def inheritedFrom: List[TemplateEntity] def isDeprecated: Boolean + def deprecationMessage: Option[String] def resultType: TypeEntity def isDef: Boolean def isVal: Boolean @@ -141,5 +142,6 @@ trait TypeParam extends ParameterEntity { /** A value parameter to a constructor or to a method. */ trait ValueParam extends ParameterEntity { - def resultType : TypeEntity + def resultType: TypeEntity + def defaultValue: Option[String] } diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala index f935dd4478..809f4bedd9 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala @@ -126,6 +126,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { extractor = if (inTemplate.sym == this.sym.owner || inTemplate.sym.isPackage) Nil else makeTemplate(this.sym.owner) :: (sym.allOverriddenSymbols map { os => makeTemplate(os.owner) }) def isDeprecated = sym.isDeprecated + def deprecationMessage = sym.deprecationMessage def resultType = makeType(sym.tpe.finalResultType, inTemplate, sym) def isDef = false def isVal = false @@ -401,16 +402,26 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { extractor = } /** */ - def makeValueParam(aSym: Symbol, inTpl: => DocTemplateImpl, newName: String): ValueParam = { + def makeValueParam(aSym: Symbol, inTpl: => DocTemplateImpl, newName: String): ValueParam = new ParameterImpl(aSym, inTpl) with ValueParam { override val name = newName def isTypeParam = false def isValueParam = true - def resultType = { + def defaultValue = + if (aSym.hasFlag(Flags.DEFAULTPARAM)) + // units.filter should return only one element + (currentRun.units filter (_.source.file == aSym.sourceFile)).toList match { + case List(unit) => + (unit.body find (_.symbol == aSym)) match { + case Some(ValDef(_,_,_,rhs)) => Some(rhs.toString) + case _ => None + } + case _ => None + } + else None + def resultType = makeType(sym.tpe, inTpl, sym) - } } - } /** */ def makeType(aType: Type, seeInTpl: => TemplateImpl, dclSym: Symbol): TypeEntity = { |