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
- blocks
-
SOLDER-158
Honor the use of HandlesExceptions on a stereotype
-
- Resolved
-
-
SOLDER-165
Remove isAnnotationPresent from CatchExtension once available in Solder
-
- Resolved
-
Proposed methods:
public static <A extends Annotation> boolean isAnnotationPresent(Annotated annotated, final Class<A> annotationType, BeanManager beanManager)
{ return true; }{
if (annotated.isAnnotationPresent(annotationType))
for (Annotation candidate : annotated.getAnnotations())
{ return true; }{
if (beanManager.isStereotype(candidate.annotationType()))
{
for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType()))
{
if (stereotyped.annotationType().equals(annotationType))
}
}
}
return false;
}
public static <A extends Annotation> boolean getAnnotation(Annotated annotated, final Class<A> annotationType, BeanManager beanManager)
{ return annotationType.cast(found); }{
Annotation found = annotated.getAnnotation(annotationType);
if (found != null)
for (Annotation candidate : annotated.getAnnotations())
{ return annotationType.cast(stereotyped); }{
if (beanManager.isStereotype(candidate.annotationType()))
{
for (Annotation stereotyped : beanManager.getStereotypeDefinition(candidate.annotationType()))
{
if (stereotyped.annotationType().equals(annotationType))
}
}
}
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.