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 :

  1. First, check the How to contribute code wiki page
  2. Import the AndroidAnnotations project and the HelloWorldEclipse project. You'll need it to test your changes.
  3. Create a new annotation in the package com.googlecode.androidannotations.annotations. It should have a source retention policy. Example: @EActivity.
  4. 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.
  5. Create a source generator for your annotation, in the package com.googlecode.androidannotations.generation. It must implement Instruction. Example: ValueInstruction.
  6. 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.
  7. 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 the buildModelProcessor() method.
  8. 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.