简体   繁体   English

在宏中查找具有类型参数的直接已知子类

[英]Find direct known subclasses with type parameter in macro

In short, I need a macro that for a given sealed trait finds all subtypes.简而言之,我需要一个宏,它可以针对给定的密封特征找到所有子类型。

Suppose I have the following hierarchy:假设我有以下层次结构:

sealed trait T[A]
case class C[A]() extends T[A]

Now, in my macro, I have the WeakTypeTag for eg T[String] .现在,在我的宏中,我有WeakTypeTag ,例如T[String] Using .asClass.knownDirectSubclasses , I can find C[A] , but I don't see a good way to arrive at type C[String] .使用.asClass.knownDirectSubclasses ,我可以找到C[A] ,但我看不到获得类型C[String]的好方法。 I've experimented with .substituteTypes(..., ...) but without success.我已经尝试过.substituteTypes(..., ...)但没有成功。

I've figured it out.我已经想通了。

The answer is using appliedType(..., ...) included in import c.universe._ .答案是使用import c.universe._中包含的appliedType(..., ...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM