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
0 answers

Can I have an AnnotationProcessor defined in maven which will cause compilation errors in my IDE?

Background: I'm adding some annotations to one of our test modules such that everything in a specific package needs to be annotated. I have already written an AnnotationProcessor which does this. The problem: My processor successfully works for me…
ohshazbot
  • 894
  • 3
  • 8
  • 16
0
votes
1 answer

how to setup icepick on eclipse? What annotation processors to add to factory path?

Using the icepick library with Eclipse requires configuration of the annotation processor. What libraries need to be added to the factory path so that there are no compilation errors and icepick processes your classes?
rtack
  • 183
  • 3
  • 10
0
votes
1 answer

How to create annotation to format amount values

So I am working on a solution right now wherein we have 2 requirements: Format SSN / Telephone Number in Hyphen form which is otherwise currently being displayed without it. Format an amount field in the format "$0.00". Currently we have written a…
Yogendra
  • 331
  • 5
  • 21
0
votes
1 answer

AnnotationProcessing - create ExecutableElement

I'm using Elements.getElementValuesWithDefaults to retrieve annotationvalues. Key of the returned Map is something extending ExecutableElement. I can iterate over the entrySet and check the name of each key but this leads to ugly…
lefloh
  • 10,653
  • 3
  • 28
  • 50
0
votes
1 answer

Java library that depends on android.os results in NoClassDefFoundError when used

I've created a java annotation processor in a project (which I'll call JavaLibrary) that makes use of android.os.Bundle. As such, the project has the following line in its gradle.build dependencies: compile 'com.google.android:android:4.1.1.4' In…
Nathan Taylor
  • 879
  • 1
  • 9
  • 16
0
votes
2 answers

Maven, NetBeans Platform, Wrapper Modules and Annotation Processors on dependencies

I have a Maven NetBeans platform application. One of its modules is a wrapper to a java project (jar) that exposes some services to the Lookup. In the wrapped project I use the maven-processor-plugin to process the annotations so everything gets…
javydreamercsw
  • 5,363
  • 13
  • 61
  • 106
0
votes
2 answers

Annotation processing for adding message attribute to existing JSR-303 annotations on fields

I have a data transfer object that's annotated with JSR-303 constraints like... public class AssetOwnedDailyLocatableId implements Serializable, AssetOwned, HasOperatingDay, Locatable { private static final long serialVersionUID =…
0
votes
1 answer

Ant android test project with AndroidMock

I have a android project, I want to build and install and run the test with command line. Following is my build shell script: android update project --path ./main/libraryProject android update project --path ./main/Project --library…
-1
votes
0 answers

CustomValue Annotation Processing : How can i create a similar annotation of @Value

I have just started using annotation processing and trying to inject the value on the field annotated with my annotation . Since yesterday I am facing this error message: Compilation failure I have tried to research and fix but unable to avoid this…
med
  • 1
  • 2
-1
votes
0 answers

Mapstruct generate two classes

Two implementation classesBuild.gradle IDEA Setting Gradle IDEA Setting Annotation Processors Although the project can be launched successfully, there might be errors in the IDE when generating the build files. How to remove one of they?
-1
votes
1 answer

gradle use project as its own annotation processor

I'm making a library that includes an annotation processor . ├── lib │   ├── build.gradle │   └── src │   ├── main │   │   ├── java │   │   │   └── demo │   │   │   ├── MyAnnotation.java │   │   │   └──…
theonlygusti
  • 11,032
  • 11
  • 64
  • 119
-1
votes
1 answer

Java annotation implementation logic

I want to know how Java generates annotation implementation like @Mapper and @FeignClient. Does It generates an implementation class in runtime? Thanks. Know how Java generates an implementation for an interface in runtime.
-1
votes
1 answer

Is it possible to raise compile error on method's return type in annotation processing

For example, if you write override method with wrong return value. new Runnable() { public int run() { } }; Compiler will mark your return value int and give you the error 'The return type is incompatible with Runnable.run()'. Now I'm writing…
Dean Xu
  • 4,438
  • 1
  • 17
  • 44
-1
votes
2 answers

Cannot remove java annotation processor from maven project

I'm about to refactor my dirty annotation processor. Therefore I wanted to create a new one to extract some responsibilities from the old one. old: com.company.coma.shared.annotation.ComaToolAnnotationProcessor new:…
xetra11
  • 7,671
  • 14
  • 84
  • 159
-1
votes
3 answers

Resource for annotation processing

I'm looking desperately for a valuable resource on Java 6 annotation processing. Ideally, the different points I would like to be addressed should be: The various Element interfaces and how to retrieve them from a class structure How to link a…
Alexis Dufrenoy
  • 11,784
  • 12
  • 82
  • 124
1 2 3
48
49