diff options
Diffstat (limited to 'src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala')
-rw-r--r-- | src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala | 94 |
1 files changed, 66 insertions, 28 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala b/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala index 8ea8c4deff..a16b306322 100644 --- a/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala +++ b/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala @@ -103,48 +103,85 @@ abstract class ScaladocSyntaxAnalyzer[G <: Global](val global: G) extends Syntax class ScaladocJavaUnitParser(unit: CompilationUnit) extends { override val in = new ScaladocJavaUnitScanner(unit) - } with JavaUnitParser(unit) { } + } with JavaUnitParser(unit) { + + override def joinComment(trees: => List[Tree]): List[Tree] = { + val doc = in.flushDoc() + + if ((doc ne null) && doc.raw.length > 0) { + log(s"joinComment(doc=$doc)") + val joined = trees map { + t => + DocDef(doc, t) setPos { + if (t.pos.isDefined) { + val pos = doc.pos.withEnd(t.pos.end) + // always make the position transparent + pos.makeTransparent + } else { + t.pos + } + } + } + joined.find(_.pos.isOpaqueRange) foreach { + main => + val mains = List(main) + joined foreach { t => if (t ne main) ensureNonOverlapping(t, mains) } + } + joined + } + else trees + + // trees + } + + + } class ScaladocJavaUnitScanner(unit: CompilationUnit) extends JavaUnitScanner(unit) { + + //is the scanner currently in a doc comment + var inDocComment = false + var docStart: Int = 0 + /** buffer for the documentation comment */ - var docBuffer: StringBuilder = null + val docBuffer: StringBuilder = new StringBuilder + + var lastDoc: DocComment = null + def flushDoc() = try lastDoc finally lastDoc = null + /** add the given character to the documentation buffer */ - protected def putDocChar(c: Char) { - if (docBuffer ne null) docBuffer.append(c) + override protected def putCommentChar(): Unit = { + if (inDocComment) docBuffer append in.ch + in.next + } + + override protected def skipBlockComment(isDoc: Boolean): Unit = { + if (!inDocComment && isDoc) { + docBuffer append "/*" // at this point, in.ch == * and will be appended next + docStart = in.cpos + inDocComment = true + } + super.skipBlockComment(isDoc) } override protected def skipComment(): Boolean = { - if (in.ch == '/') { - do { - in.next - } while ((in.ch != CR) && (in.ch != LF) && (in.ch != SU)) - true - } else if (in.ch == '*') { - docBuffer = null - in.next - val scaladoc = ("/**", "*/") - if (in.ch == '*') - docBuffer = new StringBuilder(scaladoc._1) - do { - do { - if (in.ch != '*' && in.ch != SU) { - in.next; putDocChar(in.ch) - } - } while (in.ch != '*' && in.ch != SU) - while (in.ch == '*') { - in.next; putDocChar(in.ch) - } - } while (in.ch != '/' && in.ch != SU) - if (in.ch == '/') in.next - else incompleteInputError("unclosed comment") + val skipped = super.skipComment() + if (skipped && inDocComment) { + val str = docBuffer.toString + docBuffer.setLength(0) //clear buffer + val p = Position.range(unit.source, docStart - 2, docStart - 2, in.cpos) + signalParsedDocComment(str, p) + lastDoc = DocComment(str, p) + inDocComment = false true } else { - false + skipped } } + } class ScaladocUnitScanner(unit0: CompilationUnit, patches0: List[BracePatch]) extends UnitScanner(unit0, patches0) { @@ -230,6 +267,7 @@ abstract class ScaladocSyntaxAnalyzer[G <: Global](val global: G) extends Syntax } } class ScaladocUnitParser(unit: CompilationUnit, patches: List[BracePatch]) extends UnitParser(unit, patches) { + override def newScanner() = new ScaladocUnitScanner(unit, patches) override def withPatches(patches: List[BracePatch]) = new ScaladocUnitParser(unit, patches) |