summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorHeather Miller <heather.miller@epfl.ch>2014-11-10 14:43:39 +0100
committerHeather Miller <heather.miller@epfl.ch>2014-11-10 14:43:39 +0100
commit24a2ef9728c403b81ffb36f2da241cff35defd78 (patch)
tree703f3c14b1aca411a235b8e6507ecd84b31b5101 /src/compiler
parent9e56c7a6fe73bce5962a3b121615c6a5bc1023d2 (diff)
downloadscala-24a2ef9728c403b81ffb36f2da241cff35defd78.tar.gz
scala-24a2ef9728c403b81ffb36f2da241cff35defd78.tar.bz2
scala-24a2ef9728c403b81ffb36f2da241cff35defd78.zip
SI-6502 Refactorings suggested by review
- Moves mergeUrlsIntoClassPath from Global into ClassPath - Revises and documents AbstractFile.getURL
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala26
-rw-r--r--src/compiler/scala/tools/nsc/util/ClassPath.scala19
2 files changed, 19 insertions, 26 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 3fb1bd10f0..430424d0f8 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -846,36 +846,12 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
/** Extend classpath of `platform` and rescan updated packages. */
def extendCompilerClassPath(urls: URL*): Unit = {
- val newClassPath = mergeUrlsIntoClassPath(platform, urls: _*)
+ val newClassPath = platform.classPath.mergeUrlsIntoClassPath(urls: _*)
platform.currentClassPath = Some(newClassPath)
// Reload all specified jars into this compiler instance
invalidateClassPathEntries(urls.map(_.getPath): _*)
}
- /** Merge classpath of `platform` and `urls` into merged classpath */
- def mergeUrlsIntoClassPath(platform: JavaPlatform, urls: URL*): MergedClassPath[AbstractFile] = {
- // Collect our new jars/directories and add them to the existing set of classpaths
- val prevEntries = platform.classPath match {
- case mcp: MergedClassPath[AbstractFile] => mcp.entries
- case cp: ClassPath[AbstractFile] => List(cp)
- }
- val allEntries = (prevEntries ++
- urls.map(url => platform.classPath.context.newClassPath(
- if (url.getProtocol == "file") {
- val f = new File(url.getPath)
- if (f.isDirectory) io.AbstractFile.getDirectory(f)
- else io.AbstractFile.getFile(f)
- } else {
- io.AbstractFile.getURL(url)
- }
- )
- )
- ).distinct
-
- // Combine all of our classpaths (old and new) into one merged classpath
- new MergedClassPath(allEntries, platform.classPath.context)
- }
-
// ------------ Invalidations ---------------------------------
/** Is given package class a system package class that cannot be invalidated?
diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala
index e89f08ec6b..e78dee5eee 100644
--- a/src/compiler/scala/tools/nsc/util/ClassPath.scala
+++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala
@@ -197,6 +197,23 @@ abstract class ClassPath[T] {
def packages: IndexedSeq[ClassPath[T]]
def sourcepaths: IndexedSeq[AbstractFile]
+ /** The entries this classpath is composed of. In class `ClassPath` it's just the singleton list containing `this`.
+ * Subclasses such as `MergedClassPath` typically return lists with more elements.
+ */
+ def entries: IndexedSeq[ClassPath[T]] = IndexedSeq(this)
+
+ /** Merge classpath of `platform` and `urls` into merged classpath */
+ def mergeUrlsIntoClassPath(urls: URL*): MergedClassPath[T] = {
+ // Collect our new jars/directories and add them to the existing set of classpaths
+ val allEntries =
+ (entries ++
+ urls.map(url => context.newClassPath(io.AbstractFile.getURL(url)))
+ ).distinct
+
+ // Combine all of our classpaths (old and new) into one merged classpath
+ new MergedClassPath(allEntries, context)
+ }
+
/**
* Represents classes which can be loaded with a ClassfileLoader and/or SourcefileLoader.
*/
@@ -322,7 +339,7 @@ extends MergedClassPath[T](original.entries map (e => subst getOrElse (e, e)), o
* A classpath unifying multiple class- and sourcepath entries.
*/
class MergedClassPath[T](
- val entries: IndexedSeq[ClassPath[T]],
+ override val entries: IndexedSeq[ClassPath[T]],
val context: ClassPathContext[T])
extends ClassPath[T] {
def this(entries: TraversableOnce[ClassPath[T]], context: ClassPathContext[T]) =