Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AllArgsConstructor should mark constructor parameters with same annotations that are used for fields #1730

Open
mih-kopylov opened this issue Jun 14, 2018 · 5 comments

Comments

@mih-kopylov
Copy link

Assume a case

@AllArgsConstructor
public class MyClass {
  @NonNull
  private MyService myService;
}

It generates a constructor

public MyClass(@NonNull MyService myService){}

But when myService is annotated with @Qualifier, for example, it isn't passed to constructor parameters.

@AllArgsConstructor
public class MyClass {
  @NonNull
  @Qualifier("myCustomService")
  private MyService myService;
}

I'd like it to be

public MyClass(@NonNull @Qualifier("myCustomService") MyService myService){}
@janrieke
Copy link
Contributor

janrieke commented Jun 14, 2018

Problem is that an annotation may be valid for fields, but not for method parameters. So such a behavior must definitively be made "opt-in" individually for each field/parameter/annotation via the @*ArgsConstructor annotations. This would probably make the syntax quite ugly.

@Maaartinus
Copy link
Contributor

@janrieke Sure, with @*ArgsConstructor, it'd be pretty ugly. With configuration, it'd fine.

The main use case are binding annotations (Spring @Qualifier and Guice @Named) and they can and should always be copied. I can't imagine, why someone would like to control it on a class level. So with a line in config.lombok, it'd done.

I've never seen any other annotation with a simple name Qualifier or Named, so

lombok.constructor.copyToArgument=com.google.guice.Named

or just

lombok.constructor.copyToArgument=Named

should be no problem, even if Lombok can't determine the FQN.

@Enigo
Copy link

Enigo commented Dec 20, 2018

Hey @janrieke , @Maaartinus!
Any progress on this issue?
Or at least maybe some guidelines how to implement it?
Thanks :)

@janrieke
Copy link
Contributor

Did not test it, but this should work in 1.18.4 using the config option lombok.copyableAnnotations.

@Enigo
Copy link

Enigo commented Dec 21, 2018

Thanks @janrieke , it does work!
I assume this ticket might be closed then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants