質問

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 Processor to an annotation
  • How to build an annotation, with the Processor, for example in the form of jar file
  • How to make all this in Eclipse

Do you any resource which could match the bill?

役に立ちましたか?

解決

This guide to modern, static, annotation processing is very easy to follow and has a video corollary to boot:

Blog post: http://hannesdorfmann.com/annotation-processing/annotationprocessing101

Video Talk: https://www.youtube.com/watch?v=43FFfTyDYEg

I strongly recommend a static approach to annotation processing, as it yields advantages such as:

  • Avoiding reflection.
  • Compatibility with both Java and Android.

Also it is pretty cool.

他のヒント

I guess this is quite a decent introduction on writing and processing custom annotations.

About packaging: you can use the command line tool in java or any of the tools a an IDE or even a build tool like ant, gradle or maven. And eclipse is just an IDE. Just use it. It will become quite natural after a while.

Here's some short introduction and some example code: Java 6.0 Features Part – 2 : Pluggable Annotation Processing API. Take a look this, I summarised some steps of processing annotations: Annotation Processing Tool <- checking valid annotation

Not sure if you want to develop the processor in eclipse or if you finally want to use it with eclipse. There's nothing special when developing the processor, create a project for the processor and maybe another one with some example annotations for testing. You can add and enable the processor in eclipse projects (and netbeans afaik) to take advantage of a nice integration of errors or warnings your processor may create. Use the Messager for this to let the IDE mark particular elements directly in your source code.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top