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

Honor the use of HandlesExceptions on a stereotype

    Details

    • Type: Feature Request
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.0.0.Beta1
    • Component/s: Core
    • Labels:
      None

      Description

      The HandlesExceptions should be permitted on a stereotype so annotations can be consolidated.

        Gliffy Diagrams

          Issue Links

            Activity

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

            Add this utility method to CatchExtension (should be pushed into Solder eventually)

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

            Then replace the line that checks for HandlesExceptions

            if (isAnnotationPresent(type, HandlesExceptions.class, bm))

            Here are two classes to use for a test

            @HandlesExceptions
            @Stereotype
            @Target(

            { TYPE }

            )
            @Retention(RUNTIME)
            @Documented
            public @interface GetYourHandlersHere {}

            @GetYourHandlersHere
            public class StereotypedExceptionHandler
            {
            public void handlesAll(@Handles CaughtException<Throwable> caught)
            {
            }
            }

            Show
            dan.j.allen Dan Allen added a comment - Add this utility method to CatchExtension (should be pushed into Solder eventually) 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; } Then replace the line that checks for HandlesExceptions if (isAnnotationPresent(type, HandlesExceptions.class, bm)) Here are two classes to use for a test @HandlesExceptions @Stereotype @Target( { TYPE } ) @Retention(RUNTIME) @Documented public @interface GetYourHandlersHere {} @GetYourHandlersHere public class StereotypedExceptionHandler { public void handlesAll(@Handles CaughtException<Throwable> caught) { } }
            Hide
            dan.j.allen Dan Allen added a comment -

            An open question is whether to support HandlesExceptions as a meta-annotation on any annotation, or just on a stereotype.

            Show
            dan.j.allen Dan Allen added a comment - An open question is whether to support HandlesExceptions as a meta-annotation on any annotation, or just on a stereotype.
            Hide
            dan.j.allen Dan Allen added a comment -

            It turns out Solder already supports this, just not as a single method. Currently, the supported logic is:

            if (AnnotationInspector.isAnnotationPresent(type, HandlesExceptions.class, false, bm) ||
            AnnotationInspector.isAnnotationPresent(type, HandlesExceptions.class, true, bm)) {
            ...
            }

            The false means only look on the element (the type) and the true means only look for it on the stereotypes. I'll enhance Solder to have a more intuitive method.

            Show
            dan.j.allen Dan Allen added a comment - It turns out Solder already supports this, just not as a single method. Currently, the supported logic is: if (AnnotationInspector.isAnnotationPresent(type, HandlesExceptions.class, false, bm) || AnnotationInspector.isAnnotationPresent(type, HandlesExceptions.class, true, bm)) { ... } The false means only look on the element (the type) and the true means only look for it on the stereotypes. I'll enhance Solder to have a more intuitive method.
            Hide
            dan.j.allen Dan Allen added a comment -
            Show
            dan.j.allen Dan Allen added a comment - https://github.com/seam/catch/pull/12

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development