Skip to content

Commit 795218f

Browse files
committed
Add FileUtil.isScalaBinary
1 parent c4f2a8d commit 795218f

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ object FileUtils {
2222

2323
def isTasty: Boolean = !file.isDirectory && file.hasExtension("tasty")
2424

25+
def isScalaBinary: Boolean = file.isClass || file.isTasty
26+
2527
def isScalaOrJavaSource: Boolean = !file.isDirectory && (file.hasExtension("scala") || file.hasExtension("java"))
2628

2729
// TODO do we need to check also other files using ZipMagicNumber like in scala.tools.nsc.io.Jar.isJarOrZip?

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import io.AbstractFile
3131
import util.{SourceFile, NoSource, Property, SourcePosition, SrcPos, EqHashMap}
3232
import scala.annotation.internal.sharable
3333
import config.Printers.typr
34+
import dotty.tools.dotc.classpath.FileUtils.isScalaBinary
3435

3536
object Symbols {
3637

@@ -150,8 +151,7 @@ object Symbols {
150151
* symbols defined by the user in a prior run of the REPL, that are still valid.
151152
*/
152153
final def isDefinedInSource(using Context): Boolean =
153-
span.exists && isValidInCurrentRun
154-
&& associatedFileMatches(file => file.extension != "class" && file.extension != "tasty")
154+
span.exists && isValidInCurrentRun && associatedFileMatches(!_.isScalaBinary)
155155

156156
/** Is symbol valid in current run? */
157157
final def isValidInCurrentRun(using Context): Boolean =
@@ -272,7 +272,7 @@ object Symbols {
272272
/** The class file from which this class was generated, null if not applicable. */
273273
final def binaryFile(using Context): AbstractFile | Null = {
274274
val file = associatedFile
275-
if file != null && (file.extension == "class" || file.extension == "tasty") then file else null
275+
if file != null && file.isScalaBinary then file else null
276276
}
277277

278278
/** A trap to avoid calling x.symbol on something that is already a symbol.
@@ -285,7 +285,7 @@ object Symbols {
285285

286286
final def source(using Context): SourceFile = {
287287
def valid(src: SourceFile): SourceFile =
288-
if (src.exists && src.file.extension != "class" && src.file.extension != "tasty") src
288+
if (src.exists && !src.file.isScalaBinary) src
289289
else NoSource
290290

291291
if (!denot.exists) NoSource
@@ -463,7 +463,7 @@ object Symbols {
463463
if !mySource.exists && !denot.is(Package) then
464464
// this allows sources to be added in annotations after `sourceOfClass` is first called
465465
val file = associatedFile
466-
if file != null && file.extension != "class" && file.extension != "tasty" then
466+
if file != null && !file.isScalaBinary then
467467
mySource = ctx.getSource(file)
468468
else
469469
mySource = defn.patchSource(this)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.io.File
77
import java.util.{Arrays, EnumSet}
88

99
import dotty.tools.dotc.ast.tpd
10+
import dotty.tools.dotc.classpath.FileUtils.{isTasty, isClass}
1011
import dotty.tools.dotc.core.Contexts._
1112
import dotty.tools.dotc.core.Decorators._
1213
import dotty.tools.dotc.core.Flags._
@@ -141,10 +142,10 @@ class ExtractDependencies extends Phase {
141142
if (depFile != null) {
142143
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
143144
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
144-
if (depFile.extension == "class") {
145+
if (depFile.isClass) {
145146
// Dependency is external -- source is undefined
146147
processExternalDependency(depFile, dep.to.binaryClassName)
147-
} else if (depFile.extension == "tasty") {
148+
} else if (depFile.isTasty) {
148149
val depClassFile = depFile.resolveSibling(dep.to.binaryClassName + ".class")
149150
if depClassFile != null then
150151
processExternalDependency(depClassFile, dep.to.binaryClassName)

0 commit comments

Comments
 (0)