@SuppressWarnings({ "rawtypes", "unchecked" })
@Around("call(@com.amazonaws.services.simpleworkflow.flow.annotations.Asynchronous * *(..)) && @annotation(asynchronousAnnotation)")
public Object makeAsynchronous(ProceedingJoinPoint pjp, Asynchronous asynchronousAnnotation) throws Throwable {
final Signature signature = pjp.getStaticPart().getSignature();
if (signature instanceof MethodSignature) {
final MethodSignature methodSignature = (MethodSignature) signature;
int i = 0;
Object[] methodArguments = pjp.getArgs();
Annotation[][] parameterAnnotations = methodSignature.getMethod().getParameterAnnotations();
List<Promise> valueParams = new ArrayList<Promise>();
for (final Class<?> parameterType : methodSignature.getParameterTypes()) {
if ((isPromise(parameterType) || isPromiseArray(parameterType) || (isCollection(parameterType) && hasWaitAnnotation(parameterAnnotations[i])))
&& !hasNoWaitAnnotation(parameterAnnotations[i])) {
Object param = methodArguments[i];
if (isPromise(parameterType)) {
valueParams.add((Promise) param);