Skip to content

Commit

Permalink
Beginning of Extension docs
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=137033107
  • Loading branch information
netdpb authored and ronshapiro committed Nov 9, 2016
1 parent 840451a commit 52e2335
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion value/userguide/extensions.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# Extensions

TODO

AutoValue can be extended to implement new features for classes annotated with
`@AutoValue`.

## Using extensions

Each extension is a class. If that class is on the `processorpath` when you
compile your `@AutoValue` class, the extension can run.


Some extensions are triggered by their own annotations, which you add to your
class; others may be triggered in other ways. Consult the extension's
documentation for usage instructions.

## Writing an extension

To add a feature, write a class that extends [`AutoValueExtension`], and put
that class on the `processorpath` along with `AutoValueProcessor`.

`AutoValueExtension` uses the [`ServiceLoader`] mechanism, which means:

* Your class must be public and have a public no-argument constructor.
* Its fully-qualified name must appear in a file called
`META-INF/services/com.google.auto.value.extension.AutoValueExtension` in a
JAR that is on the compiler's `classpath` or `processorpath`.

You can use [AutoService] to make implementing the `ServiceLoader` pattern easy.

Without extensions, AutoValue generates a subclass of the `@AutoValue` class.
Extensions can work by generating a chain of subclasses, each of which alters
behavior by overriding or implementing new methods.

## TODO

* How to distribute extensions.
* List of known extensions.

[AutoService]: https://github.com/google/auto/tree/master/service
[`AutoValueExtension`]: https://github.com/google/auto/blob/master/value/src/main/java/com/google/auto/value/extension/AutoValueExtension.java
[`ServiceLoader`]: http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html

0 comments on commit 52e2335

Please sign in to comment.