Created
September 21, 2012 10:09
-
-
Save xeno-by/3760748 to your computer and use it in GitHub Desktop.
Mines static state declared in reflective universes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.reflect.runtime.universe._ | |
object Test extends App { | |
def investigate(pkg: String) = { | |
def basesOf(sym: ClassSymbol): List[ClassSymbol] = { val bases = sym.baseClasses.map(_.asClass).filter(_.fullName.toString startsWith pkg); bases.head +: bases.tail.map(basesOf).flatten } | |
val bases = basesOf(typeOf[scala.reflect.runtime.SymbolTable].typeSymbol.asClass) | |
val decls = bases.map(_.typeSignature).flatMap(_.declarations.toList) | |
val state = decls.collect{case ts: TermSymbol => ts}.filter(sym => sym.isVal || sym.isVar || sym.isModule) | |
def suffix(sym: TermSymbol, name: String) = sym.name.toString.trim.endsWith(name) | |
def isa(sym: TermSymbol, name: String) = Some(sym).collect{case ms: ModuleSymbol if ms.companionSymbol != NoSymbol => ms.companionSymbol.asClass}.map(sym => basesOf(sym).exists(_.name.toString == name)).getOrElse(false) | |
val filtered = state.filter(sym => !suffix(sym, "Tag") && !suffix(sym, "Attachment") && !isa(sym, "Tree") && !isa(sym, "Type")) | |
val grouped = filtered.sortBy(sym => sym.name.toString).groupBy(sym => sym.owner.fullName.toString) | |
grouped.keys.toList.sorted foreach (k => { | |
println(s"\n${k}\n==============") | |
grouped(k) foreach println | |
}) | |
} | |
investigate("scala.reflect.internal") | |
investigate("scala.reflect.runtime") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results: https://gist.github.com/3760764