On Aug 9, 4:04 pm, Reinier Zwitserloot <
reini...@gmail.com> wrote:
> For no-args annotations, we can just do this:
>
> @Getter(onMethod=Deprecated.class)
>
> no problem. However, this is a bit ugly (very minor concern), occupies the
> 'onMethod' name for the future if ever we can go back to
> @Getter(onMethod=@Deprecated) (medium concern), and doesn't let you put any
> arguments on the annotation (major concern).
I think, it can be solved by combining two things:
For parameterless annotations use arguments of the lombok annotations
like
Class<? extends Annotation>[] onMethod() default {};
Combine them with annotations on fields like
@Named("blue") private Something a;
in order to specify parameterized annotations. So for example
@Setter(Deprecated.class) private Something a;
leads to placing @Deprecated on the setter, while
@Setter(onMethod=Named.class) @Named("blue") private Something a;
leads to placing @Named("blue") on the setter. At the same time the
annotation gets removed from the field, since AFAIK there's no tool
requiring such duplicities.
This doesn't allow all combinations, e.g, you can't place
@Named("blue") on the setter and @Named("red") on the getter. But
again, I don't think anybody needs it. Compared to the state before
the onX-removal it's a bit more verbose, but not much. It doesn't
allow some strange combinations previously possible, but it allows
some additional things like annotating constructor arguments:
@RequiredArgsConstructor(onParam=Named.class, onMethod=Inject.class)
class SomeFileProcessor {
@Named("src") private final File srcFile;
@Named("dst") private final File dstFile;
}
leads to
class SomeFileProcessor {
@Inject
public SomeFileProcessor(@Named("src") File srcFile, @Named("dst")
File dstFile) {
this.srcFile = srcFile;
this.dstFile = dstFile;
}
private final File srcFile;
private final File dstFile;
}
Something like this is necessary whenever you want to constructor-
inject two different instances of a single class.