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

Improve method naming in MethodParameter class [SPR-6055] #10724

Closed
spring-projects-issues opened this issue Aug 31, 2009 · 1 comment
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Oliver Drotbohm opened SPR-6055 and commented

Implementing custom WebArgumentResolver s you intensively deal with the @MethodParameter@ parameter you get handed in resolveArgument(..). It's API could need some minor improvements to reduce surprises:

  1. getAnnotations() does not return the annotations of the parameter but the annotations of the method. To access the actual parameter annotations you have to call getParameterAnnotations(). So I'd suggest to let getAnnotations() return the parameter annotations instead, drop getParameterAnnotations() and introduce a getMethodAnnotations() to return the method's annotations.
  2. As in most cases in inspecting parameter annotations you look for a particular type of annotation, it would be cool to be able to simply call some kind of hasAnnotation(Class<? extends Annotation> annotation) or maybe <T extends Annotation> T getAnnotation(Class<T> annotation) to access the annotation directly or get null if the parameter does not contain the an annotation of the given type. This would save the client from extracting all annotations and teadiously iterating over all of them.

Affects: 3.0 M3

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point - getAnnotations isn't very specific there. It's new in 3.0, with getParameterAnnotations being the older one. Consequently, I've renamed getAnnotations to getMethodAnnotations and kept getParameterAnnotations as-is for compatibility purposes (and to clearly indicate the source of the annotations). I've also added getMethodAnnotation(T) and getParameterAnnotation(T) convenience methods.

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants