Feature Request: Copy field @Named annotation to constructor parameters

2,956 views
Skip to first unread message

Pablo Grisafi

unread,
Nov 15, 2016, 9:24:59 AM11/15/16
to Project Lombok
Maybe I'm not using lombok the right way, but I have this problem.

I love to use the @AllArgsConstructor(onConstructor = @__(@Inject)) when working with Guice. However, once I need to inject @Named properties (tipically configuration Strings, I need to remove the   @AllArgsConstructor(onConstructor = @__(@Inject))
and type a constructor like 
       
       @Inject
public MyClass(MyDependency dependency, @Named("project.version") String projectVersion) {
this.dependency = dependency;
this.projectVersion = projectVersion;
}

I think it would be nicer to be able to write

@AllArgsConstructor(onConstructor = @__(@Inject), copyFieldAnnotationsToConstructorParams=true)
class MyClass{
    private final MyDependency dependency;
    private final  @Named("project.version") String projectVersion;
}


And gt he constructor automatically generated. At the very least, it will help Guice users like myself.

Thanks again for this awesome addition to Java
      

Martin Grajcar

unread,
Nov 15, 2016, 12:37:31 PM11/15/16
to project...@googlegroups.com
This feels a bit hacky as sometimes not all annotations should be copied and/or are allowed on parameters. I proposed a separate annotation @OnConstructor one day and started to implement it, but it was more work than I thought. Even as a Guice user, I can live without it using a few (sometimes ugly) workarounds (injecting properties could be rather hard).

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombok+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages