Adding Functionalities - PerfectCarl/androidannotations GitHub Wiki
This page is not up to date, the introduction of
CodeModel
to generate code removed the need to use Instruction classes.
Adding new Annotations
This page describes the process to follow when adding annotations and code generation :
- First, check the How to contribute code wiki page
- Import the
AndroidAnnotations
project and the HelloWorldEclipse project. You'll need it to test your changes. - Create a new annotation in the package
com.googlecode.androidannotations.annotations
. It should have a source retention policy. Example: @EActivity. - Create a validator for your annotation, in the package
com.googlecode.androidannotations.validation
. It must implement ElementValidator. It can extend ValidatorHelper which provides helper methods. Example: ExtraValidator. - Create a source generator for your annotation, in the package
com.googlecode.androidannotations.generation
. It must implement Instruction. Example: ValueInstruction. - Create a processor that will take validated elements, then create and add the corresponding instructions in the model, in the package
com.googlecode.androidannotations.processing
. It must implement ElementProcessor. Example: ClickProcessor. - Bind everything in AndroidAnnotationProcessor:
1. Add your annotation to the @SupportedAnnotationClasses class list at the top of the AndroidAnnotationProcessor class.
2. Register your validator in the
buildModelValidator()
method. 3. Register your processor in thebuildModelProcessor()
method. - Test your new annotation with the HelloWorldEclipse project. Once you've configured everything, you only need to delete the
AndroidAnnotation
JAR in the target folder from Eclipse to see it automatically rebuilt and reloaded in HelloWorldEclipse.