summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiles Sabin <miles@milessabin.com>2010-01-15 14:12:20 +0000
committerMiles Sabin <miles@milessabin.com>2010-01-15 14:12:20 +0000
commit135ec1392770b301925e2e9c660f7a67e4615ee9 (patch)
tree846d54796b54e449d8f917d307669aa473ab9173
parent2d324f4506191ba9059e14fa7482c2276b5f255a (diff)
downloadscala-135ec1392770b301925e2e9c660f7a67e4615ee9.tar.gz
scala-135ec1392770b301925e2e9c660f7a67e4615ee9.tar.bz2
scala-135ec1392770b301925e2e9c660f7a67e4615ee9.zip
Fixes for various Scaladoc-related positions re...
Fixes for various Scaladoc-related positions regressions with tests. Review by dubochet.
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala33
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Scanners.scala5
-rw-r--r--test/files/positions/Scaladoc6.scala10
-rw-r--r--test/files/positions/Scaladoc7.scala6
-rw-r--r--test/files/positions/Scaladoc8.scala6
5 files changed, 49 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 91fd7dbdc8..b86356ba94 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -421,17 +421,19 @@ self =>
def joinComment(trees: => List[Tree]): List[Tree] = {
val doc = in.flushDoc
if ((doc ne null) && doc.raw.length > 0) {
- val ts = trees
- val main = ts.find(_.pos.isOpaqueRange)
- ts map {
+ val joined = trees map {
t =>
val dd = DocDef(doc, t)
- val pos = doc.pos.withEnd(t.pos.endOrPoint)
- dd setPos (
- if (main exists (_ eq t)) pos
- else pos.makeTransparent
- )
+ val defnPos = t.pos
+ val pos = doc.pos.withEnd(defnPos.endOrPoint)
+ dd setPos (if (defnPos.isOpaqueRange) pos else pos.makeTransparent)
}
+ joined.find(_.pos.isOpaqueRange) foreach {
+ main =>
+ val mains = List(main)
+ joined foreach { t => if (t ne main) ensureNonOverlapping(t, mains) }
+ }
+ joined
}
else trees
}
@@ -2463,14 +2465,15 @@ self =>
val stats = new ListBuffer[Tree]
while (in.token != RBRACE && in.token != EOF) {
if (in.token == PACKAGE) {
+ in.flushDoc
val start = in.skipToken()
stats += {
if (in.token == OBJECT) makePackageObject(start, objectDef(in.offset, NoMods))
else packaging(start)
}
} else if (in.token == IMPORT) {
+ in.flushDoc
stats ++= importClause()
- // XXX: IDE hook this all.
} else if (in.token == CLASS ||
in.token == CASECLASS ||
in.token == TRAIT ||
@@ -2501,6 +2504,7 @@ self =>
var self: ValDef = emptyValDef
val stats = new ListBuffer[Tree]
if (isExprIntro) {
+ in.flushDoc
val first = expr(InTemplate) // @S: first statement is potentially converted so cannot be stubbed.
if (in.token == ARROW) {
first match {
@@ -2521,8 +2525,10 @@ self =>
}
while (in.token != RBRACE && in.token != EOF) {
if (in.token == IMPORT) {
+ in.flushDoc
stats ++= importClause()
} else if (isExprIntro) {
+ in.flushDoc
stats += statement(InTemplate)
} else if (isDefIntro || isModifier || in.token == LBRACKET /*todo: remove */ || in.token == AT) {
stats ++= joinComment(nonLocalDefOrDcl)
@@ -2621,6 +2627,7 @@ self =>
while (in.token == SEMI) in.nextToken()
val start = in.offset
if (in.token == PACKAGE) {
+ in.flushDoc
in.nextToken()
if (in.token == OBJECT) {
ts += makePackageObject(start, objectDef(in.offset, NoMods))
@@ -2648,10 +2655,14 @@ self =>
}
ts.toList
}
- val start = caseAwareTokenOffset max 0
topstats() match {
case List(stat @ PackageDef(_, _)) => stat
- case stats => makePackaging(start, atPos(o2p(start)) { Ident(nme.EMPTY_PACKAGE_NAME) }, stats)
+ case stats =>
+ val start = stats match {
+ case Nil => 0
+ case _ => wrappingPos(stats).startOrPoint
+ }
+ makePackaging(start, atPos(start, start, start) { Ident(nme.EMPTY_PACKAGE_NAME) }, stats)
}
}
}
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
index be90a835f5..6cb7c8b99f 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
@@ -166,6 +166,11 @@ trait Scanners {
sepRegions = sepRegions.tail
case _ =>
}
+ (lastToken: @switch) match {
+ case RBRACE | RBRACKET | RPAREN =>
+ docBuffer = null
+ case _ =>
+ }
// Read a token or copy it from `next` tokenData
if (next.token == EMPTY) {
diff --git a/test/files/positions/Scaladoc6.scala b/test/files/positions/Scaladoc6.scala
new file mode 100644
index 0000000000..8beda625ae
--- /dev/null
+++ b/test/files/positions/Scaladoc6.scala
@@ -0,0 +1,10 @@
+object Scaladoc6 {
+ {
+ /**
+ * Foo
+ */
+ val i = 23
+ }
+
+ def f {}
+}
diff --git a/test/files/positions/Scaladoc7.scala b/test/files/positions/Scaladoc7.scala
new file mode 100644
index 0000000000..6175222e3f
--- /dev/null
+++ b/test/files/positions/Scaladoc7.scala
@@ -0,0 +1,6 @@
+object Scaladoc7 {
+ /**
+ * Foo
+ */
+ val Pair(i, j) = (1, 2)
+}
diff --git a/test/files/positions/Scaladoc8.scala b/test/files/positions/Scaladoc8.scala
new file mode 100644
index 0000000000..519d6ca06c
--- /dev/null
+++ b/test/files/positions/Scaladoc8.scala
@@ -0,0 +1,6 @@
+/**
+ * Foo
+ */
+object Scaladoc8 {
+
+}