Skip to content

Commit

Permalink
Extract base scaladoc functionality for the IDE.
Browse files Browse the repository at this point in the history
  • Loading branch information
vigdorchik committed Dec 12, 2012
1 parent 522ef79 commit e5e6d67
Show file tree
Hide file tree
Showing 36 changed files with 664 additions and 496 deletions.
39 changes: 20 additions & 19 deletions src/compiler/scala/tools/nsc/ast/DocComments.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ import scala.collection.mutable
*/ */
trait DocComments { self: Global => trait DocComments { self: Global =>


var cookedDocComments = Map[Symbol, String]() val cookedDocComments = mutable.HashMap[Symbol, String]()


/** The raw doc comment map */ /** The raw doc comment map */
val docComments = mutable.HashMap[Symbol, DocComment]() val docComments = mutable.HashMap[Symbol, DocComment]()


def clearDocComments() {
cookedDocComments.clear()
docComments.clear()
defs.clear()
}

/** Associate comment with symbol `sym` at position `pos`. */ /** Associate comment with symbol `sym` at position `pos`. */
def docComment(sym: Symbol, docStr: String, pos: Position = NoPosition) = def docComment(sym: Symbol, docStr: String, pos: Position = NoPosition) =
if ((sym ne null) && (sym ne NoSymbol)) if ((sym ne null) && (sym ne NoSymbol))
Expand Down Expand Up @@ -55,25 +61,20 @@ trait DocComments { self: Global =>
* If a symbol does not have a doc comment but some overridden version of it does, * If a symbol does not have a doc comment but some overridden version of it does,
* the doc comment of the overridden version is copied instead. * the doc comment of the overridden version is copied instead.
*/ */
def cookedDocComment(sym: Symbol, docStr: String = ""): String = cookedDocComments.get(sym) match { def cookedDocComment(sym: Symbol, docStr: String = ""): String = cookedDocComments.getOrElseUpdate(sym, {
case Some(comment) => val ownComment = if (docStr.length == 0) docComments get sym map (_.template) getOrElse ""
comment
case None =>
val ownComment = if (docStr.length == 0) docComments get sym map (_.template) getOrElse ""
else DocComment(docStr).template else DocComment(docStr).template
val comment = superComment(sym) match { superComment(sym) match {
case None => case None =>
if (ownComment.indexOf("@inheritdoc") != -1) if (ownComment.indexOf("@inheritdoc") != -1)
reporter.warning(sym.pos, "The comment for " + sym + reporter.warning(sym.pos, "The comment for " + sym +
" contains @inheritdoc, but no parent comment is available to inherit from.") " contains @inheritdoc, but no parent comment is available to inherit from.")
ownComment.replaceAllLiterally("@inheritdoc", "<invalid inheritdoc annotation>") ownComment.replaceAllLiterally("@inheritdoc", "<invalid inheritdoc annotation>")
case Some(sc) => case Some(sc) =>
if (ownComment == "") sc if (ownComment == "") sc
else expandInheritdoc(sc, merge(sc, ownComment, sym), sym) else expandInheritdoc(sc, merge(sc, ownComment, sym), sym)
} }
cookedDocComments += (sym -> comment) })
comment
}


/** The cooked doc comment of symbol `sym` after variable expansion, or "" if missing. /** The cooked doc comment of symbol `sym` after variable expansion, or "" if missing.
* *
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/doc/DocFactory.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DocFactory(val reporter: Reporter, val settings: doc.Settings) { processor
with model.ModelFactoryImplicitSupport with model.ModelFactoryImplicitSupport
with model.ModelFactoryTypeSupport with model.ModelFactoryTypeSupport
with model.diagram.DiagramFactory with model.diagram.DiagramFactory
with model.comment.CommentFactory with model.CommentFactory
with model.TreeFactory with model.TreeFactory
with model.MemberLookup { with model.MemberLookup {
override def templateShouldDocument(sym: compiler.Symbol, inTpl: DocTemplateImpl) = override def templateShouldDocument(sym: compiler.Symbol, inTpl: DocTemplateImpl) =
Expand Down
Loading

0 comments on commit e5e6d67

Please sign in to comment.