Skip to content

Commit c4f2a8d

Browse files
committed
Add AbstractFile.resolveSibling
1 parent abbd237 commit c4f2a8d

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ object FileUtils {
3636
/** Returns the tasty file associated with this class file */
3737
def classToTasty: Option[AbstractFile] =
3838
assert(file.isClass, s"non-class: $file")
39-
val parent = file match // TODO: simplify when #3552 is fixed
40-
case file: io.ZipArchive#Entry => file.parent
41-
case _ => file.container
4239
val tastyName = classNameToTasty(file.name)
43-
Option(parent.lookupName(tastyName, directory = false))
40+
Option(file.resolveSibling(tastyName))
4441
}
4542

4643
extension (file: JFile) {

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ class ExtractDependencies extends Phase {
145145
// Dependency is external -- source is undefined
146146
processExternalDependency(depFile, dep.to.binaryClassName)
147147
} else if (depFile.extension == "tasty") {
148-
val parent = depFile match // TODO: simplify when #3552 is fixed
149-
case depFile: io.ZipArchive#Entry => depFile.parent
150-
case _ => depFile.container
151-
val depClassFile = parent.lookupName(dep.to.binaryClassName + ".class", directory = false)
148+
val depClassFile = depFile.resolveSibling(dep.to.binaryClassName + ".class")
152149
if depClassFile != null then
153150
processExternalDependency(depClassFile, dep.to.binaryClassName)
154151
} else if (allowLocal || depFile.file != sourceFile) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
250250
file
251251
}
252252

253+
/** Returns the sibling abstract file in the parent of this abstract file or directory.
254+
* If there is no such file, returns `null`.
255+
*/
256+
def resolveSibling(name: String): AbstractFile =
257+
container.lookupName(name, directory = false)
258+
253259
private def fileOrSubdirectoryNamed(name: String, isDir: Boolean): AbstractFile =
254260
lookupName(name, isDir) match {
255261
case null =>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ abstract class ZipArchive(override val jpath: JPath, release: Option[String]) ex
7272
// have to keep this name for compat with sbt's compiler-interface
7373
def getArchive: ZipFile = null
7474
override def underlyingSource: Option[ZipArchive] = Some(self)
75+
override def resolveSibling(name: String): AbstractFile =
76+
parent.lookupName(name, directory = false)
7577
override def toString: String = self.path + "(" + path + ")"
7678
}
7779

0 commit comments

Comments
 (0)