Questions tagged [annotation-processing]

An annotation processor is a plug-in for the Java compiler. An annotation processor can do such things as analyze declarations, cause compilation errors and generate new compilation units.

An annotation processor is a plug-in for the Java compiler.

An annotation processor is an instance of javax.annotation.processing.Processor whose process method is invoked during compilation.

Once invoked, the processor is then able to do such things as:

  • Analyze parts of the abstract syntax tree, primarily declarations via javax.lang.model.element and types via javax.lang.model.type.
  • Cause compilation errors and warnings (similar to how the @Override annotation works) via the Messager.
  • Generate new compilation units (i.e. source code files) via the Filer which are subsequently compiled.

Notes on the current limitations of annotation processors

  • Annotation processors may only generate new compilation units, not modify existing compilation units. Some annotation processors, such as Project Lombok, achieve the latter via undocumented internal Javac API.
  • The existing API in Java Platform SE is limited to only analyzing declarations, such as class declarations and method declarations. The Compiler Tree API exists, which allows one to analyze the full abstract syntax tree, but it's largely undocumented and not yet a part of SE.

Resources

723 questions
0
votes
1 answer

Annotation processor handles only recently changed classes

In our project we want to create unique identifiers for user interface dialogs. To make sure developers do not create duplicate identifiers for dialogs i created an annotation processor which check for a "Dialog annotation" (It contains the unique…
peq
  • 329
  • 1
  • 2
  • 9
0
votes
1 answer

Intellij Maven default annotation processors configuration getting lost

I configured my Maven project to work with a Annotation processor options in IntelliJ Idea 2017.1 by adding two options that correspond to two compilerArg of maven-compiler-plugin. My problem : IntelliJ reset the annotation processing configuration…
Radouane ROUFID
  • 10,595
  • 9
  • 42
  • 80
0
votes
2 answers

Android studio - run annotation processor manually

Is that possible? I have changed a few basic things in my code and want to make a clean build to see how many things needs to be adjusted now. This results in 1000s of cannot find symbol class ... messages in my Messages Gradle Build window. So I…
0
votes
0 answers

Custom Annotation Processor to call specific methods at runtime

I'm trying to learn annotation processors. I'm trying to create a custom annotation that would send a certain object to a certain method. Both of them will be annotated with the same annotation. For Example: public void…
user2498079
  • 2,872
  • 8
  • 32
  • 60
0
votes
2 answers

Generate Dagger components using Annotation Processor

I'm working on an Android App which follows the MVP architecture pattern. In all my fragments I'm injecting a Presenter. Therefore my Fragments (Views) need to have a Component in which I declare the injects. For example: @ActivityScope @Component( …
4gus71n
  • 3,717
  • 3
  • 39
  • 66
0
votes
1 answer

Generating XML Resources into Classpath using Annotation Processors

I am currently working on a Gradle 3.3 project in Intellij 15.0.6. I am using the Gradle APT plugin to add annotation processors to my classpath. It works fine when generating Java class files, however I need to be able to generate XML sources…
Armin Naderi
  • 33
  • 1
  • 7
0
votes
3 answers

DataBinding doesn't work after upgrading to gradle plugin 2.3

After upgrading to classpath 'com.android.tools.build:gradle:2.3.0' and migrating to build-in annotation processor I got following error for all my DataBinding generated classes: :app:compileInternalDebugJavaWithJavac …
Roman Nazarevych
  • 7,513
  • 4
  • 62
  • 67
0
votes
0 answers

Class first-letter cutting in Google Truth Unit Tests

I am trying to make tests for ActivityStarter library, which is using annotation processing, but I get strange error: An expected source declared one or more top-level types that were not present. Expected top-level types:…
MarcinM
  • 428
  • 7
  • 15
0
votes
1 answer

Java annotation process not yet generated elements

I use last versions of eclipse, java and https://marketplace.eclipse.org/content/m2e-apt to process annotations. I have a processor that processes a single annotation, and looks at the methods within the annotated class and will take all the…
0
votes
1 answer

annotation processing - how to access (and modify) the contents of a field

I'm trying to create an annotation that will change the content of the annotated field. So far this is my annotation: @Retention(RetentionPolicy.CLASS) @Target(ElementType.FIELD) public @interface MyAnnotation { String value(); } And I want to…
geanakuch
  • 778
  • 7
  • 13
  • 24
0
votes
0 answers

How to stop IntelliJ IDEA from creating new annotation processor profiles when a pom file is changed

I am using IntelliJ IDEA with Maven to write Java application. I have created several modules, created a custom annotation processor profile with a custom Production sources directory property and moved the modules to that profile. I have also…
Ivan Stoyanov
  • 5,412
  • 12
  • 55
  • 71
0
votes
1 answer

Retrieve private class member name

I am designing a Hibernate's entity Pre-Update Event Listener with Java 8. I've created a StateTracker class that, from the PreUpdateEvent, gets the entity's new and old states and the parameters name. This class maps the parameters names to the…
Rodrigo Oliveira
  • 1,452
  • 4
  • 19
  • 36
0
votes
1 answer

Custom annotation processor - Java

I have created a custom annotation and annotation processor using Abstract Processor. Which means I want to do annotation processing a before compile time. I exported my custom annotation and processor as a Jar and trying to use it with a simple…
Yogesh D
  • 1,663
  • 2
  • 23
  • 38
0
votes
1 answer

Annotation processor: file writing from the process() method

I wrote an annotation processor and i'd like to write some information into a text file. In my class I'm extending the AbstractProcessor and overriding the public void init(ProcessingEnvironment processingEnv) and public boolean process(Set
Barnie
  • 5
  • 5
0
votes
2 answers

Annotation Processor generated class on GWT Client side

I have to instantiate a Class which is generated by my custom annotation processor on a GWT client Class which extends Composite. Generated class is also at the same package with this view. However, when I run the super dev mode (SDM), I get the…
Baris
  • 471
  • 6
  • 19