Class<? extends Annotation> annotationType = annotation.annotationType();
Method valueMethod;
try {
valueMethod = annotationType.getDeclaredMethod(value);
} catch (NoSuchMethodException e) {
throw new AnalysisListenerException("Cannot resolve required method '" + value + "()' for '" + annotationType + "'.");
}
Object elementValue;
try {
elementValue = valueMethod.invoke(annotation);
} catch (ReflectiveOperationException e) {
throw new AnalysisListenerException("Cannot invoke method value() for " + annotationType);
}
return elementValue != null ? expectedType.cast(elementValue) : null;
}