robolectric/robolectric — pull request #1224 by kriegfrj (2014-08-09 09:36:31+00:00)
Title: Robolectric annotation processor (potential fix for #1128)

Hi all,

This pull request started as a proposal to fix for issue #1128 (which I raised a couple of months back). It is an annotation processor which can do some useful things with Robolectric annotations at compile time. For a full description of its current features, please see the GitHub home page I have created for this project: https://github.com/kriegfrj/rap.

This PR fixes #1128 with the introduction of a new @Resetter annotation in conjunction with RAP. Initially I used the @Resetter annotation at runtime only, but because finding the resetter methods required iterating through every method of every shadow for every call to Robolectric.reset() (which in turn is called for every test), this slowed down the performance noticeably. This was the inspiration for RAP, so that this iteration over all shadows need only happen once at compile time. automatically generates a reset() method that calls all of the @Resetter-annotated methods it finds. This also allows it to incorporate the calls to ShadowLooper.resetMainLooper() and others by annotating these methods as @Resetter. As I learned more about annotation processing the other features presented themselves to me as possible enhancements.

**This PR will currently fail on Travis** because introduces a new build dependency on the annotation processor, which has not yet been deployed to Maven Central. Before going to the effort of deploying it to Maven Central I thought I would submit what I have as a work-in-progress to get feedback from the core team. I didn't want to go to the effort of deploying it to Maven Central if the core team didn't think it was a good idea. Ideally if this was to become part of the Robolectric build process then ownership should probably pass to the Robolectric core group and it should deployed in the org.robolectric namespace. I also haven't got much of an idea how well the annotation processor will work with Gradle and/or IntelliJ, so feedback/contributions here would also be appreciated.