xtend-contrib icon indicating copy to clipboard operation
xtend-contrib copied to clipboard

Support projectlombok-like constructor annotations

Open otrosien opened this issue 10 years ago • 3 comments

These are the annotations I would like to port from projectlombok to xtend first:

  • NoArgsConstructor, AllArgsConstructor, RequiredArgsConstructor, probably with a very similar API, so you can control constructor visibility, make it a static factory method, and set annotations to the constructor (e.g. @AutoWired or @Inject)

But let's discuss the idea and possible API before jumping to the implementation this time. :)

otrosien avatar Feb 17 '16 17:02 otrosien

I think this is pretty well covered by Xtend's FinalFieldsConstructor (which is equivalent to RequiredArgsConstructor).

  • a NoArgsConstructor is so short in Xtend (new() {}) that I don't think it makes sense to have an annotation for that

  • an AllArgsConstructor seems weird. Why would I take something in the constructor if it can be changed later?

  • visibility, annotations etc. can be controlled by using this pattern:

    class Foo {
      @Inject @FinalFieldsConstructor
      protected new() {}
    }
    

oehme avatar Feb 17 '16 19:02 oehme

The AllArgsConstructor is not as useful in xtend as in java, I agree (because we have the with-initilizer => [] ) the lombok versions feature the possibility to be used as static factory methods. (e.g. Price.of(amount) instead of new Price(amount))

otrosien avatar Feb 17 '16 20:02 otrosien

I'd rather have something like @FactoryMethod instead of an argument on the constructor annotation.

oehme avatar Feb 17 '16 20:02 oehme