Skip to content

Commit a914812

Browse files
committed
Fixes and more translations
1 parent 31e7255 commit a914812

10 files changed

+53
-52
lines changed

.drone.yml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pipeline:
1313
image: lampepfl/dotty:2017-10-20
1414
commands:
1515
- cp -R . /tmp/1/ && cd /tmp/1/
16-
- ./project/scripts/sbt compile # to ensure that side projects (such as dotty doc) compile
1716
- ./project/scripts/sbt testAll
1817
- ./project/scripts/sbt ";dotty-bench/jmh:run 1 1 tests/run/arrays.scala"
1918

compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ trait ZipArchiveFileLookup[FileEntryType <: ClassRepresentation] extends ClassPa
2323
override def asURLs: Seq[URL] = Seq(zipFile.toURI.toURL)
2424
override def asClassPathStrings: Seq[String] = Seq(zipFile.getPath)
2525

26-
private val archive = new FileZipArchive(zipFile)
26+
private val archive = new FileZipArchive(zipFile.toPath)
2727

2828
override private[dotty] def packages(inPackage: String): Seq[PackageEntry] = {
2929
val prefix = PackageNameUtils.packagePrefix(inPackage)

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ class ExtractAPI extends Phase {
4545
val dumpInc = ctx.settings.YdumpSbtInc.value
4646
val forceRun = dumpInc || ctx.settings.YforceSbtPhases.value
4747
if ((ctx.sbtCallback != null || forceRun) && !unit.isJava) {
48-
val sourceFile = unit.source.file.file
48+
val sourceFile = unit.source.file
4949
val apiTraverser = new ExtractAPICollector
5050
val source = apiTraverser.apiSource(unit.tpdTree)
5151

5252
if (dumpInc) {
5353
// Append to existing file that should have been created by ExtractDependencies
54-
val pw = new PrintWriter(Path(sourceFile).changeExtension("inc").toFile
54+
val pw = new PrintWriter(Path(sourceFile.jpath).changeExtension("inc").toFile
5555
.bufferedWriter(append = true), true)
5656
try {
5757
pw.println(DefaultShowAPI(source))
5858
} finally pw.close()
5959
}
6060

6161
if (ctx.sbtCallback != null)
62-
ctx.sbtCallback.api(sourceFile, source)
62+
ctx.sbtCallback.api(sourceFile.file, source)
6363
}
6464
}
6565
}

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ExtractDependencies extends Phase {
4747
val dumpInc = ctx.settings.YdumpSbtInc.value
4848
val forceRun = dumpInc || ctx.settings.YforceSbtPhases.value
4949
if ((ctx.sbtCallback != null || forceRun) && !unit.isJava) {
50-
val sourceFile = unit.source.file.file
50+
val sourceFile = unit.source.file
5151
val extractDeps = new ExtractDependenciesCollector
5252
extractDeps.traverse(unit.tpdTree)
5353

@@ -59,7 +59,7 @@ class ExtractDependencies extends Phase {
5959
Arrays.sort(deps)
6060
Arrays.sort(inhDeps)
6161

62-
val pw = Path(sourceFile).changeExtension("inc").toFile.printWriter()
62+
val pw = Path(sourceFile.jpath).changeExtension("inc").toFile.printWriter()
6363
try {
6464
pw.println(s"// usedNames: ${names.mkString(",")}")
6565
pw.println(s"// topLevelDependencies: ${deps.mkString(",")}")
@@ -69,11 +69,11 @@ class ExtractDependencies extends Phase {
6969

7070
if (ctx.sbtCallback != null) {
7171
extractDeps.usedNames.foreach(name =>
72-
ctx.sbtCallback.usedName(sourceFile, name.toString))
72+
ctx.sbtCallback.usedName(sourceFile.file, name.toString))
7373
extractDeps.topLevelDependencies.foreach(dep =>
74-
recordDependency(sourceFile, dep, DependencyContext.DependencyByMemberRef))
74+
recordDependency(sourceFile.file, dep, DependencyContext.DependencyByMemberRef))
7575
extractDeps.topLevelInheritanceDependencies.foreach(dep =>
76-
recordDependency(sourceFile, dep, DependencyContext.DependencyByInheritance))
76+
recordDependency(sourceFile.file, dep, DependencyContext.DependencyByInheritance))
7777
}
7878
}
7979
}

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
9595
def path: String
9696

9797
/** Returns the path of this abstract file in a canonical form. */
98-
def canonicalPath: String = if (jpath == null) path else jpath.toFile.getCanonicalPath
98+
def canonicalPath: String = if (jpath == null) path else jpath.normalize.toString
9999

100100
/** Checks extension case insensitively. */
101101
def hasExtension(other: String) = extension == other.toLowerCase
@@ -241,13 +241,10 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
241241
val lookup = lookupName(name, isDir)
242242
if (lookup != null) lookup
243243
else {
244+
Files.createDirectories(jpath)
244245
val path = jpath.resolve(name)
245-
try {
246-
if (isDir) Files.createDirectories(path)
247-
else Files.createFile(path)
248-
} catch {
249-
case _: FileAlreadyExistsException =>
250-
}
246+
if (isDir) Files.createDirectory(path)
247+
else Files.createFile(path)
251248
new PlainNioFile(path)
252249
}
253250
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
package dotty.tools.io
1010

11+
import java.nio.file.Files
12+
import java.util.stream.Collectors
13+
14+
import scala.collection.JavaConverters._
15+
1116
/**
1217
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
1318
*/
@@ -18,6 +23,7 @@ object Directory {
1823
def Current: Option[Directory] = if (userDir == "") None else normalizePath(userDir)
1924

2025
def apply(path: Path): Directory = path.toDirectory
26+
def apply(jpath: JPath): Directory = new Directory(jpath)
2127

2228
// Like File.makeTemp but creates a directory instead
2329
def makeTemp(prefix: String = Path.randomPrefix, suffix: String = null, dir: JFile = null): Directory = {
@@ -43,10 +49,7 @@ class Directory(jpath: JPath) extends Path(jpath) {
4349
/** An iterator over the contents of this directory.
4450
*/
4551
def list: Iterator[Path] =
46-
jfile.listFiles match {
47-
case null => Iterator.empty
48-
case xs => xs.iterator map Path.apply
49-
}
52+
Files.list(jpath).toArray[JPath](n => new Array(n)).iterator.map(Path.apply)
5053

5154
def dirs: Iterator[Directory] = list collect { case x: Directory => x }
5255
def files: Iterator[File] = list collect { case x: File => x }

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class File(jpath: JPath)(implicit constructorCodec: Codec) extends Path(jpath) w
4646

4747
override def addExtension(ext: String): File = super.addExtension(ext).toFile
4848
override def toAbsolute: File = if (isAbsolute) this else super.toAbsolute.toFile
49-
override def toDirectory: Directory = new Directory(jfile.toPath)
49+
override def toDirectory: Directory = new Directory(jpath)
5050
override def toFile: File = this
5151
override def normalize: File = super.normalize.toFile
5252
override def length = super[Path].length

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package dotty.tools.io
77

88
import scala.language.implicitConversions
99
import java.io.RandomAccessFile
10-
import java.nio.file.{DirectoryNotEmptyException, FileAlreadyExistsException, Files, NoSuchFileException}
10+
import java.nio.file.{DirectoryNotEmptyException, FileAlreadyExistsException, Files, NoSuchFileException, Paths}
1111
import java.net.{URI, URL}
1212

1313
import scala.util.Random.alphanumeric
@@ -45,20 +45,20 @@ object Path {
4545

4646
// not certain these won't be problematic, but looks good so far
4747
implicit def string2path(s: String): Path = apply(s)
48-
implicit def jfile2path(jfile: JFile): Path = apply(jfile)
48+
implicit def jfile2path(jfile: JFile): Path = apply(jfile.toPath)
4949

5050
def onlyDirs(xs: Iterator[Path]): Iterator[Directory] = xs filter (_.isDirectory) map (_.toDirectory)
5151
def onlyDirs(xs: List[Path]): List[Directory] = xs filter (_.isDirectory) map (_.toDirectory)
5252
def onlyFiles(xs: Iterator[Path]): Iterator[File] = xs filter (_.isFile) map (_.toFile)
5353

54-
def roots: List[Path] = java.io.File.listRoots().toList map Path.apply
54+
def roots: List[Path] = java.io.File.listRoots().toList.map(r => Path.apply(r.toPath))
5555

56-
def apply(path: String): Path = apply(new JFile(path))
57-
def apply(jfile: JFile): Path = try {
58-
if (jfile.isFile) new File(jfile.toPath)
59-
else if (jfile.isDirectory) new Directory(jfile.toPath)
60-
else new Path(jfile.toPath)
61-
} catch { case ex: SecurityException => new Path(jfile.toPath) }
56+
def apply(path: String): Path = apply(Paths.get(path))
57+
def apply(jpath: JPath): Path = try {
58+
if (Files.isRegularFile(jpath)) new File(jpath)
59+
else if (Files.isDirectory(jpath)) new Directory(jpath)
60+
else new Path(jpath)
61+
} catch { case ex: SecurityException => new Path(jpath) }
6262

6363
/** Avoiding any shell/path issues by only using alphanumerics. */
6464
private[io] def randomPrefix = alphanumeric take 6 mkString ""
@@ -149,7 +149,7 @@ class Path private[io] (val jpath: JPath) {
149149
if (isAbsolute) toDirectory // it should be a root. BTW, don't need to worry about relative pathed root
150150
else Directory(".") // a dir under pwd
151151
case x =>
152-
Directory(x.toFile)
152+
Directory(x)
153153
}
154154
}
155155
def parents: List[Directory] = {
@@ -213,6 +213,7 @@ class Path private[io] (val jpath: JPath) {
213213
}
214214
def createFile(failIfExists: Boolean = false): File = {
215215
val res = tryCreate(Files.createFile(jpath))
216+
jfile.createNewFile()
216217
if (!res && failIfExists && exists) fail("File '%s' already exists." format name)
217218
else if (isFile) toFile
218219
else new File(jpath)
@@ -236,7 +237,7 @@ class Path private[io] (val jpath: JPath) {
236237
}
237238

238239
private def delete(path: JPath): Boolean =
239-
try { Files.delete(path); true } catch { case _: DirectoryNotEmptyException | _: NoSuchFileException => false }
240+
try { Files.deleteIfExists(path); true } catch { case _: DirectoryNotEmptyException => false }
240241

241242
def truncate() =
242243
isFile && {

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package dotty.tools
77
package io
88

9+
import java.nio.file.{Files, NotDirectoryException}
10+
911
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
1012
class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) {
1113
override def isDirectory = true
@@ -35,8 +37,8 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
3537
def absolute = new PlainFile(givenPath.toAbsolute)
3638

3739
override def container: AbstractFile = new PlainFile(givenPath.parent)
38-
override def input = givenPath.toFile.inputStream()
39-
override def output = givenPath.toFile.outputStream()
40+
override def input = Files.newInputStream(jpath)
41+
override def output = Files.newOutputStream(jpath)
4042
override def sizeOption = Some(givenPath.length.toInt)
4143

4244
override def hashCode(): Int = fpath.hashCode()
@@ -53,14 +55,13 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
5355

5456
/** Returns all abstract subfiles of this abstract directory. */
5557
def iterator: Iterator[AbstractFile] = {
56-
// Optimization: Assume that the file was not deleted and did not have permissions changed
57-
// between the call to `list` and the iteration. This saves a call to `exists`.
58-
def existsFast(path: Path) = path match {
59-
case (_: Directory | _: io.File) => true
60-
case _ => path.exists
58+
try {
59+
import scala.collection.JavaConverters._
60+
val it = Files.newDirectoryStream(jpath).iterator()
61+
it.asScala.map(new PlainNioFile(_))
62+
} catch {
63+
case _: NotDirectoryException => Iterator.empty
6164
}
62-
if (!isDirectory) Iterator.empty
63-
else givenPath.toDirectory.list filter existsFast map (new PlainFile(_))
6465
}
6566

6667
/**
@@ -91,7 +92,6 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
9192
}
9293

9394
private[dotty] class PlainNioFile(nioPath: java.nio.file.Path) extends AbstractFile {
94-
import java.nio.file._
9595

9696
assert(nioPath ne null)
9797

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package dotty.tools.io
77

88
import java.net.URL
99
import java.io.{ IOException, InputStream, ByteArrayInputStream, FilterInputStream }
10+
import java.nio.file.Files
1011
import java.util.zip.{ ZipEntry, ZipFile, ZipInputStream }
1112
import java.util.jar.Manifest
1213
import scala.collection.mutable
@@ -32,7 +33,7 @@ object ZipArchive {
3233
*/
3334
def fromFile(file: File): FileZipArchive = fromFile(file.jfile)
3435
def fromFile(file: JFile): FileZipArchive =
35-
try { new FileZipArchive(file) }
36+
try { new FileZipArchive(file.toPath) }
3637
catch { case _: IOException => null }
3738

3839
def fromManifestURL(url: URL): AbstractFile = new ManifestResources(url)
@@ -112,7 +113,7 @@ abstract class ZipArchive(override val jpath: JPath) extends AbstractFile with E
112113
}
113114
}
114115
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
115-
final class FileZipArchive(file: JFile) extends ZipArchive(file.toPath) {
116+
final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
116117
private[this] def openZipFile(): ZipFile = try {
117118
new ZipFile(file)
118119
} catch {
@@ -182,16 +183,16 @@ final class FileZipArchive(file: JFile) extends ZipArchive(file.toPath) {
182183

183184
def iterator: Iterator[Entry] = root.iterator
184185

185-
def name = file.getName
186-
def path = file.getPath
187-
def input = File(file).inputStream()
188-
def lastModified = file.lastModified
186+
def name = jpath.getFileName.toString
187+
def path = jpath.toString
188+
def input = Files.newInputStream(jpath)
189+
def lastModified = Files.getLastModifiedTime(jpath).toMillis
189190

190-
override def sizeOption = Some(file.length.toInt)
191+
override def sizeOption = Some(Files.size(jpath).toInt)
191192
override def canEqual(other: Any) = other.isInstanceOf[FileZipArchive]
192-
override def hashCode() = file.hashCode
193+
override def hashCode() = jpath.hashCode
193194
override def equals(that: Any) = that match {
194-
case x: FileZipArchive => file.getAbsoluteFile == x.file.getAbsoluteFile
195+
case x: FileZipArchive => jpath.toAbsolutePath == x.jpath.toAbsolutePath
195196
case _ => false
196197
}
197198
}

0 commit comments

Comments
 (0)