package scala.tools.nsc
package io
import scala.collection.mutable
class VirtualDirectory(val name: String, maybeContainer: Option[VirtualDirectory])
extends AbstractFile {
def path: String =
maybeContainer match {
case None => name
case Some(parent) => parent.path+'/'+ name
}
def absolute = this
def container = maybeContainer.get
def isDirectory = true
var lastModified: Long = System.currentTimeMillis
override def file = null
override def input = sys.error("directories cannot be read")
override def output = sys.error("directories cannot be written")
def create() { unsupported }
def delete() { unsupported }
def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile = unsupported
private val files = mutable.Map.empty[String, AbstractFile]
def iterator = files.values.toList.iterator
override def lookupName(name: String, directory: Boolean): AbstractFile =
files get name filter (_.isDirectory == directory) orNull
override def fileNamed(name: String): AbstractFile =
Option(lookupName(name, false)) getOrElse {
val newFile = new VirtualFile(name, path+'/'+name)
files(name) = newFile
newFile
}
override def subdirectoryNamed(name: String): AbstractFile =
Option(lookupName(name, true)) getOrElse {
val dir = new VirtualDirectory(name, Some(this))
files(name) = dir
dir
}
def clear() {
files.clear();
}
}