diff options
author | Miles Sabin <miles@milessabin.com> | 2009-10-14 22:10:20 +0000 |
---|---|---|
committer | Miles Sabin <miles@milessabin.com> | 2009-10-14 22:10:20 +0000 |
commit | b57abb7bfefdc8b1c07742cd01ab2b620bcc018a (patch) | |
tree | 9532fbc6868ba3546b6fbc435ef41dd610c53ca8 /src | |
parent | 9d9889a7d6b9625aff6ee9ef72850cd9c9e7c17c (diff) | |
download | scala-b57abb7bfefdc8b1c07742cd01ab2b620bcc018a.tar.gz scala-b57abb7bfefdc8b1c07742cd01ab2b620bcc018a.tar.bz2 scala-b57abb7bfefdc8b1c07742cd01ab2b620bcc018a.zip |
Scaladoc comment position fixes with tests; sca...
Scaladoc comment position fixes with tests; scaladoc comment postions
are now accessible by symbol; respond retry in interactive Global is now
handled properly.
Diffstat (limited to 'src')
5 files changed, 54 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index bcf81c56e6..f447cf4327 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -125,6 +125,14 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable if (onlyPresentation) new HashMap[Symbol,String] else null + /** A map of all doc comments source file offsets, + * indexed by symbols. + * Only active in onlyPresentation mode + */ + val commentOffsets = + if (onlyPresentation) new HashMap[Symbol,Int] + else null + /** A map of argument names for methods * !!! can be dropped once named method arguments are in !!! */ diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 6bd9371c2a..8f94c64a4e 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -420,8 +420,17 @@ self => /** Join the comment associated with a definition */ def joinComment(trees: => List[Tree]): List[Tree] = { - val buf = in.flushDoc - if ((buf ne null) && buf.length > 0) trees map (t => DocDef(buf, t) setPos t.pos) // !!! take true comment position + val doc = in.flushDoc + if ((doc ne null) && doc._1.length > 0) { + val ts = trees + val main = ts.find(_.pos.isOpaqueRange) + ts map { + t => + val dd = DocDef(doc._1, t) + val pos = doc._2.withEnd(t.pos.endOrPoint) + dd setPos (if (t eq main) pos else pos.makeTransparent) + } + } else trees } diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 570bb1f0c9..c966a23fcb 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -103,10 +103,11 @@ trait Scanners { /** buffer for the documentation comment */ var docBuffer: StringBuilder = null + var docOffset: Position = null /** Return current docBuffer and set docBuffer to null */ def flushDoc = { - val ret = if (docBuffer != null) docBuffer.toString else null + val ret = if (docBuffer != null) (docBuffer.toString, docOffset) else null docBuffer = null ret } @@ -119,6 +120,8 @@ trait Scanners { protected def foundComment(value: String, start: Int, end: Int) = () + protected def foundDocComment(value: String, start: Int, end: Int) = () + private class TokenData0 extends TokenData /** we need one token lookahead and one token history @@ -411,8 +414,11 @@ trait Scanners { var openComments = 1 nextChar() appendToComment() - if (ch == '*' && buildDocs) + var buildingDocComment = false + if (ch == '*' && buildDocs) { + buildingDocComment = true docBuffer = new StringBuilder("/**") + } while (openComments > 0) { do { do { @@ -435,7 +441,11 @@ trait Scanners { else incompleteInputError("unclosed comment") openComments -= 1 } + + if (buildingDocComment) + foundDocComment(comment.toString, offset, charOffset - 2) } + foundComment(comment.toString, offset, charOffset - 2) true } else { @@ -1059,6 +1069,10 @@ trait Scanners { override def foundComment(value: String, start: Int, end: Int) { unit.comments += unit.Comment(value, new RangePosition(unit.source, start, start, end)) } + + override def foundDocComment(value: String, start: Int, end: Int) { + docOffset = new RangePosition(unit.source, start, start, end) + } } class ParensAnalyzer(unit: CompilationUnit, patches: List[BracePatch]) extends UnitScanner(unit, patches) { diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index b0b82e5743..8444065004 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -200,6 +200,7 @@ self => outOfDate = false compileRunner = newRunnerThread ex match { + case _ : FreshRunReq => // This shouldn't be reported case _ : ValidateError => // This will have been reported elsewhere case _ => ex.printStackTrace(); inform("Fatal Error: "+ex) } @@ -265,16 +266,17 @@ self => // ----------------- Implementations of client commmands ----------------------- def respond[T](result: Response[T])(op: => T): Unit = - while(true) - try { - result set Left(op) - return - } catch { - case ex : ControlException => - case ex => - result set Right(ex) - throw ex - } + try { + result set Left(op) + return + } catch { + case ex : FreshRunReq => + scheduler.postWorkItem(() => respond(result)(op)) + throw ex + case ex => + result set Right(ex) + throw ex + } /** Make sure a set of compilation units is loaded and parsed */ def reloadSources(sources: List[SourceFile]) { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index ebcd18082d..e07d1e252d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1392,8 +1392,8 @@ trait Typers { self: Analyzer => } if (mods hasFlag DEFERRED) gs.toList else vdef :: gs.toList } - case DocDef(comment, defn) => - addGetterSetter(defn) map (stat => DocDef(comment, stat)) + case dd @ DocDef(comment, defn) => + addGetterSetter(defn) map (stat => DocDef(comment, stat) setPos dd.pos) case Annotated(annot, defn) => addGetterSetter(defn) map (stat => Annotated(annot, stat)) @@ -3519,9 +3519,12 @@ trait Typers { self: Analyzer => case ldef @ LabelDef(_, _, _) => labelTyper(ldef).typedLabelDef(ldef) - case DocDef(comment, defn) => + case ddef @ DocDef(comment, defn) => val ret = typed(defn, mode, pt) - if ((comments ne null) && (defn.symbol ne null) && (defn.symbol ne NoSymbol)) comments(defn.symbol) = comment + if ((comments ne null) && (defn.symbol ne null) && (defn.symbol ne NoSymbol)) { + comments(defn.symbol) = comment + commentOffsets(defn.symbol) = ddef.pos.startOrPoint + } ret case Annotated(constr, arg) => |