Skip to content

Instantly share code, notes, and snippets.

@xeno-by
Created September 21, 2012 10:09
Show Gist options
  • Save xeno-by/3760748 to your computer and use it in GitHub Desktop.
Save xeno-by/3760748 to your computer and use it in GitHub Desktop.
Mines static state declared in reflective universes
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")
}
@xeno-by
Copy link
Author

xeno-by commented Sep 21, 2012

@xeno-by
Copy link
Author

xeno-by commented Sep 21, 2012

test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment