annotation-processing

AnnotationProcessing - Generating Files at Each Round vs at Last Round

只谈情不闲聊 提交于 2019-12-22 05:49:12
问题 I was playing around with annotation processing and was unable to use generated files directly via an import in my code. Instead I had to prepend the generated class with its complete package. I posted a SO question error: package generated.schema does not exist. In the end I figured out the reason for this, turned out to be pretty simple, see my answer to the same post. Turned out the error was because I was generating the files at last round of processing, instead of anywhere in between. So

Annotation Processor, Getting Modifiers of Method Parameters

北慕城南 提交于 2019-12-21 12:39:30
问题 I'm currently at a project where I work with Java's custom annotations. I want to force the user of my annotation that he has to declare at least a final boolean b inside the method parameters list if he has annotated the method with @Foo. So it should look something like this: @Foo public void foo(final boolean b) { } @Foo public void bar() { } // This should result in an error With my annotation processor I can retrieve the type of the variable but not the final modifier . If i want to

How to write automated unit tests for java annotation processor?

社会主义新天地 提交于 2019-12-20 08:59:21
问题 I'm experimenting with java annotation processors. I'm able to write integration tests using the "JavaCompiler" (in fact I'm using "hickory" at the moment). I can run the compile process and analyse the output. The Problem: a single test runs for about half a second even without any code in my annotation processor. This is way too long to using it in TDD style. Mocking away the dependencies seems very hard for me (I would have to mock out the entire "javax.lang.model.element" package). Have

Why IntelliJ needs Lombok plugin?

*爱你&永不变心* 提交于 2019-12-19 09:09:34
问题 As far as I understand, Lombok uses Java's Annotation Processors to generate additional methods. With Maven 3.5 it works perfectly without adding any additional configuration, just add dependecy to Lombok and put some annotations like @Getter , @Setter . However, if I open this project in IntelliJ IDEA 2018.2, all usages of generated getters/setters are highlighted as errors. I have Annotation Processing turned on, I tried to built project in IntelliJ or build in Maven and then use in

Why IntelliJ needs Lombok plugin?

狂风中的少年 提交于 2019-12-19 09:09:22
问题 As far as I understand, Lombok uses Java's Annotation Processors to generate additional methods. With Maven 3.5 it works perfectly without adding any additional configuration, just add dependecy to Lombok and put some annotations like @Getter , @Setter . However, if I open this project in IntelliJ IDEA 2018.2, all usages of generated getters/setters are highlighted as errors. I have Annotation Processing turned on, I tried to built project in IntelliJ or build in Maven and then use in

How to obtain the right JavaFileManager in a Java annotation processor?

穿精又带淫゛_ 提交于 2019-12-19 06:06:15
问题 I've written an Java annotation processor by extending javax.annotation.processing.AbstractProcessor which is called in the Eclipse context and it works fine, except that I need more information about the source path and class path for my processor to work: @SupportedAnnotationTypes({"MyAnno"}) @SupportedSourceVersion(SourceVersion.RELEASE_8) public class Processor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

Writing an annotation processor for maven-processor-plugin

北慕城南 提交于 2019-12-19 01:28:37
问题 I am interested in writing an annotation processor for the maven-processor-plugin. I am relatively new to Maven. Where in the project path should the processor Java source code go (e.g.: src/main/java/...) so that it gets compiled appropriately, but does not end up as part of my artifact JAR file? 回答1: The easiest way is to keep your annotation processor in a separate project that you include as dependency. If that doesn't work for you, use this config Compiler Plugin: <plugin> <groupId>org

Databinding annotation processor kapt warning

落爺英雄遲暮 提交于 2019-12-18 12:17:26
问题 In my app module's build.gradle, I have added dependencies { kapt('com.android.databinding:compiler:3.1.2') ... } but I'm still receiving the compiler warning for app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.android.databinding:compiler:3.1.2'. Everything functions, I just hate having warnings hanging around. Any help is much appreciated! 回答1: I had same warnings until I

How do you use Java 1.6 Annotation Processing to perform compile time weaving?

女生的网名这么多〃 提交于 2019-12-18 04:51:31
问题 I have created an annotation, applied it to a DTO and written a Java 1.6 style annotationProcessor. I can see how to have the annotationProcessor write a new source file, which isn't what I want to do, I cannot see or find out how to have it modify the existing class (ideally just modify the byte code). The modification is actually fairly trivial, all I want the processor to do is to insert a new getter and setter where the name comes from the value of the annotation being processed. My

Java 6 annotation processing — getting a class from an annotation

浪子不回头ぞ 提交于 2019-12-17 17:38:31
问题 I have an custom annotation called @Pojo which I use for automatic wiki documentation generation: package com.example.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.SOURCE) @Target(ElementType.METHOD) public @interface Pojo { Class<?> value(); } I use it like this: @Pojo(com.example.restserver.model.appointment.Appointment.class) to