简体   繁体   English

如何在注释处理器上获取 Java Class 的声明字段?

[英]How can I get the Declared Fields of a Java Class on an Annotation Processor?

Hi I am currently trying my hand at an AnnotationProcessor for Java.嗨,我目前正在尝试 Java 的 AnnotationProcessor。 The only problem I have now is how to get the Declared Fields for the class over which the annotation is placed.我现在唯一的问题是如何获取放置注释的 class 的声明字段。

Does anyone know how to get the fields?有谁知道如何获得这些领域?

Once you get the element, you loop over the enclosed elements and filter by element kind:获取元素后,循环封闭的元素并按元素类型过滤:

typeElement.getEnclosedElements().stream()
                .filter(e -> ElementKind.FIELD.equals(e.getKind()))
                .collect(Collectors.toList());

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

相关问题 Java注释 - 如何在处理器中获取属性和类 - Java annotation - how to get properties and class in processor 如何获取在Java注释处理器中应用了注释的类? - How to get class that annotation applied to in Java Annotation Processor? 如何从Java中的Annotation Processor获取项目的工作目录 - How can I get the working directory of a project from an Annotation Processor in Java 如何在 Java 11 的注释处理器中获取带注释的方法参数的名称 - How can I get the names of annotated method parameters in an Annotation Processor in Java 11 注释处理器 - 如何获取它正在处理的类 - Annotation Processor - How to get the Class it is processing 使用Annotation处理器获取annotatted类的声明字段 - getting declared field of annotatted class with Annotation processor 从注释处理器中的注释 Object 中获取 Class 字段 - Get Class fields from annotated Object in annotation processor 如何从注释处理器进程中的构造函数 Java 元素 object 获取参数。 使用 Kotlin 数据 Class - How do I get parameters from constructors Java Element object from Annotation Processor process. using Kotlin Data Class Java 注释处理器:如何从注释中提取 class 值 - Java Annotation Processor: how to extract class values from an annotation Java注释处理器将忽略父类中的注释 - Java annotation processor ignores annotation in parent class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM