• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Extensions
2
3
4AutoValue can be extended to implement new features for classes annotated with
5`@AutoValue`.
6
7## Using extensions
8
9Each extension is a class. If that class is on the `processorpath` when you
10compile your `@AutoValue` class, the extension can run.
11
12
13Some extensions are triggered by their own annotations, which you add to your
14class; others may be triggered in other ways. Consult the extension's
15documentation for usage instructions.
16
17## Writing an extension
18
19To add a feature, write a class that extends [`AutoValueExtension`], and put
20that class on the `processorpath` along with `AutoValueProcessor`.
21
22`AutoValueExtension` uses the [`ServiceLoader`] mechanism, which means:
23
24*   Your class must be public and have a public no-argument constructor.
25*   Its fully-qualified name must appear in a file called
26    `META-INF/services/com.google.auto.value.extension.AutoValueExtension` in a
27    JAR that is on the compiler's `classpath` or `processorpath`.
28
29You can use [AutoService] to make implementing the `ServiceLoader` pattern easy.
30
31Without extensions, AutoValue generates a subclass of the `@AutoValue` class.
32Extensions can work by generating a chain of subclasses, each of which alters
33behavior by overriding or implementing new methods.
34
35## TODO
36
37*   How to distribute extensions.
38*   List of known extensions.
39
40[AutoService]: https://github.com/google/auto/tree/master/service
41[`AutoValueExtension`]: https://github.com/google/auto/blob/master/value/src/main/java/com/google/auto/value/extension/AutoValueExtension.java
42[`ServiceLoader`]: http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html
43
44