Uploaded image for project: 'Solder'
  1. Solder
  2. SOLDER-52

Add methods to AnnotationInspector that operate on Annotated (from CDI)

    Details

    • Type: Feature Request
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 3.0.0.Beta1
    • Fix Version/s: 3.0.0.Beta2
    • Component/s: Reflections
    • Labels:
      None
    • Estimated Difficulty:
      Low

      Description

      The AnnotationInspector works on java.lang.reflect.AnnotatedElement types. However, in an extension, you are most often dealing with an Annotated. Therefore, the AnnotationInspector should provide parallel utilities for retrieving/checking an annotation on Annotated or any stereotype on Annotated.

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            dan.j.allen Dan Allen added a comment -

            Proposed methods:

            public static <A extends Annotation> boolean isAnnotationPresent(Annotated annotated, final Class<A> annotationType, BeanManager beanManager)
            {
            if (annotated.isAnnotationPresent(annotationType))

            { return true; }

            for (Annotation candidate : annotated.getAnnotations())
            {
            if (beanManager.isStereotype(candidate.annotationType()))
            {
            for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType()))
            {
            if (stereotyped.annotationType().equals(annotationType))

            { return true; }

            }
            }
            }
            return false;
            }

            public static <A extends Annotation> boolean getAnnotation(Annotated annotated, final Class<A> annotationType, BeanManager beanManager)
            {
            Annotation found = annotated.getAnnotation(annotationType);
            if (found != null)

            { return annotationType.cast(found); }

            for (Annotation candidate : annotated.getAnnotations())
            {
            if (beanManager.isStereotype(candidate.annotationType()))
            {
            for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType()))
            {
            if (stereotyped.annotationType().equals(annotationType))

            { return annotationType.cast(stereotyped); }

            }
            }
            }
            return null;
            }

            Though we should probably expand this to handle three flags:

            1. Only look on Annotated
            2. Look on Annotated or stereotypes
            3. Look on Annotated or as meta-annotation

            There are holes in the scenarios covered by the existing methods as well.

            Show
            dan.j.allen Dan Allen added a comment - Proposed methods: public static <A extends Annotation> boolean isAnnotationPresent(Annotated annotated, final Class<A> annotationType, BeanManager beanManager) { if (annotated.isAnnotationPresent(annotationType)) { return true; } for (Annotation candidate : annotated.getAnnotations()) { if (beanManager.isStereotype(candidate.annotationType())) { for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType())) { if (stereotyped.annotationType().equals(annotationType)) { return true; } } } } return false; } public static <A extends Annotation> boolean getAnnotation(Annotated annotated, final Class<A> annotationType, BeanManager beanManager) { Annotation found = annotated.getAnnotation(annotationType); if (found != null) { return annotationType.cast(found); } for (Annotation candidate : annotated.getAnnotations()) { if (beanManager.isStereotype(candidate.annotationType())) { for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType())) { if (stereotyped.annotationType().equals(annotationType)) { return annotationType.cast(stereotyped); } } } } return null; } Though we should probably expand this to handle three flags: 1. Only look on Annotated 2. Look on Annotated or stereotypes 3. Look on Annotated or as meta-annotation There are holes in the scenarios covered by the existing methods as well.
            Hide
            dan.j.allen Dan Allen added a comment -

            Also, the one annotation finder method on Reflections (getAnnotationsWithMetaAnnotations) should be moved to this class so that they are all in one place (just deprecate and delegate to AnnotationInspector).

            Show
            dan.j.allen Dan Allen added a comment - Also, the one annotation finder method on Reflections (getAnnotationsWithMetaAnnotations) should be moved to this class so that they are all in one place (just deprecate and delegate to AnnotationInspector).
            Hide
            pmuir Pete Muir added a comment -

            In general we only support meta-annotations if the annotation is a stereotype. No reason to change this.

            Show
            pmuir Pete Muir added a comment - In general we only support meta-annotations if the annotation is a stereotype. No reason to change this.
            Hide
            dan.j.allen Dan Allen added a comment -

            Okay, so that makes an even stronger point to align these because currently I'm seeing places where stereotypes are not honored. I embrace the idea of making stereotypes "the" meta-annotation resolver/designator

            So, 1 and 2.

            Show
            dan.j.allen Dan Allen added a comment - Okay, so that makes an even stronger point to align these because currently I'm seeing places where stereotypes are not honored. I embrace the idea of making stereotypes "the" meta-annotation resolver/designator So, 1 and 2.
            Hide
            dan.j.allen Dan Allen added a comment -

            Added support for Annotated in addition to AnnotatedElement. Introduced simpler methods to make searching element + stereotypes (a transitive search). Added methods explicitly named to search annotation amongst stereotypes.

            https://github.com/seam/solder/commit/c1539baf065fafc00d43cb08a76c327fd529b595

            Show
            dan.j.allen Dan Allen added a comment - Added support for Annotated in addition to AnnotatedElement. Introduced simpler methods to make searching element + stereotypes (a transitive search). Added methods explicitly named to search annotation amongst stereotypes. https://github.com/seam/solder/commit/c1539baf065fafc00d43cb08a76c327fd529b595

              People

              • Assignee:
                dan.j.allen Dan Allen
                Reporter:
                dan.j.allen Dan Allen
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development