Exemple #1
0
  /**
   * Returns the description of a method.
   *
   * @param o object of the method
   * @param methodName name of the method
   * @param params method parameters
   * @return description of the method or <code>null</code> if the requested method could not be
   *     found
   */
  public MethodDescription getMethodDescription(Object o, String methodName, Class... params) {
    ObjectDescription oDesc = getObjectDescription(o);
    MethodDescription result = null;

    ArrayList<Class> paramTypes = new ArrayList<Class>();

    for (Class<?> p : params) {
      //            Class c = p.getClass();
      paramTypes.add(p);
    }

    for (MethodDescription mDesc : oDesc.getMethods()) {
      if (mDesc.getMethodName().equals(methodName)) {
        //                System.out.println("M: " + mDesc.getMethodName());
        boolean isEqual = true;
        for (int i = 0; i < mDesc.getParameterTypes().length; i++) {
          //                    System.out.println(">> P: " +
          //                            mDesc.getParameterTypes()[i].getName());
          //                    System.out.println(">> PE: " + paramTypes.get(i).getName());
          if (!paramTypes.get(i).equals(mDesc.getParameterTypes()[i])) {
            isEqual = false;
            break;
          }
        }
        if (isEqual) {
          result = mDesc;
          result.setParameters(params);

          break;
        }
      }
    }

    //        if (result == null) {
    //            System.err.println(">> MethodDescription not found!"
    //                    + " Wrong name or wrong parameters?");
    //        }

    return result;
  }
Exemple #2
0
  /**
   * Returns the description of a method.
   *
   * @param o object of the method
   * @param methodName name of the method
   * @param params method parameters
   * @return description of the method
   */
  public MethodDescription getMethodDescriptionFromGUI(
      Object o, String methodName, Object... params) {
    ObjectDescription oDesc = getObjectDescription(o);
    MethodDescription result = null;

    //        ArrayList<Class> paramTypes = new ArrayList<Class>();
    //
    //        for (Object p : params) {
    //            Class c = p.getClass();
    //            paramTypes.add(c);
    //        }
    for (MethodDescription mDesc : oDesc.getMethods()) {
      if (mDesc.getMethodName().equals(methodName)) {
        boolean isEqual = true;
        for (int i = 0; i < mDesc.getParameterTypes().length; i++) {

          if (!params[i].equals(mDesc.getParameterTypes()[i])) {
            isEqual = false;
            break;
          }
        }
        if (isEqual) {
          result = mDesc;
          result.setParameters(params);

          break;
        }
      }
    }

    if (result == null) {
      System.out.println(">> MethodDescription not found!" + " Wrong name or wrong parameters?");
    }

    return result;
  }