Skip to content

Commit

Permalink
[backport] Update javadoc tag to new scaladoc tags.
Browse files Browse the repository at this point in the history
(cherry picked from commit 68b16a0)
  • Loading branch information
pocket7878 authored and gourlaysama committed Aug 11, 2014
1 parent 5cb672b commit 40beefb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/compiler/scala/tools/nsc/ast/DocComments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,21 @@ trait DocComments { self: Global =>
comment.defineVariables(sym)
}


def replaceInheritDocToInheritdoc(docStr: String):String = {
docStr.replaceAll("""\{@inheritDoc\p{Zs}*\}""", "@inheritdoc")
}

/** The raw doc comment of symbol `sym`, minus usecase and define sections, augmented by
* missing sections of an inherited doc comment.
* 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.
*/
def cookedDocComment(sym: Symbol, docStr: String = ""): String = cookedDocComments.getOrElseUpdate(sym, {
val ownComment = if (docStr.length == 0) docComments get sym map (_.template) getOrElse ""
var ownComment = if (docStr.length == 0) docComments get sym map (_.template) getOrElse ""
else DocComment(docStr).template
ownComment = replaceInheritDocToInheritdoc(ownComment)

superComment(sym) match {
case None =>
if (ownComment.indexOf("@inheritdoc") != -1)
Expand Down
1 change: 1 addition & 0 deletions src/scaladoc/scala/tools/nsc/doc/ScaladocGlobal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import reporters.Reporter
import typechecker.Analyzer
import scala.reflect.internal.util.{ BatchSourceFile, RangePosition }


trait ScaladocGlobalTrait extends Global {
outer =>

Expand Down
22 changes: 11 additions & 11 deletions src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,19 @@ trait CommentFactoryBase { this: MemberLookupBase =>
/** Javadoc tags that should be replaced by something useful, such as wiki
* syntax, or that should be dropped. */
private val JavadocTags =
new Regex("""\{\@(code|docRoot|inheritDoc|link|linkplain|literal|value)([^}]*)\}""")
new Regex("""\{\@(code|docRoot|linkplain|link|literal|value)\p{Zs}*([^}]*)\}""")

/** Maps a javadoc tag to a useful wiki replacement, or an empty string if it cannot be salvaged. */
private def javadocReplacement(mtch: Regex.Match): String = mtch.group(1) match {
case "code" => "`" + mtch.group(2) + "`"
case "docRoot" => ""
case "inheritDoc" => ""
case "link" => "`" + mtch.group(2) + "`"
case "linkplain" => "`" + mtch.group(2) + "`"
case "literal" => mtch.group(2)
case "value" => "`" + mtch.group(2) + "`"
case _ => ""
private def javadocReplacement(mtch: Regex.Match): String = {
mtch.group(1) match {
case "code" => "<code>" + mtch.group(2) + "</code>"
case "docRoot" => ""
case "link" => "`[[" + mtch.group(2) + "]]`"
case "linkplain" => "[[" + mtch.group(2) + "]]"
case "literal" => "`" + mtch.group(2) + "`"
case "value" => "`" + mtch.group(2) + "`"
case _ => ""
}
}

/** Safe HTML tags that can be kept. */
Expand Down Expand Up @@ -680,7 +681,6 @@ trait CommentFactoryBase { this: MemberLookupBase =>
jump("[[")
val parens = 2 + repeatJump('[')
val stop = "]" * parens
//println("link with " + parens + " matching parens")
val target = readUntil { check(stop) || check(" ") }
val title =
if (!check(stop)) Some({
Expand Down

0 comments on commit 40beefb

Please sign in to comment.