views:

27

answers:

1

I want to define a few annotations that will allow extra warnings/errors to be reported during compilation (similar in concept to the @Nullable and @NotNull annotations in IntelliJ).

I would like to be able to write some compiler hooks that will also add my compilation logic based on those attributes.

I want a generic hook if possible, however since we are using Eclipse - it would also be a benefit if we had that ability.

I'd like to know:

  1. Is it possible? (any of the options above)
  2. Where do I start?
  3. I had little experience with annotations so far, so if I'm going about this the wrong way - I'd like to know that and if possible get a better direction to go with.

Thanks.

+1  A: 

You can use the Java Annotation Processor (see JSR 269: Pluggable Annotation Processing API) for that. From Annotation checking at compile time with Java Annotation Processor:

The JSR 269 states that you can implement a plug-in for the compiler which can handle the annotations. This plug-in can be given as parameter at compile time, so your code will be called when one of your annotation appears in source code.

The mentioned link provides an example that will get you started.

See also:

Pascal Thivent
Thanks - that is exactly what I was looking for.
RonK
@RonK: You're welcome. Have fun!
Pascal Thivent