diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-03-29 13:07:54 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-03-29 13:28:31 +0100 |
commit | 0cb632440e07ce370a3b97f81a81ee920eadb282 (patch) | |
tree | d3bc80aeae327c6823057d86375e9d9d476ea785 /src/reflect/scala/reflect/io/Path.scala | |
parent | 2efc6d56e6ee14dc7d86bc0667c921b082e8b9b4 (diff) | |
download | scala-0cb632440e07ce370a3b97f81a81ee920eadb282.tar.gz scala-0cb632440e07ce370a3b97f81a81ee920eadb282.tar.bz2 scala-0cb632440e07ce370a3b97f81a81ee920eadb282.zip |
Add counters to File#{exists, isFile, isDirectory}.
Due to limitations in the Statistics machinery, these are only
reported if this patch is applied.
--- a/src/reflect/scala/reflect/internal/util/Statistics.scala
+++ b/src/reflect/scala/reflect/internal/util/Statistics.scala
@@ -109,7 +109,7 @@ quant)
* Quantities with non-empty prefix are printed in the statistics info.
*/
trait Quantity {
- if (enabled && prefix.nonEmpty) {
+ if (prefix.nonEmpty) {
val key = s"${if (underlying != this) underlying.prefix else ""}/$prefix"
qs(key) = this
}
@@ -243,7 +243,7 @@ quant)
*
* to remove all Statistics code from build
*/
- final val canEnable = _enabled
+ final val canEnable = true // _enabled
Diffstat (limited to 'src/reflect/scala/reflect/io/Path.scala')
-rw-r--r-- | src/reflect/scala/reflect/io/Path.scala | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/reflect/scala/reflect/io/Path.scala b/src/reflect/scala/reflect/io/Path.scala index 44fb41a1cd..56d4faed99 100644 --- a/src/reflect/scala/reflect/io/Path.scala +++ b/src/reflect/scala/reflect/io/Path.scala @@ -13,6 +13,7 @@ import java.io.{ File => JFile } import java.net.{ URI, URL } import scala.util.Random.alphanumeric import scala.language.implicitConversions +import scala.reflect.internal.util.Statistics /** An abstraction for filesystem paths. The differences between * Path, File, and Directory are primarily to communicate intent. @@ -57,8 +58,18 @@ object Path { def apply(path: String): Path = apply(new JFile(path)) def apply(jfile: JFile): Path = try { - if (jfile.isFile) new File(jfile) - else if (jfile.isDirectory) new Directory(jfile) + def isFile = { + if (Statistics.canEnable) Statistics.incCounter(IOStats.fileIsFileCount) + jfile.isFile + } + + def isDirectory = { + if (Statistics.canEnable) Statistics.incCounter(IOStats.fileIsDirectoryCount) + jfile.isDirectory + } + + if (isFile) new File(jfile) + else if (isDirectory) new Directory(jfile) else new Path(jfile) } catch { case ex: SecurityException => new Path(jfile) } @@ -187,10 +198,19 @@ class Path private[io] (val jfile: JFile) { // Boolean tests def canRead = jfile.canRead() def canWrite = jfile.canWrite() - def exists = try jfile.exists() catch { case ex: SecurityException => false } + def exists = { + if (Statistics.canEnable) Statistics.incCounter(IOStats.fileExistsCount) + try jfile.exists() catch { case ex: SecurityException => false } + } - def isFile = try jfile.isFile() catch { case ex: SecurityException => false } - def isDirectory = try jfile.isDirectory() catch { case ex: SecurityException => false } + def isFile = { + if (Statistics.canEnable) Statistics.incCounter(IOStats.fileIsFileCount) + try jfile.isFile() catch { case ex: SecurityException => false } + } + def isDirectory = { + if (Statistics.canEnable) Statistics.incCounter(IOStats.fileIsDirectoryCount) + try jfile.isDirectory() catch { case ex: SecurityException => false } + } def isAbsolute = jfile.isAbsolute() def isEmpty = path.length == 0 |