Skip to content

Commit 77ca8d4

Browse files
committed
Rewrite io files to compile under Dotty
1 parent 1833e0b commit 77ca8d4

File tree

6 files changed

+23
-92
lines changed

6 files changed

+23
-92
lines changed

compiler/src/dotty/tools/dotc/util/WeakHashSet.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class WeakHashSet[A >: Null <: AnyRef](val initialCapacity: Int, val loadF
3737
/**
3838
* the number of elements in this set
3939
*/
40-
private[this] var count = 0
40+
/*private[this]*/ var count = 0
4141

4242
/**
4343
* from a specified initial capacity compute the capacity we'll use as being the next
@@ -86,7 +86,7 @@ final class WeakHashSet[A >: Null <: AnyRef](val initialCapacity: Int, val loadF
8686
/**
8787
* remove a single entry from a linked list in a given bucket
8888
*/
89-
private[this] def remove(bucket: Int, prevEntry: Entry[A], entry: Entry[A]) {
89+
private[this] def remove(bucket: Int, prevEntry: Entry[A], entry: Entry[A]): Unit = {
9090
prevEntry match {
9191
case null => table(bucket) = entry.tail
9292
case _ => prevEntry.tail = entry.tail
@@ -97,7 +97,7 @@ final class WeakHashSet[A >: Null <: AnyRef](val initialCapacity: Int, val loadF
9797
/**
9898
* remove entries associated with elements that have been gc'ed
9999
*/
100-
private[this] def removeStaleEntries() {
100+
private[this] def removeStaleEntries(): Unit = {
101101
def poll(): Entry[A] = queue.poll().asInstanceOf[Entry[A]]
102102

103103
@tailrec
@@ -122,7 +122,7 @@ final class WeakHashSet[A >: Null <: AnyRef](val initialCapacity: Int, val loadF
122122
/**
123123
* Double the size of the internal table
124124
*/
125-
private[this] def resize() {
125+
private[this] def resize(): Unit = {
126126
val oldTable = table
127127
table = new Array[Entry[A]](oldTable.size * 2)
128128
threshhold = computeThreshHold
@@ -207,7 +207,7 @@ final class WeakHashSet[A >: Null <: AnyRef](val initialCapacity: Int, val loadF
207207
val bucket = bucketFor(hash)
208208
val oldHead = table(bucket)
209209

210-
def add() {
210+
def add() = {
211211
table(bucket) = new Entry(elem, hash, oldHead, queue)
212212
count += 1
213213
if (count > threshhold) resize()
@@ -228,7 +228,7 @@ final class WeakHashSet[A >: Null <: AnyRef](val initialCapacity: Int, val loadF
228228
def +=(elem: A) = this + elem
229229

230230
// from scala.reflect.interanl.Set
231-
override def addEntry(x: A) { this += x }
231+
override def addEntry(x: A) = { this += x }
232232

233233
// remove an element from this set and return this set
234234
override def -(elem: A): this.type = elem match {

compiler/src/dotty/tools/io/Statistics.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ object Statistics {
77
type TimerSnapshot = (Long, Long)
88

99
/** If enabled, increment counter by one */
10-
@inline final def incCounter(c: Counter) {
10+
@inline final def incCounter(c: Counter) = {
1111
if (_enabled && c != null) c.value += 1
1212
}
1313

1414
/** If enabled, increment counter by given delta */
15-
@inline final def incCounter(c: Counter, delta: Int) {
15+
@inline final def incCounter(c: Counter, delta: Int) = {
1616
if (_enabled && c != null) c.value += delta
1717
}
1818

@@ -27,7 +27,7 @@ object Statistics {
2727
if (_enabled && sc != null) sc.start() else null
2828

2929
/** If enabled, stop subcounter from tracking its base counter. */
30-
@inline final def stopCounter(sc: SubCounter, start: (Int, Int)) {
30+
@inline final def stopCounter(sc: SubCounter, start: (Int, Int)) = {
3131
if (_enabled && sc != null) sc.stop(start)
3232
}
3333

@@ -36,7 +36,7 @@ object Statistics {
3636
if (_enabled && tm != null) tm.start() else null
3737

3838
/** If enabled, stop timer */
39-
@inline final def stopTimer(tm: Timer, start: TimerSnapshot) {
39+
@inline final def stopTimer(tm: Timer, start: TimerSnapshot) = {
4040
if (_enabled && tm != null) tm.stop(start)
4141
}
4242

@@ -45,7 +45,7 @@ object Statistics {
4545
if (_enabled && timers != null) timers.push(timer) else null
4646

4747
/** If enabled, stop and pop timer from timer stack */
48-
@inline final def popTimer(timers: TimerStack, prev: TimerSnapshot) {
48+
@inline final def popTimer(timers: TimerStack, prev: TimerSnapshot) = {
4949
if (_enabled && timers != null) timers.pop(prev)
5050
}
5151

@@ -156,7 +156,7 @@ quant)
156156

157157
class SubCounter(prefix: String, override val underlying: Counter) extends Counter(prefix, underlying.phases) with SubQuantity {
158158
def start() = (value, underlying.value)
159-
def stop(prev: (Int, Int)) {
159+
def stop(prev: (Int, Int)) = {
160160
val (value0, uvalue0) = prev
161161
value = value0 + underlying.value - uvalue0
162162
}
@@ -170,7 +170,7 @@ quant)
170170
def start() = {
171171
(nanos, System.nanoTime())
172172
}
173-
def stop(prev: TimerSnapshot) {
173+
def stop(prev: TimerSnapshot) = {
174174
val (nanos0, start) = prev
175175
nanos = nanos0 + System.nanoTime() - start
176176
timings += 1
@@ -209,7 +209,7 @@ quant)
209209
elem
210210
}
211211
override def toString =
212-
this.toSeq.sortWith(_._2 > _._2).map {
212+
this.toSeq.map {
213213
case (cls: Class[_], elem) =>
214214
s"${cls.toString.substring(cls.toString.lastIndexOf("$") + 1)}: $elem"
215215
case (key, elem) =>

compiler/src/dotty/tools/io/Streamable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object Streamable {
5454
lazy val in = bufferedInput()
5555
var offset = 0
5656

57-
def loop() {
57+
def loop(): Unit = {
5858
if (offset < len) {
5959
val read = in.read(arr, offset, len - offset)
6060
if (read >= 0) {

compiler/src/dotty/tools/io/VirtualDirectory.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ extends AbstractFile {
3333
override def output = sys.error("directories cannot be written")
3434

3535
/** Does this abstract file denote an existing file? */
36-
def create() { unsupported() }
36+
def create() = { unsupported() }
3737

3838
/** Delete the underlying file or directory (recursively). */
39-
def delete() { unsupported() }
39+
def delete() = { unsupported() }
4040

4141
/** Returns an abstract file with the given name. It does not
4242
* check that it exists.
@@ -66,7 +66,7 @@ extends AbstractFile {
6666
dir
6767
}
6868

69-
def clear() {
69+
def clear() = {
7070
files.clear()
7171
}
7272
}

compiler/src/dotty/tools/io/VirtualFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
4343

4444
override def output: OutputStream = {
4545
new ByteArrayOutputStream() {
46-
override def close() {
46+
override def close() = {
4747
super.close()
4848
content = toByteArray()
4949
}

compiler/src/dotty/tools/io/ZipArchive.scala

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ final class FileZipArchive(file: JFile) extends ZipArchive(file) {
153153
val root = new DirEntry("/")
154154
val dirs = mutable.HashMap[String, DirEntry]("/" -> root)
155155
val zipFile = openZipFile()
156-
val enum = zipFile.entries()
156+
val entries = zipFile.entries()
157157

158158
try {
159-
while (enum.hasMoreElements) {
160-
val zipEntry = enum.nextElement
159+
while (entries.hasMoreElements) {
160+
val zipEntry = entries.nextElement
161161
val dir = getDir(dirs, zipEntry)
162162
if (zipEntry.isDirectory) dir
163163
else {
@@ -195,74 +195,6 @@ final class FileZipArchive(file: JFile) extends ZipArchive(file) {
195195
case _ => false
196196
}
197197
}
198-
///** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
199-
//final class URLZipArchive(val url: URL) extends ZipArchive(null) {
200-
// def iterator: Iterator[Entry] = {
201-
// val root = new DirEntry("/")
202-
// val dirs = mutable.HashMap[String, DirEntry]("/" -> root)
203-
// val in = new ZipInputStream(new ByteArrayInputStream(Streamable.bytes(input)))
204-
//
205-
// @tailrec def loop() {
206-
// val zipEntry = in.getNextEntry()
207-
// class EmptyFileEntry() extends Entry(zipEntry.getName) {
208-
// override def toByteArray: Array[Byte] = null
209-
// override def sizeOption = Some(0)
210-
// }
211-
// class FileEntry() extends Entry(zipEntry.getName) {
212-
// override val toByteArray: Array[Byte] = {
213-
// val len = zipEntry.getSize().toInt
214-
// val arr = if (len == 0) Array.emptyByteArray else new Array[Byte](len)
215-
// var offset = 0
216-
//
217-
// def loop() {
218-
// if (offset < len) {
219-
// val read = in.read(arr, offset, len - offset)
220-
// if (read >= 0) {
221-
// offset += read
222-
// loop()
223-
// }
224-
// }
225-
// }
226-
// loop()
227-
//
228-
// if (offset == arr.length) arr
229-
// else throw new IOException("Input stream truncated: read %d of %d bytes".format(offset, len))
230-
// }
231-
// override def sizeOption = Some(zipEntry.getSize().toInt)
232-
// }
233-
//
234-
// if (zipEntry != null) {
235-
// val dir = getDir(dirs, zipEntry)
236-
// if (zipEntry.isDirectory)
237-
// dir
238-
// else {
239-
// val f = if (zipEntry.getSize() == 0) new EmptyFileEntry() else new FileEntry()
240-
// dir.entries(f.name) = f
241-
// }
242-
// in.closeEntry()
243-
// loop()
244-
// }
245-
// }
246-
//
247-
// loop()
248-
// try root.iterator
249-
// finally dirs.clear()
250-
// }
251-
//
252-
// def name = url.getFile()
253-
// def path = url.getPath()
254-
// def input = url.openStream()
255-
// def lastModified =
256-
// try url.openConnection().getLastModified()
257-
// catch { case _: IOException => 0 }
258-
//
259-
// override def canEqual(other: Any) = other.isInstanceOf[URLZipArchive]
260-
// override def hashCode() = url.hashCode
261-
// override def equals(that: Any) = that match {
262-
// case x: URLZipArchive => url == x.url
263-
// case _ => false
264-
// }
265-
//}
266198

267199
final class ManifestResources(val url: URL) extends ZipArchive(null) {
268200
def iterator = {
@@ -274,12 +206,11 @@ final class ManifestResources(val url: URL) extends ZipArchive(null) {
274206
for (zipEntry <- iter) {
275207
val dir = getDir(dirs, zipEntry)
276208
if (!zipEntry.isDirectory) {
277-
class FileEntry() extends Entry(zipEntry.getName) {
209+
val f = new Entry(zipEntry.getName) {
278210
override def lastModified = zipEntry.getTime()
279211
override def input = resourceInputStream(path)
280212
override def sizeOption = None
281213
}
282-
val f = new FileEntry()
283214
dir.entries(f.name) = f
284215
}
285216
}

0 commit comments

Comments
 (0)