murat8505 / projectlombok

Automatically exported from code.google.com/p/projectlombok
0 stars 1 forks source link

add "annotations" parameter of type java.lang.String[] (or Annotation[] ?) to @Getter and @Setter #371

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Expected output :
@Getter(annotations = { "@MyAnnotation" })
private Foo bar;

to generate : 

@MyAnnotation
public Foo getBar() {
    return this.bar;
}

Original issue reported on code.google.com by nicolas....@gmail.com on 3 May 2012 at 1:12

GoogleCodeExporter commented 9 years ago
And what about this?

@NonNull @Size(min=3, max=5) @Name("foo_bar")
private Foo bar;

Maybe if you need annotations on the getter and only there, generating the 
other way round would be a better option.

@Field(access=PRIVATE) @Setter
@NonNull @Size(min=3, max=5) @Name("foo_bar")
public Foo getBar();

could generate just this. (For syntactical correctness, one could force an 
"abstract" modifier on the getter.)

Original comment by k.tinnefeld on 5 May 2012 at 6:14

GoogleCodeExporter commented 9 years ago
There is no other way than the one which Karsten has pointed out. Its technical 
not possible for lombok to embbed annotations in lombok-generated methods, at 
least not with the current javac and bytecode implementation.

So, if you want custom annotations on a method, then you have to hardcode it.

Original comment by Eric6i...@googlemail.com on 4 Jun 2012 at 3:18