-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Add getRoot() to MergedAnnotation #22818
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
Comments
This proposal is similar to the feature set of As such, I would also find it quite useful to have comparable features in I suppose the mappings would be as follows, but please correct me if my interpretation is wrong.
While looking at that comparison table, however, a few things come to mind.
In general, I think we should take some time to rethink the names of these methods and what they actually return, considering root annotated elements (like a method or class), what it means to be a parent or child, considering that annotation hierarchies are top-down and can have multiple levels, etc. Admittedly, I had a difficult time coming up with the names in |
Regarding the current implementation/naming of @Test
public void getParent() {
MergedAnnotations annotations = MergedAnnotations.from(ComposedTransactionalComponentClass.class);
assertThat(annotations.get(TransactionalComponent.class).getParent().getType())
.isEqualTo(ComposedTransactionalComponent.class);
} That test passes as-is, but I would expect a call to Rationale: in terms of object oriented inheritance terminology, the |
FWIW, I realize now that In any case, let's learn from that and not make the same mistake again. 😉 |
Taking the example from @Transactional
@Retention(RetentionPolicy.RUNTIME)
public @interface MyTransactional { } @MyTransactional
@ContextConfiguration({"/test-datasource.xml", "/repository-config.xml"})
@Retention(RetentionPolicy.RUNTIME)
public @interface RepositoryTests { } @RepositoryTests
public class UserRepositoryTests { } If we do the following: MergedAnnotations<Transactional> annotation = MergedAnnotations.from(UserRepositoryTests.class).get(Transactional.class); The the method results would be:
Yes, currently it does. In earlier versions of the prototype it used to check if it could bypass the method but I dropped that because it didn't seem to make much difference to performance and it made the code a bit more complex. I was also hoping that people wouldn't call
We'll also need to change I think most users of the API want to work with annotations and not really care if they are meta-annotations or not. I think of the parent relationship as breadcrumbs to get you back to the root of the data. I also like that parent maps nicely to depth. So for example, I might be trying to handle
So to put it another way. When I think about Perhaps we should just move away from the parent/child terminology entirely. |
@sbrannen I've added the extra method as is for now. I think we should open another issue if we want to reconsider the method names. |
@philwebb, thanks for providing the examples with the
I disagree with that. We literally have a top-down inheritance hierarchy from
Yes, that is likely the right thing to do for these particular methods. |
Currently
MergedAnnotation
has agetParent()
method but I think it would also be useful to add agetRoot()
method as well. Using the API, I've quite often wanted to show details of the actual user annotation and not the meta-annotation.The text was updated successfully, but these errors were encountered: