Skip to content

Commit dbd1db4

Browse files
committed
Migrate some code related to file
1 parent 3852f8d commit dbd1db4

10 files changed

+12
-20
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package dotty.tools
22

3-
import scala.language.unsafeNulls
4-
53
import scala.annotation.tailrec
64
import scala.io.Source
75
import scala.util.Try

compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
135135
new JarEntryWriter(jarFile, jarManifestMainClass, jarCompressionLevel)
136136
}
137137
else if (file.isVirtual) new VirtualFileWriter(file)
138-
else if (file.isDirectory) new DirEntryWriter(file.file.toPath)
138+
else if (file.isDirectory) new DirEntryWriter(file.file.nn.toPath)
139139
else throw new IllegalStateException(s"don't know how to handle an output of $file [${file.getClass}]")
140140
}
141141

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
package dotty.tools
55
package dotc.classpath
66

7-
import scala.language.unsafeNulls
8-
97
import java.net.URL
108
import scala.collection.mutable.ArrayBuffer
119
import scala.collection.immutable.ArraySeq

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ClassPathFactory {
8282
if (file.isJarOrZip)
8383
ZipAndJarSourcePathFactory.create(file)
8484
else if (file.isDirectory)
85-
new DirectorySourcePath(file.file)
85+
new DirectorySourcePath(file.file.nn)
8686
else
8787
sys.error(s"Unsupported sourcepath element: $file")
8888
}
@@ -94,7 +94,7 @@ object ClassPathFactory {
9494
if (file.isJarOrZip)
9595
ZipAndJarClassPathFactory.create(file)
9696
else if (file.isDirectory)
97-
new DirectoryClassPath(file.file)
97+
new DirectoryClassPath(file.file.nn)
9898
else
9999
sys.error(s"Unsupported classpath element: $file")
100100
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*/
44
package dotty.tools.dotc.classpath
55

6-
import scala.language.unsafeNulls
7-
86
import java.io.{File => JFile}
97
import java.net.{URI, URL}
108
import java.nio.file.{FileSystems, Files}
@@ -119,7 +117,7 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo
119117
protected def toAbstractFile(f: JFile): AbstractFile = f.toPath.toPlainFile
120118
protected def isPackage(f: JFile): Boolean = f.isPackage
121119

122-
assert(dir != null, "Directory file in DirectoryFileLookup cannot be null")
120+
assert(dir.asInstanceOf[JFile | Null] != null, "Directory file in DirectoryFileLookup cannot be null")
123121

124122
def asURLs: Seq[URL] = Seq(dir.toURI.toURL)
125123
def asClassPathStrings: Seq[String] = Seq(dir.getPath)
@@ -216,7 +214,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
216214
final class CtSymClassPath(ctSym: java.nio.file.Path, release: Int) extends ClassPath with NoSourcePaths {
217215
import java.nio.file.Path, java.nio.file.*
218216

219-
private val fileSystem: FileSystem = FileSystems.newFileSystem(ctSym, null: ClassLoader)
217+
private val fileSystem: FileSystem = FileSystems.newFileSystem(ctSym, null.asInstanceOf[ClassLoader])
220218
private val root: Path = fileSystem.getRootDirectories.iterator.next
221219
private val roots = Files.newDirectoryStream(root).iterator.asScala.toList
222220

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
package dotty.tools
55
package dotc.classpath
66

7-
import scala.language.unsafeNulls
8-
97
import java.io.{File => JFile, FileFilter}
108
import java.net.URL
119
import dotty.tools.io.AbstractFile

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
1111
type F = AbstractFile
1212

1313
// From AbstractFileClassLoader
14-
private final def lookupPath(base: AbstractFile)(pathParts: Seq[String], directory: Boolean): AbstractFile = {
15-
var file: AbstractFile = base
14+
private final def lookupPath(base: AbstractFile)(pathParts: Seq[String], directory: Boolean): AbstractFile | Null = {
15+
var file: AbstractFile | Null = base
1616
val dirParts = pathParts.init.iterator
1717
while (dirParts.hasNext) {
1818
val dirPart = dirParts.next

compiler/src/dotty/tools/dotc/coverage/Location.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ object Location:
4646
s"$packageName.$className",
4747
classType,
4848
methodName,
49-
source.file.absolute.jpath
49+
source.file.absolute.jpath.nn
5050
)

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class Pickler extends Phase {
413413
)
414414
if ctx.isBestEffort then
415415
val outpath =
416-
ctx.settings.outputDir.value.jpath.toAbsolutePath.normalize
416+
ctx.settings.outputDir.value.jpath.nn.toAbsolutePath.normalize
417417
.resolve("META-INF")
418418
.resolve("best-effort")
419419
Files.createDirectories(outpath)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
115115
def container : AbstractFile
116116

117117
/** Returns the underlying File if any and null otherwise. */
118-
def file: JFile = try {
118+
def file: JFile | Null = try {
119119
if (jpath == null) null
120120
else jpath.toFile
121121
} catch {
122122
case _: UnsupportedOperationException => null
123123
}
124124

125125
/** Returns the underlying Path if any and null otherwise. */
126-
def jpath: JPath
126+
def jpath: JPath | Null
127127

128128
/** An underlying source, if known. Mostly, a zip/jar file. */
129129
def underlyingSource: Option[AbstractFile] = None
@@ -201,7 +201,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
201201
/** Drill down through subdirs looking for the target, as in lookupName.
202202
* Ths target name is the last of parts.
203203
*/
204-
final def lookupPath(parts: Seq[String], directory: Boolean): AbstractFile =
204+
final def lookupPath(parts: Seq[String], directory: Boolean): AbstractFile | Null =
205205
var file: AbstractFile = this
206206
var i = 0
207207
val n = parts.length - 1

0 commit comments

Comments
 (0)