From ebafcc4e7cb4734736d6a063d49226f944d74637 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 26 Jan 2011 12:07:07 +0000 Subject: One last attempt at getting the presentation co... One last attempt at getting the presentation compiler pass some tests. no review. --- .../nsc/interactive/tests/InteractiveTest.scala | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src') 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) } -- cgit v1.2.3