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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import scala.tools.nsc._
import io.{ AbstractFile }
import util.{ SourceFile, BatchSourceFile, stringFromStream }
import scala.tools.nsc.reporters.ConsoleReporter
object Test {
val src: SourceFile = new BatchSourceFile("src", """
package foo.bar
class Bippy {
type BippyType <: {
def showdefTestMemberType1: Unit
}
def showdefTestMemberClass1 = 5
class Boppity {
def showdefTestMemberClass2 = 5
class Boo {
def showdefTestMemberClass3 = 5
}
object Boo {
def showdefTestMemberObject1 = "abc"
}
}
}
object Bippy {
type BippyType <: {
def showdefTestMemberType2: Unit
}
def showdefTestMemberObject2 = "abc"
}
""")
def mkCompiler(args: String*) = {
val settings = new Settings()
val command = new CompilerCommand("-usejavacp" :: args.toList, settings)
new Global(settings)
}
def slurp(body: => Unit): String = stringFromStream { stream =>
Console.withOut(stream) {
Console.withErr(stream) {
body
}
}
}
def lines(args: String*): List[String] = {
val output = slurp {
val compiler = mkCompiler(args: _*)
val run = new compiler.Run()
run.compileSources(List(src))
}
output split "\\n" toList
}
def showClass(name: String) = lines("-Yshow:typer", "-Xshow-class", name)
def showObject(name: String) = lines("-Yshow:typer", "-Xshow-object", name)
def show(xs: List[String]) = {
xs filter (x => (x contains "def showdefTestMember") || (x startsWith "<<-- ")) foreach println
}
def main(args: Array[String]) {
show(List("Bippy", "Bippy#BippyType", "Bippy.BippyType", "Bippy#Boppity", "Bippy#Boppity#Boo") flatMap showClass)
show(List("Bippy", "Bippy#Boppity#Boo") flatMap showObject)
}
}
|