forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileish.scala
53 lines (40 loc) · 1.93 KB
/
Fileish.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Inspired by the original Fileish,
// testing combinations of lazy and non-lazy vals for their treatment in constructors
package dotty.tools
package io
import java.io.InputStream
import java.util.jar.JarEntry
import language.postfixOps
/** A common interface for File-based things and Stream-based things.
* (In particular, io.File and JarEntry.)
*/
class Fileish(val path: Path, val input: () => InputStream) extends Streamable.Chars {
def inputStream() = input()
def parent = path.parent
def name = path.name
def isSourceFile = path.hasExtension("java", "scala")
private lazy val pkgLines = lines() collect { case x if x startsWith "package " => x stripPrefix "package" trim }
lazy val pkgFromPath = parent.path.replaceAll("""[/\\]""", ".")
lazy val pkgFromSource = pkgLines map (_ stripSuffix ";") mkString "."
override def toString = path.path
}
class Fileish2(val path: Path, val input: () => InputStream) extends Streamable.Chars {
def inputStream() = input()
def parent = path.parent
def name = path.name
def isSourceFile = path.hasExtension("java", "scala")
private val pkgLines = lines() collect { case x if x startsWith "package " => x stripPrefix "package" trim }
lazy val pkgFromPath = parent.path.replaceAll("""[/\\]""", ".")
lazy val pkgFromSource = pkgLines map (_ stripSuffix ";") mkString "."
override def toString = path.path
}
class Fileish3(val path: Path, val input: () => InputStream) extends Streamable.Chars {
def inputStream() = input()
def parent = path.parent
def name = path.name
def isSourceFile = path.hasExtension("java", "scala")
private val pkgLines = lines() collect { case x if x startsWith "package " => x stripPrefix "package" trim }
private val pkgFromPath = parent.path.replaceAll("""[/\\]""", ".")
private val pkgFromSource = pkgLines map (_ stripSuffix ";") mkString "."
override def toString = path.path
}