summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/tools/nsc/interactive/CompilerControl.scala')
-rw-r--r--src/compiler/scala/tools/nsc/interactive/CompilerControl.scala13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
index 32a780104d..9d29b781c1 100644
--- a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
+++ b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
@@ -51,7 +51,14 @@ trait CompilerControl { self: Global =>
*/
def getUnitOf(s: SourceFile): Option[RichCompilationUnit] = getUnit(s)
- /** The compilation unit corresponding to a source file
+ /** Run operation `op` on a compilation unit assocuated with given `source`.
+ * If source has a loaded compilation unit, this one is passed to `op`.
+ * Otherwise a new compilation unit is created, but not added to the set of loaded units.
+ */
+ def onUnitOf[T](source: SourceFile)(op: RichCompilationUnit => T): T =
+ op(unitOfFile.getOrElse(source.file, new RichCompilationUnit(source)))
+
+ /** The compilation unit corresponding to a source file
* if it does not yet exist create a new one atomically
* Note: We want to get roid of this operation as it messes compiler invariants.
*/
@@ -193,6 +200,10 @@ trait CompilerControl { self: Global =>
/** Returns parse tree for source `source`. No symbols are entered. Syntax errors are reported.
*/
def askParse(source: SourceFile, response: Response[Tree]) = respond(response) {
+ parseTree(source)
+ }
+
+ def parseTree(source: SourceFile): Tree = ask { () =>
getUnit(source) match {
case Some(unit) if unit.status >= JustParsed =>
unit.body