summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/util/ClassFileLookup.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/ClassFileLookup.scala')
-rw-r--r--src/compiler/scala/tools/nsc/util/ClassFileLookup.scala21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/util/ClassFileLookup.scala b/src/compiler/scala/tools/nsc/util/ClassFileLookup.scala
index 4451651229..5d8831a607 100644
--- a/src/compiler/scala/tools/nsc/util/ClassFileLookup.scala
+++ b/src/compiler/scala/tools/nsc/util/ClassFileLookup.scala
@@ -3,6 +3,8 @@
*/
package scala.tools.nsc.util
+import scala.tools.nsc.Settings
+import scala.tools.nsc.classpath.{AggregateFlatClassPath, FlatClassPath, FlatClassPathFactory}
import scala.tools.nsc.io.AbstractFile
import java.net.URL
@@ -39,6 +41,25 @@ trait ClassFileLookup[T] {
def asSourcePathString: String
}
+object ClassFileLookup {
+ def createForFile(f: AbstractFile, current: ClassFileLookup[AbstractFile], settings: Settings): ClassFileLookup[AbstractFile] = current match {
+ case cp: ClassPath[_] => cp.context.newClassPath(f)
+ case _: FlatClassPath => FlatClassPathFactory.newClassPath(f, settings)
+ }
+
+ def createAggregate(elems: Iterable[ClassFileLookup[AbstractFile]], current: ClassFileLookup[AbstractFile]): ClassFileLookup[AbstractFile] = {
+ assert(elems.nonEmpty)
+ if (elems.size == 1) elems.head
+ else current match {
+ case cp: ClassPath[_] =>
+ new MergedClassPath(elems.asInstanceOf[Iterable[ClassPath[AbstractFile]]], cp.context)
+
+ case _: FlatClassPath =>
+ AggregateFlatClassPath.createAggregate(elems.asInstanceOf[Iterable[FlatClassPath]].toSeq : _*)
+ }
+ }
+}
+
/**
* Represents classes which can be loaded with a ClassfileLoader and/or SourcefileLoader.
*/