I am trying to migrate a piece of scala.reflect code to Scala 3.
Given
sealed trait MyReader
object ReaderA extends MyReader
object ReaderB extends MyReader
How do I write a macro (or inline def?)
inline def findSubclassModulesOfSealedTrait[T]: List[T] = ???
// caller code
val mods = findSubclassModulesOfSealedTrait[MyReader]
// mods = List(ReaderA, ReaderB)
I get to the point where I have a List of all the Symbols and am completely at a loss here:
import scala.quoted.*
object FindClassesMacro {
def findDirectSubModulesImpl[T](using
quotes: Quotes,
t: Type[T]
): Expr[Set[T]] = {
import quotes.reflect.*
val tpeSym = TypeTree.of[T].symbol
val children: List[Symbol] = tpeSym.children
val nonModules = children.filterNot(_.flags.is(Flags.Module))
val modules = children.filter(_.flags.is(Flags.Module))
// TODO
'{Set.empty}
I have the feeling that this is super simple and that I am missing something trivial, any hints or examples to get me started are highly appreciated.