annotation-processing

How can I refer to implementations of a method in annotation processing?

谁说胖子不能爱 提交于 2020-01-12 06:26:10
问题 I am playing around with Java (javax) annotation processing. Suppose I have an annotation for methods: @Target(ElementType.METHOD) public @interface MethodAnnotation { } Now I want to process all the methods which are overridden from a type with the annotated method: interface MyInterface() { @MethodAnnotation void f() } class MyClass implements MyInterface { override void f() { } // <- I want to process this method } @Inherited meta-annotation seems not to be suitable here: Note that this

Annotation processor in Gradle outputs source files to build/classes making javadoc fail. How to fix it?

北城余情 提交于 2020-01-11 02:31:09
问题 I have an annotation processor that is automatically picked up by the Java compiler at build time (using SPI). During a gradle build, the generated java sources of this annotation processor are put in build/classes as Gradle tells the annotation processor that this is the place to output generated source files. When the standard javadoc task is run, it tries to create javadoc for all files in build/classes, including *.java. This failes because javadoc only expects *.class files, making the

Code replacement with an annotation processor

末鹿安然 提交于 2020-01-09 04:23:06
问题 I'm trying to write an annotation processor to insert methods and fields on a class... and the documentation is so sparse. I'm not getting far and I don't know if I'm approaching it correctly. The processing environment provides a Filer object which has handy methods for creating new source and class files. Those work fine but then I tried to figure out how read the existing source files, and all it provides is "getResource". So in my Processor implementation I've done this: @Override public

Code replacement with an annotation processor

霸气de小男生 提交于 2020-01-09 04:23:05
问题 I'm trying to write an annotation processor to insert methods and fields on a class... and the documentation is so sparse. I'm not getting far and I don't know if I'm approaching it correctly. The processing environment provides a Filer object which has handy methods for creating new source and class files. Those work fine but then I tried to figure out how read the existing source files, and all it provides is "getResource". So in my Processor implementation I've done this: @Override public

Custom compiler error isnt removed (after fixing) until file is saved

独自空忆成欢 提交于 2020-01-06 13:12:51
问题 Every annotation processor I've made seems to have this problem. For example, a @Constant annotation: package annotations; @Retention(RetentionPolicy.SOURCE) @Target(ElementType.FIELD) public @interface Constant { } The processor: package processor; @SupportedAnnotationTypes("annotations.Constant") @SupportedSourceVersion(SourceVersion.RELEASE_8) public final class ConstantProcessor extends AbstractProcessor { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment

What its the first, the annotated class (egg) or used class (chicken)?

六眼飞鱼酱① 提交于 2020-01-05 10:02:10
问题 certainly I have not read something fundamental, and it seems very strange, but I wonder. Suppose you use @SharedPref public interface SharedPreferencesInterface { @DefaultBoolean(true) boolean showDeviceName(); I have the IDE (idea) configured with Gradle, and I generated the SharedPreferencesInterface_ class that I can use in another class as @Pref SharedPreferencesInterface_ prefs; But suppose someone now download the project, how can the use? Because the class where used

Compile-time created class is shown as non-existent in IntelliJ

旧时模样 提交于 2020-01-05 04:17:05
问题 Motivation : I'd like to try if compile-time annotation processing fits my problem. It needs to work out of the box, no compiler arguments etc. Current state : I have: The annotation An annotation processor A .jar containing both of these and a javax.annotation.processing.Processor file containing the FQCN of my processor in META-INF/services What should happen: It should autodetect the processor It should process the annotation and create a new class (WiredAnnotated) I should be able to use

Need file from src/main/resources in generate-sources phase for annotation processor config

。_饼干妹妹 提交于 2020-01-04 14:14:56
问题 I have an annotation processor that I need to give some configuration to tell it a few details about how I want it to generate source code. I spent a good deal of time trying to understand why the file was sitting in target/classes after the build, but I was getting an exception during annotation processing stating that the file did not, in fact, exist. After much digging I finally figured out why the file (stored in src/main/resources/config ) isn't getting copied over to target/classes

How can I get the working directory of a project from an Annotation Processor in Java

倖福魔咒の 提交于 2020-01-04 04:20:26
问题 I am writing an annotation processor in Java and in this annotation processor I want to be able to find a file in the Project hierarchy of the project on which I am using this annotation processor. Through the annotation I can pass in the path of the file I am searching for relative to the project root but i cannot retrieve the project's working directory. Let's say that the processor is MyCustomProcessor and I am using it on the project MyProject. I want to be able to access(read) a file (a

How do I use custom Java Annotation Processor in Gradle?

假如想象 提交于 2020-01-02 03:47:07
问题 I've been working on a simple java annotation processor that extends AbstractProcessor . I've been able to successfully test this using javac -Processor MyProcessor mySource.java The problem is integrating this into a simple Hello World android application using Android Studio. I started by making a new Android Project, and then adding a separate module where I place all my annotation processor code (the MyProcessor class as well as the custom annotation it uses). I then added this new module