annotation-processing

JSR269 annotation processing getElementsAnnotatedWith() return all the annotated elements each loop and cannot distinguish it belongs to which type

為{幸葍}努か 提交于 2021-02-11 14:58:23
问题 Recently, I have been intersted with the JSR-269 annotation processing and I want to write a lib to eliminate some boilerplate code with it, such as json processing. I really generate the code, then, however, I encounter a fatal problem and spent a lot of time but could not slove it. The problem is, the RoundEnvironment.getElementsAnnotatedWith() method alway return all the elements annotated with the annotation, I cannot tistinguish which one comes from a specific class. Maybe the problem

Mapstruct AnnotationProcessor with IntelliJ and Gradle

给你一囗甜甜゛ 提交于 2021-01-29 20:15:56
问题 I am trying to get the Mapstruct annotation processor to work in IntelliJ in a Gradle project. Ideally, I would expect for all configuration to be in the gradle-file and that anyone could just import the project into IntelliJ and get a complete setup without having to set any preferences manually. But I am okay with compromises on that. I am using IntelliJ 2018.3 and Gradle 5.0 with Java 11 (i.e. the latest and greatest). The Mapstruct version is 1.2.0.FINAL. What I have done: Configured the

Android Annotation processor access resources (assets)

£可爱£侵袭症+ 提交于 2021-01-29 04:04:47
问题 I want to access a resource from my andoid studio project in my annotation processor. I first tried to use the getResource method from filer: FileObject fo = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "", "src/main/res/layout/activity_main.xml"); , but it always throwed a exception that just returned "src/main/res/layout/activity_main.xml" as a message. Next think i have tried was this.getClass().getResource("src/main/res/layout/activity_main.xml") , but this always

How can I add a generated Source Folder to my Source Path in Gradle?

≡放荡痞女 提交于 2020-07-04 07:27:23
问题 I use annotation processing. Therefore I use the apt plugin. It generates new java sources in build/source/apt . Here is my build.gradle: apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'apt' apply plugin: 'war' apply plugin: 'gwt' apply plugin: 'jetty' sourceCompatibility = 1.7 version = '1.0' eclipse { classpath { downloadSources=true downloadJavadoc=true } } buildscript { repositories { mavenCentral() jcenter() maven { url "https://oss.sonatype.org/content/repositories/snapshots

How can I add a generated Source Folder to my Source Path in Gradle?

 ̄綄美尐妖づ 提交于 2020-07-04 07:27:18
问题 I use annotation processing. Therefore I use the apt plugin. It generates new java sources in build/source/apt . Here is my build.gradle: apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'apt' apply plugin: 'war' apply plugin: 'gwt' apply plugin: 'jetty' sourceCompatibility = 1.7 version = '1.0' eclipse { classpath { downloadSources=true downloadJavadoc=true } } buildscript { repositories { mavenCentral() jcenter() maven { url "https://oss.sonatype.org/content/repositories/snapshots

How to access TypeUse annotation via AnnotationProcessor

大城市里の小女人 提交于 2020-07-01 13:09:28
问题 Question: Is it possible to access elements annotated with a @Target(ElementType.TYPE_USE) annotation via an annotation processor? Is it possible to access the annotated type bounds via an annotation processor? Links to related documentation I missed are highly appreciated. Context: The annotation: @Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.SOURCE) public @interface TypeUseAnno {} An example class: public class SomeClass extends HashMap<@TypeUseAnno String, String> {} The

How to access TypeUse annotation via AnnotationProcessor

China☆狼群 提交于 2020-07-01 13:09:05
问题 Question: Is it possible to access elements annotated with a @Target(ElementType.TYPE_USE) annotation via an annotation processor? Is it possible to access the annotated type bounds via an annotation processor? Links to related documentation I missed are highly appreciated. Context: The annotation: @Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.SOURCE) public @interface TypeUseAnno {} An example class: public class SomeClass extends HashMap<@TypeUseAnno String, String> {} The

How to invoke Annotation Processor from Gradle plugin

笑着哭i 提交于 2020-06-13 08:32:09
问题 I am currently working on a Gradle custon plugin that should analyse my root project for specific configs in every subproject and then generate some kotlin source code in the build dir. I can't figure out a way to invoke my annotation processor from my gradle plugin which has a custom task for this matter. Any ideas how to achieve this? Any resource/tutorial/documentation is also highly welcomed. Thanks in advance and be safe. 回答1: After a long time of googling and mostly trying and failing,

Find type parameter of method return type in Java 6 annotation processor

萝らか妹 提交于 2020-01-20 04:07:51
问题 I'm writing a tool that uses the annotation processor to generate source code depending on the return type of methods of an annotated class. The return type is always some subtype (interface or class) of an interface A that defines a type variable T . interface A<T>{T m();}; I would like to find the type parameter for the method m() return value type variable T . The return type is represented by the annotation processor as a javax.lang.model.type.TypeMirror instance. The simplest case is to