Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1021

Provide methods to retrieve all fields/methods annotated with a specific type

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.4
    • lang.reflect.*
    • None

    Description

      I find myself repeatedly searching for fields (or methods) that are annotated with a specified annotation like this (field-only example):

      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);
          }
      }
      

      Commons Lang could provide these methods:

      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);
      

      Attachments

        1. annotatedMethodsAndFields.patch
          15 kB
          Alexander Müller

        Activity

          People

            britter Benedikt Ritter
            alexander.mueller Alexander Müller
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: