diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2011-01-26 12:07:07 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2011-01-26 12:07:07 +0000 |
commit | ebafcc4e7cb4734736d6a063d49226f944d74637 (patch) | |
tree | e1b6cbce30f6ba1310ed5baa8af36653057e5b2a /src/compiler | |
parent | ccc81fa54cca9939e0d45487d65b1e317bef91b6 (diff) | |
download | scala-ebafcc4e7cb4734736d6a063d49226f944d74637.tar.gz scala-ebafcc4e7cb4734736d6a063d49226f944d74637.tar.bz2 scala-ebafcc4e7cb4734736d6a063d49226f944d74637.zip |
One last attempt at getting the presentation co...
One last attempt at getting the presentation compiler pass some tests.
no review.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala b/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala index 1cda29fdba..1d106a5c64 100644 --- a/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala +++ b/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala @@ -94,19 +94,40 @@ abstract class InteractiveTest { buf.toList } + /** Should askAllSources wait for each ask to finish before issueing the next? */ + val synchronousRequests = true + /** Perform an operation on all sources at all positions that match the given * marker string. For instance, askAllSources("/*!*/")(askTypeAt)(println) would * ask the tyep at all positions marked with /*!*/ and println the result. */ - def askAllSources[T](marker: String)(askAt: Position => Response[T])(f: (Position, T) => Unit) { + def askAllSourcesAsync[T](marker: String)(askAt: Position => Response[T])(f: (Position, T) => Unit) { val positions = allPositionsOf(str = marker).valuesIterator.toList.flatten val responses = for (pos <- positions) yield askAt(pos) - for ((pos, r) <- positions zip responses) r.get(TIMEOUT) match { - case Some(Left(members)) => - f(pos, members) + for ((pos, r) <- positions zip responses) withResponse(pos, r)(f) + } + + /** Synchronous version of askAllSources. Each position is treated in turn, waiting for the + * response before going to the next one. + */ + def askAllSourcesSync[T](marker: String)(askAt: Position => Response[T])(f: (Position, T) => Unit) { + val positions = allPositionsOf(str = marker).valuesIterator.toList.flatten + for (pos <- positions) withResponse(pos, askAt(pos))(f) + } + + def askAllSources[T] = if (synchronousRequests) askAllSourcesSync[T] _ else askAllSourcesAsync[T] _ + + /** Return the filename:line:col version of this position. */ + def showPos(pos: Position): String = + "%s:%d:%d".format(pos.source.file.name, pos.line, pos.column) + + protected def withResponse[T](pos: Position, response: Response[T])(f: (Position, T) => Unit) { + response.get(TIMEOUT) match { + case Some(Left(t)) => + f(pos, t) case None => - println("TIMEOUT: " + r) + println("TIMEOUT: " + showPos(pos)) case Some(r) => println("ERROR: " + r) } |