-
Notifications
You must be signed in to change notification settings - Fork 273
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
passAnnotations patterns #1513
Comments
Reading this only now, sorry for delayed feedback. I think we can look into expanding current logic with patterns or alike, passAnnotation is definitely a cumbersome solution. wrt to InjectAnnotation. Can you confirm that it wont work if you apply // annotations we want to pass/inject,
// let's say on accessor (getter) and initializer(builder setter) in this example
@interface Cool {}
@interface Great {}
// InjectAnnotation is repeatable annotation
@InjectAnnotation(type = Cool.class, ifPresent = true, target = {Where.ACCESSOR, Where.INITIALIZER})
@InjectAnnotation(type = Great.class, ifPresent = true, target = {Where.ACCESSOR, Where.INITIALIZER})
@interface PassMyAnnotations {}
@Immutable interface Abc {
@Great int a();
@Cool String s();
}
// then put @PassMyAnnotations on either Abc directly or on a whole package.
// I don't remember if it will work placed on the meta-annotated style annotation,
// but it can be (or can be relatively easy to implement)
@PassMyAnnotations
package abc;
// the expected result would be that we will have
// @Great int a() { return this.a; }... @Cool Builder s(String value) { ...
// annotation transferred on "Where" targets.
// See also tests in the `annotate` module for `ifPresent = true` behavior |
@elucash Thanks! This works really well, and also seems to work on package-info.java. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I wanted to get thoughts on a new feature where we would be able to specify patterns (regex?) or at the very least a whole package of annotations to include in passAnnotations.
We have a use case where we are adding meta data to our POJOs via annotations and we need this on the class instance.
The issue we are having is that we are adding a long list of classes to passAnnotations to every class.
I looked into InjectAnnotation but these annotations are also used on non-immutables classes and so it's annoying to have 2 types of annotations to use.
We could also setup a meta-annotation for Value.Style but a lot of these classes have other Style attributes and so this gets overridden.
I'm happy to have a go at implementing this but would love opinions on if this is the best route or if there are other alternatives to consider?
Maybe a better option is to have a meta-annotation to add to ours that tells Immutables to pass it automatically?
Thanks,
Harris
The text was updated successfully, but these errors were encountered: