Пример #1
0
  private int getParamIndexByName(Method method, String paramName) {
    Parameter[] params = method.getParameters();
    for (int i = 0; i < params.length; i++) {
      if (paramName.equals(params[i].getName())) return i;
    }

    return -1;
  }
Пример #2
0
  /**
   * @AfterThrowing( throwing="e" } public void afterThrowing(Throwable e)
   *
   * @param method
   * @return
   */
  private int getAfterThrowingParamIndex(Method method) {
    AfterThrowing annotation = method.getAnnotation(AfterThrowing.class);
    if (annotation != null) {
      String paramName = annotation.throwing().toString();
      return getParamIndexByName(method, paramName);
    }

    return -1;
  }
Пример #3
0
  /** Object[] invocation.getArguments() */
  public Object[] createArgs(
      MethodInvocation invocation, Method method, Object returnValue, Throwable throwingValue) {
    Parameter[] params = method.getParameters();
    Object[] result = new Object[params.length];
    for (int i = 0; i < params.length; i++) {
      Parameter param = params[i];

      if (onlyOneByType(params, param)) {
        result[i] = getArgByType_OnlyOne(invocation, param.getTypeName());
      }
    }

    int paramIndex = this.getReturningParamIndex(method);
    if (paramIndex >= 0) result[paramIndex] = returnValue;

    paramIndex = this.getAfterThrowingParamIndex(method);
    if (paramIndex >= 0) result[paramIndex] = throwingValue;

    return result;
  }