在扩展AbstractProcessor
的注释处理器中,我有:
override fun process(annotations: MutableSet<out TypeElement>, roundEnv: RoundEnvironment): Boolean {
roundEnv.getElementsAnnotatedWith(FxBean::class.java)
.forEach {
val className = it.simpleName.toString()
val metaDataClass = Class.forName("kotlin.Metadata").asSubclass(Annotation::class.java)
val isKotlinClass = it.getAnnotation(metaDataClass) != null
if (isKotlinClass) {
// Trying to get the list of methods
// of the data class with the @FxBean annotation.
val methods = roundEnv.rootElements.find {
it.simpleName.toString() == className // This is never true
}?.let {
val methods = mutableListOf<ExecutableElement>()
it.enclosedElements.forEach {
if (it is ExecutableElement) {
methods.add(it)
}
}
methods
}
}
}
return true
}
我错过了什么?有没有办法让Element表示正在处理@FxBean
注释的数据类?
答案 0 :(得分:1)
根元素不能保证是带注释的元素,它们是根。注释处理根可以是单独的元素,带有注释注释,通过getSupportedAnnotationTypes()或类/包定向,包含这些元素的集合, - API指定得有些糟糕,因此根元素的确切性质是模糊的。 / p>
事实是,Kotlin和最新版本的Gradle可以包装注释处理器API并提供他们自己的RoundEnvironment
实现,这种情况更加复杂。这些实现可能不会以与javac默认值一致的方式运行。