@@ -4,7 +4,6 @@ package typer
44
55import core ._
66import Contexts ._ , Symbols ._ , Decorators ._ , Comments ._
7- import util .Positions ._
87import ast .tpd
98
109trait Docstrings { self : Typer =>
@@ -21,39 +20,46 @@ trait Docstrings { self: Typer =>
2120 * @param sym The symbol for which the comment is being cooked.
2221 * @param owner The class for which comments are being cooked.
2322 */
24- def cookComment (sym : Symbol , owner : Symbol )(implicit ctx : Context ): Unit = {
23+ def cookComment (sym : Symbol , owner : Symbol )(implicit ctx : Context ): Option [ Comment ] = {
2524 for {
26- docbase <- ctx.docCtx
27- comment <- docbase.docstring(sym).filter(! _.isExpanded)
28- } {
29- expandParentDocs(sym)
30- docbase.docstring(sym).get.usecases.foreach { usecase =>
25+ docCtx <- ctx.docCtx
26+ comment <- expandParentDocs(sym)(ctx, docCtx)
27+ } yield {
28+ val typedUsecases = comment.usecases.map { usecase =>
3129 enterSymbol(createSymbol(usecase.untpdCode))
3230 typedStats(usecase.untpdCode :: Nil , owner) match {
33- case List (df : tpd.DefDef ) => usecase.tpdCode = df
34- case _ => ctx.error(" `@usecase` was not a valid definition" , usecase.codePos)
31+ case List (df : tpd.DefDef ) =>
32+ usecase.typed(df)
33+ case _ =>
34+ ctx.error(" `@usecase` was not a valid definition" , usecase.codePos)
35+ usecase
3536 }
3637 }
38+ val newComment = comment.copy(usecases = typedUsecases)
39+ docCtx.addDocstring(sym, Some (newComment))
40+ newComment
3741 }
3842 }
3943
40- private def expandParentDocs (sym : Symbol )(implicit ctx : Context ): Unit =
41- ctx.docCtx.foreach { docCtx =>
42- docCtx.docstring(sym).foreach { cmt =>
43- def expandDoc (owner : Symbol ): Unit = if (! cmt.isExpanded) {
44- val tplExp = docCtx.templateExpander
45- tplExp.defineVariables(sym)
46-
47- val newCmt = cmt
48- .expand(tplExp.expandedDocComment(sym, owner, _))
49-
50- docCtx.addDocstring(sym, Some (newCmt))
51- }
44+ private def expandDoc (sym : Symbol , owner : Symbol , comment : Comment )(implicit ctx : Context , docCtx : ContextDocstrings ): Comment = {
45+ if (! comment.isExpanded) {
46+ val tplExp = docCtx.templateExpander
47+ tplExp.defineVariables(sym)
48+ val newComment = comment.expand(tplExp.expandedDocComment(sym, owner, _))
49+ docCtx.addDocstring(sym, Some (newComment))
50+ newComment
51+ } else {
52+ comment
53+ }
54+ }
5255
53- if (sym ne NoSymbol ) {
54- expandParentDocs(sym.owner)
55- expandDoc(sym.owner)
56- }
57- }
56+ private def expandParentDocs (sym : Symbol )(implicit ctx : Context , docCtx : ContextDocstrings ): Option [Comment ] = {
57+ if (sym eq NoSymbol ) None
58+ else {
59+ for {
60+ cmt <- docCtx.docstring(sym) if ! cmt.isExpanded
61+ _ = expandParentDocs(sym.owner)
62+ } yield expandDoc(sym, sym.owner, cmt)
5863 }
64+ }
5965}
0 commit comments