Skip to content

Instantly share code, notes, and snippets.

@seraphr seraphr/macro memo
Created Nov 28, 2016

Embed
What would you like to do?
import scala.language.experimental.macros
import scala.reflect.macros.whitebox.Context
/**
*/
object MethodsMacro {
def apply[T]: Seq[String] = macro genMethods[T]
def genMethods[T: c.WeakTypeTag](c: Context): c.Tree = {
import c.universe._
val tType = implicitly[WeakTypeTag[T]].tpe
val tTypes = tType.members.map(_.name.toString)
q"Seq(..${tTypes})"
}
}
object CompanionMethods {
def apply[T]: Seq[String] = macro genMethods[T]
def genMethods[T: c.WeakTypeTag](c: Context): c.Tree = {
import c.universe._
val tType = implicitly[WeakTypeTag[T]].tpe.dealias
val tCompanion = tType.companion
println(tType)
println(tCompanion)
val tTypes = tCompanion.members.map(_.name.toString)
q"Seq(..${tTypes})"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.