Exemplo n.º 1
0
  /**
   * *************************************************************************************************
   *
   * <p>*************************************************************************************************
   */
  public static Method geMethodThatBestMatches(
      Class class_i, String methodName_i, Class[] methodParameterTypes_i)
      throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    // determine if we have already found a matching method
    Method method;
    String key =
        class_i + ">" + methodName_i + ":" + ArrayUtils.toString(methodParameterTypes_i, ",");
    synchronized (ReflectionUtils.class) {
      if (ourMethodCache == null) {
        ourMethodCache = new LRUCache(100);
      }

      method = (Method) ourMethodCache.get(key);
    }
    if (method == null) {
      // look for a matching method
      MethodMatcher methodMatcher = new MethodMatcher(class_i);
      method = methodMatcher.findBestMethodMatch(methodName_i, methodParameterTypes_i);
      if (method != null) {
        synchronized (ReflectionUtils.class) {
          ourMethodCache.put(key, method);
        }
      }
    }

    // return the method
    return method;
  }
Exemplo n.º 2
0
    /**
     * ***********************************************************************************************
     */
    private Member findMemberInList(
        String methodName_i, List memberList_i, Class[] methodValueTypes_i)
        throws NoSuchMethodException {
      List matchingMembers = new ArrayList();

      Iterator iterator = memberList_i.iterator();
      while (iterator.hasNext()) {
        Member member = (Member) iterator.next();

        Class[] methodParameterTypes = (Class[]) myMethodToParameterTypesMap.get(member);
        if (Arrays.equals(methodParameterTypes, methodValueTypes_i)) {
          return member;
        }

        if (ReflectionUtils.valuesAreCompatibleWithTypes(
            methodValueTypes_i, methodParameterTypes)) {
          matchingMembers.add(member);
        }
      }

      switch (matchingMembers.size()) {
        case 0:
          throw new NoSuchMethodException(
              myClass.getName()
                  + " has no method "
                  + MethodMatcher.getMethodInvocationKey(methodName_i, methodValueTypes_i));

        case 1:
          return (Member) matchingMembers.get(0);

        default:
          return findMostSpecificMemberIn(matchingMembers);
      }
    }
Exemplo n.º 3
0
    /**
     * ***********************************************************************************************
     */
    public Method findBestMethodMatch(String methodName_i, Class[] methodValueTypes_i)
        throws NoSuchMethodException {
      // look for our list of methods
      List methodList = (List) myMethodToParameterListsMap.get(methodName_i);
      if (methodList == null) {
        throw new NoSuchMethodException(
            myClass.getName()
                + " has no method "
                + MethodMatcher.getMethodInvocationKey(methodName_i, methodValueTypes_i));
      }

      return (Method) findMemberInList(methodName_i, methodList, methodValueTypes_i);
    }
Exemplo n.º 4
0
 /** {@inheritDoc} {@link Method} */
 @Override
 public boolean matches(List<Type> sourceTypes, Type targetType) {
   MethodMatcher matcher = new MethodMatcher(typeUtils, typeFactory, this);
   return matcher.matches(sourceTypes, targetType);
 }
Exemplo n.º 5
0
 /**
  * ***********************************************************************************************
  */
 private static String getMethodInvocationKey(
     String methodName_i, Object[] __methodParameterValues_i) {
   return MethodMatcher.getMethodInvocationKey(
       methodName_i, MethodMatcher.getParameterTypesFrom(__methodParameterValues_i));
 }
Exemplo n.º 6
0
 /**
  * *************************************************************************************************
  *
  * <p>*************************************************************************************************
  */
 public static Class[] getParameterTypes(Object[] __parameters_i) {
   return MethodMatcher.getParameterTypesFrom(__parameters_i);
 }