Created
November 28, 2016 15:31
-
-
Save seraphr/b068dc57ea542a073d00376e93290085 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
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