Created
July 1, 2015 05:16
-
-
Save infomaven/b47d142655943fb709a3 to your computer and use it in GitHub Desktop.
This file contains 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
object Settings { | |
final val Host = "host" | |
final val Protocol = "protocol" | |
object User { | |
final val Name = "username" | |
final val Password = "password" | |
} | |
object Subject { | |
final val Query = "query" | |
final val Predicate = "predicate" | |
} | |
} | |
//================================ | |
def deepMembers[A: scala.reflect.runtime.universe.TypeTag](a: A) = { | |
import scala.reflect.runtime.universe._ | |
def members(s: Symbol): Map[String, String] = | |
s.typeSignature.declarations.collect { | |
case m: ModuleSymbol => members(m) | |
case m: MethodSymbol if m.isAccessor => m.returnType match { | |
case ConstantType(Constant(s: String)) => Map(m.name.decoded -> s) | |
case _ => Map.empty[String, String] | |
} | |
}.foldLeft(Map.empty[String, String])(_ ++ _) | |
members(typeOf[A].termSymbol) | |
} | |
scala> deepMembers( Settings ) foreach println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment