diff --git a/src/main/java/ch/jalu/injector/annotationhandlers/TypeSafeAnnotationHandler.java b/src/main/java/ch/jalu/injector/annotationhandlers/TypeSafeAnnotationHandler.java index b4b038c..546792d 100644 --- a/src/main/java/ch/jalu/injector/annotationhandlers/TypeSafeAnnotationHandler.java +++ b/src/main/java/ch/jalu/injector/annotationhandlers/TypeSafeAnnotationHandler.java @@ -4,23 +4,36 @@ import java.lang.annotation.Annotation; /** - * . + * Type safe annotation handler base, which will fire the resolve method only if + * an annotation of the given type is present. */ public abstract class TypeSafeAnnotationHandler implements AnnotationHandler { @Override - public final Object resolveValue(Annotation... annotations) { + public final Object resolveValue(Class clazz, Annotation... annotations) throws Exception { final Class type = getAnnotationType(); for (Annotation annotation : annotations) { if (type.isInstance(annotation)) { - return resolveValueSafely(type.cast(annotation)); + return resolveValueSafely(clazz, type.cast(annotation)); } } return null; } + /** + * Returns the class of the annotation the handler can process. + * + * @return the annotation type + */ protected abstract Class getAnnotationType(); + /** + * Resolves the value with the matched annotation, guaranteed to never be null. + * + * @param clazz the dependency's type + * @param annotation the matched annotation + * @return the resolved value, or null if none applicable + */ @Nullable - protected abstract Object resolveValueSafely(T annotation); -} + protected abstract Object resolveValueSafely(Class clazz, T annotation) throws Exception; +} \ No newline at end of file