我正在制作一个注释处理器,参数中带有一个带有 KClass 的注释。我需要检查我在处理器中检索到的 KClasses 是否是数据类。
我无法使用
MyDataClass::class.isData
因为MirroredTypeException当您想要访问注释中的 Class 或 KClass 参数时会抛出
try {
element.getAnnotation(MyAnnotation::class.java).myClass
} catch (mte: MirroredTypeException) {
typeElement = typeUtils.asElement(mte.typeMirror) as TypeElement
}
现在我只能使用 TypeElement。
Kotlinpoet 提供KModifier了包含DATA属性,但它仅可用于类生成而不是读取。
我怎样才能有效地检查它?