Hi,
Love lombok but having difficulties with Guice / injection. I've looked around the site + forums and I see a few things but I'm not seeing anything I can use so wandering if there are any plans for anything else or I had a couple idea's I was looking to implement.
Either something simple like an @InjectRequiredArgsConstructor where it does required args but just adds @Inject would probably solve 90% of cases with anything more fancy requiring a hand rolled constuctor. Its not perfect, but would remove alot of boilerplate from my apps.
The other idea I was playing with / may try is to generate a constructor based off of annotations in the field declaration, but I dont know exactly what is possible in the ast.
for example something like this:
@InjectRequredConstructorArgs
class A {
@Assisted private final MyClass a;
@Named("bill") private final OtherDependency b;
}
is rewritten:
class A {
private final MyClass a;
private final OtherDependency B;
@Inject
A(@Assisted Myclass a, @Named("bill") OtherDependency b) {
this.a = a;
this.b = b
}
}
Essentially the idea being the constructor is generated from required args and any annotations on the field are added to the declaration in the constructor and stripped from the final output on the fields. If annotations are needed for the fields, I think ordering is preserved so you could do something like (but with sensible names):
@NonNull @MyAnnotionan @FollowingAnnotationsStrippedToConstructor @Assisted MyClass a
creates the field:
@NonNull @MyAnnotionan MyClass a
I'm not exactly sure how much is possibly with the AST / rewriting. I could see annotations with arguments, e.g. @Named("server"), being problematic, but then again, they are quite brittle / horrible anyway and a custom annotation would be safer, i.e. do @MyCustomAnnotation MyClass instead, so just supporting no arg annotations you could get 100% boiler plate removal with good design.
I see alot of the thought on posts has been about gentrifying annotations, so finding ways of expressing annotations with annotations and overloading, basically making required args constructor to almost polymorphic / multifunctional. Similar to Getter with lazy boolean but on steroids.
I think some specific custom annotations for it is reasonable / would be cleaner and more understandable than overloading existing annotations. Behind the scenes they can share common code. Especially as its got to the point now where injection is going to be standard.
Cheers,
Jon