Skip to content

Commit 78dcb5f

Browse files
committed
cleanup
1 parent 6bb96a1 commit 78dcb5f

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,24 +275,16 @@ final class CtSymClassPath(ctSym: java.nio.file.Path, release: Int) extends Clas
275275

276276
case class DirectoryClassPath(dir: JFile) extends JFileDirectoryLookup[BinaryFileEntry] with NoSourcePaths {
277277
override def findClass(className: String): Option[ClassRepresentation] =
278-
val classfile = findClassFile(className)
279-
findTastyFile(className) match
280-
case Some(file) =>
281-
Some(if classfile.isDefined then TastyFileEntry(file) else StandaloneTastyFileEntry(file))
282-
case None => classfile.map(ClassFileEntry(_))
278+
findClassFile(className).map(BinaryFileEntry(_))
283279

284280
def findClassFile(className: String): Option[AbstractFile] = {
285-
val relativePath = FileUtils.dirPath(className)
286-
val classFile = new JFile(dir, relativePath + ".class")
287-
if classFile.exists then Some(classFile.toPath.toPlainFile)
288-
else None
289-
}
290-
291-
private def findTastyFile(className: String): Option[AbstractFile] = {
292281
val relativePath = FileUtils.dirPath(className)
293282
val tastyFile = new JFile(dir, relativePath + ".tasty")
294283
if tastyFile.exists then Some(tastyFile.toPath.toPlainFile)
295-
else None
284+
else
285+
val classFile = new JFile(dir, relativePath + ".class")
286+
if classFile.exists then Some(classFile.toPath.toPlainFile)
287+
else None
296288
}
297289

298290
protected def createFileEntry(file: AbstractFile): BinaryFileEntry = BinaryFileEntry(file)
@@ -309,7 +301,7 @@ case class DirectorySourcePath(dir: JFile) extends JFileDirectoryLookup[SourceFi
309301
protected def createFileEntry(file: AbstractFile): SourceFileEntry = SourceFileEntry(file)
310302
protected def isMatchingFile(f: JFile): Boolean = endsScalaOrJava(f.getName)
311303

312-
override def findClass(className: String): Option[ClassRepresentation] = findSourceFile(className) map SourceFileEntry.apply
304+
override def findClass(className: String): Option[ClassRepresentation] = findSourceFile(className).map(SourceFileEntry(_))
313305

314306
private def findSourceFile(className: String): Option[AbstractFile] = {
315307
val relativePath = FileUtils.dirPath(className)

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,15 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
3939
def asClassPathStrings: Seq[String] = Seq(dir.path)
4040

4141
override def findClass(className: String): Option[ClassRepresentation] =
42-
val pathSeq = FileUtils.dirPath(className).split(java.io.File.separator)
43-
val parentDir = lookupPath(dir)(pathSeq.init.toSeq, directory = true)
44-
if parentDir == null then return None
45-
else
46-
val classfile = lookupPath(parentDir)(pathSeq.last + ".class" :: Nil, directory = false)
47-
val tasty = lookupPath(parentDir)(pathSeq.last + ".tasty" :: Nil, directory = false)
48-
if tasty != null then
49-
if classfile != null then Some(TastyFileEntry(tasty))
50-
else Some(StandaloneTastyFileEntry(tasty))
51-
else
52-
if classfile != null then Some(ClassFileEntry(classfile))
53-
else None
42+
findClassFile(className).map(BinaryFileEntry(_))
5443

5544
def findClassFile(className: String): Option[AbstractFile] = {
5645
val pathSeq = FileUtils.dirPath(className).split(java.io.File.separator)
5746
val parentDir = lookupPath(dir)(pathSeq.init.toSeq, directory = true)
5847
if parentDir == null then return None
59-
else Option(lookupPath(parentDir)(pathSeq.last + ".class" :: Nil, directory = false))
48+
else
49+
Option(lookupPath(parentDir)(pathSeq.last + ".tasty" :: Nil, directory = false))
50+
.orElse(Option(lookupPath(parentDir)(pathSeq.last + ".class" :: Nil, directory = false)))
6051
}
6152

6253
private[dotty] def classes(inPackage: PackageName): Seq[BinaryFileEntry] = files(inPackage)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ object ZipAndJarClassPathFactory extends ZipAndJarFileLookupFactory {
5151
override def findClass(className: String): Option[BinaryFileEntry] = {
5252
val (pkg, simpleClassName) = PackageNameUtils.separatePkgAndClassNames(className)
5353
val binaries = files(PackageName(pkg), simpleClassName + ".tasty", simpleClassName + ".class")
54-
binaries.find(_.binary.isDefined)
54+
binaries.find(_.file.isTasty).orElse(binaries.find(_.file.isClass))
5555
}
5656

5757
override private[dotty] def classes(inPackage: PackageName): Seq[BinaryFileEntry] = files(inPackage)

0 commit comments

Comments
 (0)