@@ -19,11 +19,17 @@ import scala.collection.mutable
19
19
*/
20
20
trait DocComments { self : Global =>
21
21
22
- var cookedDocComments = Map [Symbol , String ]()
22
+ val cookedDocComments = mutable. HashMap [Symbol , String ]()
23
23
24
24
/** The raw doc comment map */
25
25
val docComments = mutable.HashMap [Symbol , DocComment ]()
26
26
27
+ def clearDocComments () {
28
+ cookedDocComments.clear()
29
+ docComments.clear()
30
+ defs.clear()
31
+ }
32
+
27
33
/** Associate comment with symbol `sym` at position `pos`. */
28
34
def docComment (sym : Symbol , docStr : String , pos : Position = NoPosition ) =
29
35
if ((sym ne null ) && (sym ne NoSymbol ))
@@ -55,25 +61,20 @@ trait DocComments { self: Global =>
55
61
* If a symbol does not have a doc comment but some overridden version of it does,
56
62
* the doc comment of the overridden version is copied instead.
57
63
*/
58
- def cookedDocComment (sym : Symbol , docStr : String = " " ): String = cookedDocComments.get(sym) match {
59
- case Some (comment) =>
60
- comment
61
- case None =>
62
- val ownComment = if (docStr.length == 0 ) docComments get sym map (_.template) getOrElse " "
64
+ def cookedDocComment (sym : Symbol , docStr : String = " " ): String = cookedDocComments.getOrElseUpdate(sym, {
65
+ val ownComment = if (docStr.length == 0 ) docComments get sym map (_.template) getOrElse " "
63
66
else DocComment (docStr).template
64
- val comment = superComment(sym) match {
65
- case None =>
66
- if (ownComment.indexOf(" @inheritdoc" ) != - 1 )
67
- reporter.warning(sym.pos, " The comment for " + sym +
68
- " contains @inheritdoc, but no parent comment is available to inherit from." )
69
- ownComment.replaceAllLiterally(" @inheritdoc" , " <invalid inheritdoc annotation>" )
70
- case Some (sc) =>
71
- if (ownComment == " " ) sc
72
- else expandInheritdoc(sc, merge(sc, ownComment, sym), sym)
73
- }
74
- cookedDocComments += (sym -> comment)
75
- comment
76
- }
67
+ superComment(sym) match {
68
+ case None =>
69
+ if (ownComment.indexOf(" @inheritdoc" ) != - 1 )
70
+ reporter.warning(sym.pos, " The comment for " + sym +
71
+ " contains @inheritdoc, but no parent comment is available to inherit from." )
72
+ ownComment.replaceAllLiterally(" @inheritdoc" , " <invalid inheritdoc annotation>" )
73
+ case Some (sc) =>
74
+ if (ownComment == " " ) sc
75
+ else expandInheritdoc(sc, merge(sc, ownComment, sym), sym)
76
+ }
77
+ })
77
78
78
79
/** The cooked doc comment of symbol `sym` after variable expansion, or "" if missing.
8B5B
79
80
*
0 commit comments