diff options
author | Som Snytt <som.snytt@gmail.com> | 2013-04-17 13:11:18 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2013-04-17 13:50:42 -0700 |
commit | 3f0a90bd53cd1fc85891cf2673318c3a91f713bc (patch) | |
tree | 54e7b6b0a14715e104115098730e256a2840862c /src/scaladoc | |
parent | 0fde95e6a4c0659a59519399573ece0e684be660 (diff) | |
download | scala-3f0a90bd53cd1fc85891cf2673318c3a91f713bc.tar.gz scala-3f0a90bd53cd1fc85891cf2673318c3a91f713bc.tar.bz2 scala-3f0a90bd53cd1fc85891cf2673318c3a91f713bc.zip |
SI-7376 Unmoored doc has correct position
The unmoored DocComment is created more eagerly so that its position
is correct despite subsequent line comments. (Previously, skipComment
would advance docPos.)
It looks like the error caret is still off by one when a doc comment
shows up in the middle of an operator, and who doesn't scaladoc the
interior of expressions?
Another bug fixed by Paul's refactor is that additional comments
between the doc and the entity no longer breaks the scaladoc.
Test added.
Diffstat (limited to 'src/scaladoc')
-rw-r--r-- | src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala b/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala index 99a6ab9e3e..003c439f65 100644 --- a/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala +++ b/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala @@ -149,9 +149,9 @@ abstract class ScaladocSyntaxAnalyzer[G <: Global](val global: G) extends Syntax class ScaladocUnitScanner(unit0: CompilationUnit, patches0: List[BracePatch]) extends UnitScanner(unit0, patches0) { - private var docBuffer: StringBuilder = null // buffer for comments - private var docPos: Position = NoPosition // last doc comment position - private var inDocComment = false + private var docBuffer: StringBuilder = null // buffer for comments (non-null while scanning) + private var inDocComment = false // if buffer contains double-star doc comment + private var lastDoc: DocComment = null // last comment if it was double-star doc private lazy val unmooredParser = { // minimalist comment parser import scala.tools.nsc.doc.base.{comment => _, _} @@ -180,7 +180,7 @@ abstract class ScaladocSyntaxAnalyzer[G <: Global](val global: G) extends Syntax * Also warn under -Xlint, but otherwise only warn in the presence of suspicious * tags that appear to be documenting API. Warnings are suppressed while parsing * the local comment so that comments of the form `[at] Martin` will not trigger a warning. - * In addition, tags for `todo`, `note` and `example` are ignored. + * By omission, tags for `see`, `todo`, `note` and `example` are ignored. */ override def discardDocBuffer() = { import scala.tools.nsc.doc.base.comment.Comment @@ -193,13 +193,10 @@ abstract class ScaladocSyntaxAnalyzer[G <: Global](val global: G) extends Syntax } def isDirty = unclean(unmooredParser parseComment doc) if ((doc ne null) && (settings.lint || isDirty)) - unit.warning(docPos, "discarding unmoored doc comment") + unit.warning(doc.pos, "discarding unmoored doc comment") } - override def flushDoc(): DocComment = { - if (docBuffer eq null) null - else try DocComment(docBuffer.toString, docPos) finally docBuffer = null - } + override def flushDoc(): DocComment = (try lastDoc finally lastDoc = null) override protected def putCommentChar() { if (inDocComment) @@ -218,23 +215,19 @@ abstract class ScaladocSyntaxAnalyzer[G <: Global](val global: G) extends Syntax super.skipBlockComment() } override def skipComment(): Boolean = { - super.skipComment() && { - if (docBuffer ne null) { - if (inDocComment) - foundDocComment(docBuffer.toString, offset, charOffset - 2) - else - try foundComment(docBuffer.toString, offset, charOffset - 2) finally docBuffer = null - } + // emit a block comment; if it's double-star, make Doc at this pos + def foundStarComment(start: Int, end: Int) = try { + val str = docBuffer.toString + val pos = new RangePosition(unit.source, start, start, end) + unit.comment(pos, str) + if (inDocComment) + lastDoc = DocComment(str, pos) true + } finally { + docBuffer = null + inDocComment = false } - } - def foundComment(value: String, start: Int, end: Int) { - val pos = new RangePosition(unit.source, start, start, end) - unit.comment(pos, value) - } - def foundDocComment(value: String, start: Int, end: Int) { - docPos = new RangePosition(unit.source, start, start, end) - unit.comment(docPos, value) + super.skipComment() && ((docBuffer eq null) || foundStarComment(offset, charOffset - 2)) } } class ScaladocUnitParser(unit: CompilationUnit, patches: List[BracePatch]) extends UnitParser(unit, patches) { |