@@ -17,49 +17,52 @@ object FileUtils {
17
17
extension (file : AbstractFile ) {
18
18
def isPackage : Boolean = file.isDirectory && mayBeValidPackage(file.name)
19
19
20
- def isClass : Boolean = ! file.isDirectory && hasClassExtension && ! file.name.endsWith(" $class.class" )
21
- // FIXME: drop last condition when we stop being compatible with Scala 2.11
20
+ def isClass : Boolean = ! file.isDirectory && hasClassExtension
22
21
23
- def hasClassExtension : Boolean = file.hasExtension( " class " )
22
+ def hasClassExtension : Boolean = file.ext.isClass
24
23
25
- def hasTastyExtension : Boolean = file.hasExtension( " tasty " )
24
+ def hasTastyExtension : Boolean = file.ext.isTasty
26
25
27
26
def isTasty : Boolean = ! file.isDirectory && hasTastyExtension
28
27
29
28
def isScalaBinary : Boolean = file.isClass || file.isTasty
30
29
31
- def isScalaOrJavaSource : Boolean = ! file.isDirectory && ( file.hasExtension( " scala " ) || file.hasExtension( " java " ))
30
+ def isScalaOrJavaSource : Boolean = ! file.isDirectory && file.ext.isScalaOrJava
32
31
33
32
// TODO do we need to check also other files using ZipMagicNumber like in scala.tools.nsc.io.Jar.isJarOrZip?
34
- def isJarOrZip : Boolean = file.hasExtension( " jar " ) || file.hasExtension( " zip " )
33
+ def isJarOrZip : Boolean = file.ext.isJarOrZip
35
34
36
35
/**
37
36
* Safe method returning a sequence containing one URL representing this file, when underlying file exists,
38
37
* and returning given default value in other case
39
38
*/
40
39
def toURLs (default : => Seq [URL ] = Seq .empty): Seq [URL ] = if (file.file == null ) default else Seq (file.toURL)
41
40
42
- /** Returns the tasty file associated with this class file */
43
- def classToTasty : Option [AbstractFile ] =
44
- assert(file.isClass, s " non-class: $file" )
45
- val tastyName = classNameToTasty(file.name)
46
- Option (file.resolveSibling(tastyName))
41
+ /**
42
+ * Returns if there is an existing sibling `.tasty` file.
43
+ */
44
+ def hasSiblingTasty : Boolean =
45
+ assert(file.hasClassExtension, s " non-class: $file" )
46
+ file.resolveSibling(classNameToTasty(file.name)) != null
47
47
}
48
48
49
49
extension (file : JFile ) {
50
50
def isPackage : Boolean = file.isDirectory && mayBeValidPackage(file.getName)
51
51
52
- def isClass : Boolean = file.isFile && file.getName.endsWith(SUFFIX_CLASS ) && ! file.getName.endsWith(" $class.class" )
53
- // FIXME: drop last condition when we stop being compatible with Scala 2.11
52
+ def isClass : Boolean = file.isFile && hasClassExtension
53
+
54
+ def hasClassExtension : Boolean = file.getName.endsWith(SUFFIX_CLASS )
54
55
55
56
def isTasty : Boolean = file.isFile && file.getName.endsWith(SUFFIX_TASTY )
56
57
57
- /** Returns the tasty file associated with this class file */
58
- def classToTasty : Option [JFile ] =
59
- assert(file.isClass, s " non-class: $file" )
60
- val tastyName = classNameToTasty(file.getName.stripSuffix(" .class" ))
61
- val tastyPath = file.toPath.resolveSibling(tastyName)
62
- if java.nio.file.Files .exists(tastyPath) then Some (tastyPath.toFile) else None
58
+ /**
59
+ * Returns if there is an existing sibling `.tasty` file.
60
+ */
61
+ def hasSiblingTasty : Boolean =
62
+ assert(file.hasClassExtension, s " non-class: $file" )
63
+ val path = file.toPath
64
+ val tastyPath = path.resolveSibling(classNameToTasty(file.getName))
65
+ java.nio.file.Files .exists(tastyPath)
63
66
64
67
}
65
68
0 commit comments