From a259a744bb38c1cad070d459c8a59ad6c601cf74 Mon Sep 17 00:00:00 2001 From: Gilles Dubochet Date: Wed, 20 Jan 2010 14:41:58 +0000 Subject: [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. --- .../scala/tools/nsc/doc/html/page/Template.scala | 56 ++++++++++++++++++++-- .../tools/nsc/doc/html/resource/lib/template.css | 9 ++++ .../scala/tools/nsc/doc/model/Entity.scala | 4 +- .../scala/tools/nsc/doc/model/ModelFactory.scala | 19 ++++++-- 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 { + + { if(!comment.deprecated.isEmpty) +
    deprecated: + { for(body <- comment.deprecated.toList) yield
  1. {bodyToHtml(body)}
  2. } +
+ else NodeSeq.Empty + } + { if(mbr.isDeprecated) +
    deprecated: + { for(str <- mbr.deprecationMessage.toList) yield
  1. {str}
  2. } +
+ else NodeSeq.Empty + } + { if(!comment.version.isEmpty) +
    version + { for(body <- comment.version.toList) yield
  1. {bodyToHtml(body)}
  2. } +
+ else NodeSeq.Empty + } + { if(!comment.since.isEmpty) +
    since + { for(body <- comment.since.toList) yield
  1. {bodyToHtml(body)}
  2. } +
+ else NodeSeq.Empty + } + { if(!comment.see.isEmpty) +
    see also: + { val seeXml:List[scala.xml.NodeSeq]=(for(see <- comment.see ) yield
  1. {bodyToHtml(see)}
  2. ) + seeXml.reduceLeft(_ ++ Text(", ") ++ _) + } +
+ else NodeSeq.Empty + } + { if(!comment.authors.isEmpty) +
    authors: + { val authorsXml:List[scala.xml.NodeSeq]=(for(author <- comment.authors ) yield
  1. {bodyToHtml(author)}
  2. ) + authorsXml.reduceLeft(_ ++ Text(", ") ++ _) + } +
+ else NodeSeq.Empty + } +
+ }} { tpl.companion match { - case Some(companion) => + case Some(companion) if isSelf =>
Go to: companion
- 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 = - { vl.name + ": " }{ typeToHtml(vl.resultType, hasLinks) } + // notice the }{ in the next lines, they are necessary to avoid a undesired withspace in output + { Text(vl.name + ": ") }{ typeToHtml(vl.resultType, hasLinks) }{ + if(!vl.defaultValue.isEmpty) { + Text(" = ") ++ {vl.defaultValue.get} + } + else NodeSeq.Empty + } 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 = { -- cgit v1.2.3