summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala31
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)
}