commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Müller (JIRA) <j...@apache.org>
Subject [jira] [Commented] (LANG-1021) Provide methods to retrieve all fields/methods annotated with a specific type
Date Tue, 08 Jul 2014 08:55:34 GMT

    [ https://issues.apache.org/jira/browse/LANG-1021?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14054669#comment-14054669
] 

Alexander Müller commented on LANG-1021:
----------------------------------------

I agree that putting a method used for retrieving a list of fields/methods makes sense in
{{FieldUtils}}/{{MethodUtils}} but thought that - since no other annotation-specific method
is defined outside {{AnnotationUtils}} - these methods should be in {{AnnotationUtils}} to
keep consistency. If there are plans to add other methods used to retrieve lists of fields/methods,
I'd rather see them in {{FieldUtils}}/{{MethodUtils}}, e.g. {{getMethodsStartingWIth()}} ({{Field[]
getters = gettergetMethodsStartingWith("get")}}.

I really don't have a sophisticated opinion on where to put these methods. I picked the first
criterion I could imagine (consistency: annotation stuff goes to {{AnnotationUtils}}).

> Provide methods to retrieve all fields/methods annotated with a specific type
> -----------------------------------------------------------------------------
>
>                 Key: LANG-1021
>                 URL: https://issues.apache.org/jira/browse/LANG-1021
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.reflect.*
>            Reporter: Alexander Müller
>             Fix For: Review Patch
>
>
> I find myself repeatedly searching for fields (or methods) that are annotated with a
specified annotation like this (field-only example):
> {code}
> List<Field> fieldsWithAnnotation = new ArrayList<>(); 
> Field[] fields = FieldUtils.getAllFields(type);
> for (Field field : fields) {
>     Annotation fieldAnnotation = field.getAnnotation(annotation);
>     if (fieldAnnotation != null) {
>         fieldsWithAnnotation.add(fieldAnnotation);
>     }
> }
> {code}
> Commons Lang could provide these methods:
> {code}
> public Field[] AnnotationUtils.getFieldsWithAnnotation(Annotation annotation);
> public List<Field> AnnotationUtils.getFieldListWithAnnotation(Annotation annotation);
> public Method[] AnnotationUtils.getMethodsWithAnnotation(Annotation annotation);
> public List<Method> AnnotationUtils.getMethodListWithAnnotation(Annotation annotation);
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message