在使用 kapt/kotlinpoet 在 Android Studio 中构建 AbstractProcessor 时。当我尝试使用可重复注释标记时,它会停止从 roundEnv.getElementsAnnotatedWith(AnnotationName::class.java) 获取数据,如果从注释中删除可重复标记,我可以获取带注释的类信息
将尝试使用其他反思方式
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
@Repeatable // <-- issue
annotation class ConfigurableGroup(
val key: String,
val text: String
)
// the processor abbreviated
@AutoService(Processor::class)
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedOptions(AnnotationProcessorNew.
KAPT_KOTLIN_GENERATED_OPTION_NAME)
class AnnotationProcessorNew : AbstractProcessor(){
override fun process(annotations: MutableSet<out TypeElement>, roundEnv:
RoundEnvironment): Boolean {
return generateConfigurables(roundEnv)
}
override fun getSupportedAnnotationTypes(): MutableSet<String> {
return mutableSetOf(
ConfigurableGroup::class.java.name
}
roundEnv.getElementsAnnotatedWith(ConfigurableGroup::class.java)
.filter { it.kind == ElementKind.CLASS }
.forEach { classElement ->
val classPackageName =
processingEnv.elementUtils.getPackageOf(classElement).toString()
val classSimpleName = classElement.simpleName.toString()
当注释是否具有@repeatable 标记时,我希望两次都从反射中获取数据。