Skip to content

Commit

Permalink
Explain the limitations of the meta-annotation support in the ReadMe (#…
Browse files Browse the repository at this point in the history
…38)

Fixes #37
  • Loading branch information
astmuc authored Feb 8, 2025
1 parent 888b0ff commit ed81fe1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public @interface MyBuilder {
}
```

And then, you can place this `MyBuilder` so-called _meta annotation_ wherever `@Builder`
And then, you can place this `MyBuilder` so-called _meta-annotation_ wherever `@Builder`
can be placed (so, a class, constructor, or static method),
and the effect will be as if that element was annotated with the same `@Builder`
and `@BuilderInterfaces` values as `@MyBuilder` is annotated with,
Expand All @@ -595,6 +595,18 @@ public final class MyValueClass {
}
```

**Note**: since Jilt is implemented as a Java annotation processor,
that means it shares the limitations common to all annotation processors.
The restriction that is most relevant to meta-annotation support is that only files from a single source set
(the one that is currently being compiled) are passed to the processor.
This means that you can't, for example, define the meta-annotation in your main source set,
and then use it in your tests, or package the meta-annotation in a library,
and then depend on that library from your main project that uses Jilt --
in both of those cases, the meta annotation won't be passed to Jilt during compilation,
and so `@Builder` on the meta-annotation won't be recognized.
In order for meta-annotations to work correctly,
they have to be defined and used in the same source set.

##### Supporting classes with private constructors

In some cases, you might want to force customers of a class to only be able to instantiate it through its Builder,
Expand Down

0 comments on commit ed81fe1

Please sign in to comment.