--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/
To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en
--
ap
On 10-07-14 16:20, Reinier Zwitserloot wrote:
> Hmm, maybe a combination with a db of 'do the right thing', powered by
> SPI of course (NonNull and friends is currently hardcoded. In retrospect
> we didn't realize this was such a can of worms, but as we've released a
> widely used version of lombok that supported it we can't very well drop
> it now), together with the option to override this behaviour using
> parameters on the annotation, might be the best we could possibly do.
IMHO, a separate annotation specifying the behavior would be better. You
could place it on the whole class and specify that each @Foo should be
copied to the getter and to the argument of setter and kept on the
field. You could override it on a field, but I don't think you'd need it
often.
It's more general than the now deprecated
AnyAnnotation[] onMethod() default {};
since you can define all the needed annotations on fields and let lombok
move there where they belong to. This way the annotations may be
parametrized and you may specify their target locations easily and exactly.
A non-trivial example may look like
@FieldReannotation({
// move all Inject and Named annotations to setters
@PlaceAnnotations(ofType={Inject.class, Named.class}, on="S"),
// keep all NonNull annotations on fields
// and copy them to getters and setters' arguments
@PlaceAnnotations(ofType=NonNull.class, on="FGA"),
})
@Getter @Setter
public class FieldReannotationExample1 {
@Inject @Named("NameOfTheBeast") @NonNull
private String name;
}
I was thinking about using an enum for the destination, but it's not
necessary, all errors will show up immediately and the Javadoc on "on"
explains how it works, see
http://dl.dropbox.com/u/4971686/101123/reanno/FieldReannotation.java
http://dl.dropbox.com/u/4971686/101123/reanno/PlaceAnnotations.java
A more complex example
http://dl.dropbox.com/u/4971686/101123/reanno/FieldReannotationExample2.java
IMHO, @FieldReannotation should be @Inherited, since this minimizes the
boilerplate a bit. Actually, a global configuration would be ideal, I
think it could be done without any magic and without run-time dependency
on lombok, however, it needs to access other files in project, is this
already possible?
> That, and, once resolution is built into lombok, the option to use
> lombok meta annotations (annotations meant to go on @interface
> declarations) to explain the right thing to do, which lombok will
> automatically pick up and apply. The db is then a backup for those
> classes that are commonly used but refuse to release a version that
> works with the lombok meta annotations.
Neither the db not those meta annotations can help always as there are
annotations (like JPA @Id) to be placed either on fields or on
accessors, and the choice is up to the user.
There are annotations which must not be copied to accessors since
they're illegal there, but current version of Lombok does it, for
example when placing
com.google.inject.internal.Nullable
on a field with @Getter I get "The annotation @Nullable is disallowed
for this location". IMHO, this is a bug, lombok should never copy an
annotation to a place where it's not allowed (this is possibly hard to
find out) and always remove it from a field when it's not allowed there.
In my proposal, even annotation with @Target(ElementType.METHOD) would
get placed on fields and moved to the right place by lombok. I suppose,
it's doable and maybe even easy?