~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to src/compiler/scala/tools/nsc/io/PlainFile.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* NSC -- new Scala compiler
2
 
 * Copyright 2005-2011 LAMP/EPFL
3
 
 * @author  Martin Odersky
4
 
 */
5
 
 
6
 
 
7
 
package scala.tools.nsc
8
 
package io
9
 
 
10
 
import java.io.{ FileInputStream, FileOutputStream, IOException }
11
 
import PartialFunction._
12
 
 
13
 
object PlainFile {
14
 
  /**
15
 
   * If the specified File exists, returns an abstract file backed
16
 
   * by it. Otherwise, returns null.
17
 
   */
18
 
  def fromPath(file: Path): PlainFile =
19
 
    if (file.isDirectory) new PlainDirectory(file.toDirectory)
20
 
    else if (file.isFile) new PlainFile(file)
21
 
    else null
22
 
}
23
 
 
24
 
class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) {
25
 
  override def isDirectory = true
26
 
  override def iterator = givenPath.list filter (_.exists) map (x => new PlainFile(x))
27
 
  override def delete(): Unit = givenPath.deleteRecursively()
28
 
}
29
 
 
30
 
/** This class implements an abstract file backed by a File.
31
 
 */
32
 
class PlainFile(val givenPath: Path) extends AbstractFile {
33
 
  assert(path ne null)
34
 
 
35
 
  val file = givenPath.jfile
36
 
  override def underlyingSource = Some(this)
37
 
 
38
 
  private val fpath = givenPath.toAbsolute
39
 
 
40
 
  /** Returns the name of this abstract file. */
41
 
  def name = givenPath.name
42
 
 
43
 
  /** Returns the path of this abstract file. */
44
 
  def path = givenPath.path
45
 
 
46
 
  /** The absolute file. */
47
 
  def absolute = new PlainFile(givenPath.toAbsolute)
48
 
 
49
 
  override def container: AbstractFile = new PlainFile(givenPath.parent)
50
 
  override def input = givenPath.toFile.inputStream()
51
 
  override def output = givenPath.toFile.outputStream()
52
 
  override def sizeOption = Some(givenPath.length.toInt)
53
 
 
54
 
  override def hashCode(): Int = fpath.hashCode
55
 
  override def equals(that: Any): Boolean = that match {
56
 
    case x: PlainFile => fpath == x.fpath
57
 
    case _            => false
58
 
  }
59
 
 
60
 
  /** Is this abstract file a directory? */
61
 
  def isDirectory: Boolean = givenPath.isDirectory
62
 
 
63
 
  /** Returns the time that this abstract file was last modified. */
64
 
  def lastModified: Long = givenPath.lastModified
65
 
 
66
 
  /** Returns all abstract subfiles of this abstract directory. */
67
 
  def iterator: Iterator[AbstractFile] = {
68
 
    if (!isDirectory) Iterator.empty
69
 
    else givenPath.toDirectory.list filter (_.exists) map (new PlainFile(_))
70
 
  }
71
 
 
72
 
  /**
73
 
   * Returns the abstract file in this abstract directory with the
74
 
   * specified name. If there is no such file, returns null. The
75
 
   * argument "directory" tells whether to look for a directory or
76
 
   * or a regular file.
77
 
   *
78
 
   * @param name      ...
79
 
   * @param directory ...
80
 
   * @return          ...
81
 
   */
82
 
  def lookupName(name: String, directory: Boolean): AbstractFile = {
83
 
    val child = givenPath / name
84
 
    if ((child.isDirectory && directory) || (child.isFile && !directory)) new PlainFile(child)
85
 
    else null
86
 
  }
87
 
 
88
 
  /** Does this abstract file denote an existing file? */
89
 
  def create(): Unit = if (!exists) givenPath.createFile()
90
 
 
91
 
  /** Delete the underlying file or directory (recursively). */
92
 
  def delete(): Unit =
93
 
    if (givenPath.isFile) givenPath.delete()
94
 
    else if (givenPath.isDirectory) givenPath.toDirectory.deleteRecursively()
95
 
 
96
 
  /** Returns a plain file with the given name. It does not
97
 
   *  check that it exists.
98
 
   */
99
 
  def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile =
100
 
    new PlainFile(givenPath / name)
101
 
}