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