@@ -4,7 +4,6 @@ package typer
4
4
5
5
import core ._
6
6
import Contexts ._ , Symbols ._ , Decorators ._ , Comments ._
7
- import util .Positions ._
8
7
import ast .tpd
9
8
10
9
trait Docstrings { self : Typer =>
@@ -21,39 +20,46 @@ trait Docstrings { self: Typer =>
21
20
* @param sym The symbol for which the comment is being cooked.
22
21
* @param owner The class for which comments are being cooked.
23
22
*/
24
- def cookComment (sym : Symbol , owner : Symbol )(implicit ctx : Context ): Unit = {
23
+ def cookComment (sym : Symbol , owner : Symbol )(implicit ctx : Context ): Option [ Comment ] = {
25
24
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 =>
31
29
enterSymbol(createSymbol(usecase.untpdCode))
32
30
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
35
36
}
36
37
}
38
+ val newComment = comment.copy(usecases = typedUsecases)
39
+ docCtx.addDocstring(sym, Some (newComment))
40
+ newComment
37
41
}
38
42
}
39
43
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
+ }
52
55
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)
58
63
}
64
+ }
59
65
}
0 commit comments