Skip to content

Commit 92a25cb

Browse files
committed
Remove PlainNioFile as it PlainFile is on nio now
1 parent 7ff1cb6 commit 92a25cb

File tree

3 files changed

+6
-79
lines changed

3 files changed

+6
-79
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*/
44
package dotty.tools.dotc.classpath
55

6-
import java.io.File
6+
import java.io.File // TODO rename to JFile for consistency
77
import java.net.{URI, URL}
88
import java.nio.file.{FileSystems, Files, SimpleFileVisitor}
99
import java.util.function.IntFunction
1010
import java.util
1111
import java.util.Comparator
1212

13-
import dotty.tools.io.{AbstractFile, PlainFile, ClassPath, ClassRepresentation, PlainNioFile}
13+
import dotty.tools.io.{AbstractFile, PlainFile, ClassPath, ClassRepresentation}
1414
import FileUtils._
1515
import scala.collection.JavaConverters._
1616

@@ -178,7 +178,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
178178
else {
179179
packageToModuleBases.getOrElse(inPackage, Nil).flatMap(x =>
180180
Files.list(x.resolve(inPackage.replace('.', '/'))).iterator().asScala.filter(_.getFileName.toString.endsWith(".class"))).map(x =>
181-
ClassFileEntryImpl(new PlainNioFile(x))).toVector
181+
ClassFileEntryImpl(new PlainFile(new dotty.tools.io.File(x)))).toVector
182182
}
183183
}
184184

@@ -197,7 +197,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
197197
val inPackage = packageOf(className)
198198
packageToModuleBases.getOrElse(inPackage, Nil).iterator.flatMap{x =>
199199
val file = x.resolve(className.replace('.', '/') + ".class")
200-
if (Files.exists(file)) new PlainNioFile(file) :: Nil else Nil
200+
if (Files.exists(file)) new PlainFile(new dotty.tools.io.File(file)) :: Nil else Nil
201201
}.take(1).toList.headOption
202202
}
203203
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
245245
val path = jpath.resolve(name)
246246
if (isDir) Files.createDirectory(path)
247247
else Files.createFile(path)
248-
new PlainNioFile(path)
248+
new PlainFile(new File(path))
249249
}
250250
}
251251

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

+1-74
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
5858
try {
5959
import scala.collection.JavaConverters._
6060
val it = Files.newDirectoryStream(jpath).iterator()
61-
it.asScala.map(new PlainNioFile(_))
61+
it.asScala.map(p => new PlainFile(Path(p)))
6262
} catch {
6363
case _: NotDirectoryException => Iterator.empty
6464
}
@@ -90,76 +90,3 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
9090
def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile =
9191
new PlainFile(givenPath / name)
9292
}
93-
94-
private[dotty] class PlainNioFile(nioPath: java.nio.file.Path) extends AbstractFile {
95-
96-
assert(nioPath ne null)
97-
98-
def jpath = nioPath
99-
100-
override def underlyingSource = Some(this)
101-
102-
private val fpath = nioPath.toAbsolutePath.toString
103-
104-
/** Returns the name of this abstract file. */
105-
def name = nioPath.getFileName.toString
106-
107-
/** Returns the path of this abstract file. */
108-
def path = nioPath.toString
109-
110-
/** The absolute file. */
111-
def absolute = new PlainNioFile(nioPath.toAbsolutePath)
112-
113-
override def container: AbstractFile = new PlainNioFile(nioPath.getParent)
114-
override def input = Files.newInputStream(nioPath)
115-
override def output = Files.newOutputStream(nioPath)
116-
override def sizeOption = Some(Files.size(nioPath).toInt)
117-
override def hashCode(): Int = fpath.hashCode()
118-
override def equals(that: Any): Boolean = that match {
119-
case x: PlainNioFile => fpath == x.fpath
120-
case _ => false
121-
}
122-
123-
/** Is this abstract file a directory? */
124-
def isDirectory: Boolean = Files.isDirectory(nioPath)
125-
126-
/** Returns the time that this abstract file was last modified. */
127-
def lastModified: Long = Files.getLastModifiedTime(nioPath).toMillis
128-
129-
/** Returns all abstract subfiles of this abstract directory. */
130-
def iterator: Iterator[AbstractFile] = {
131-
try {
132-
import scala.collection.JavaConverters._
133-
val it = Files.newDirectoryStream(nioPath).iterator()
134-
it.asScala.map(new PlainNioFile(_))
135-
} catch {
136-
case _: NotDirectoryException => Iterator.empty
137-
}
138-
}
139-
140-
/**
141-
* Returns the abstract file in this abstract directory with the
142-
* specified name. If there is no such file, returns null. The
143-
* argument "directory" tells whether to look for a directory or
144-
* or a regular file.
145-
*/
146-
def lookupName(name: String, directory: Boolean): AbstractFile = {
147-
val child = nioPath.resolve(name)
148-
if ((Files.isDirectory(child) && directory) || (Files.isRegularFile(child) && !directory)) new PlainNioFile(child)
149-
else null
150-
}
151-
152-
/** Does this abstract file denote an existing file? */
153-
def create(): Unit = if (!exists) Files.createFile(nioPath)
154-
155-
/** Delete the underlying file or directory (recursively). */
156-
def delete(): Unit =
157-
if (Files.isRegularFile(nioPath)) Files.deleteIfExists(nioPath)
158-
else if (Files.isDirectory(nioPath)) new Directory(nioPath).deleteRecursively()
159-
160-
/** Returns a plain file with the given name. It does not
161-
* check that it exists.
162-
*/
163-
def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile =
164-
new PlainNioFile(nioPath.resolve(name))
165-
}

0 commit comments

Comments
 (0)