Ejemplo n.º 1
0
    private Method lookupMethod(
        Object obj, String methodName, Class[] methodParameters, HashMap methodCache) {
      Class objClass = obj.getClass();
      Object objMethod = methodCache.get(objClass);

      if (objMethod == null) {
        return cacheMethod(obj, methodName, methodParameters, methodCache);
      } else if (objMethod == NONE) {
        return null;
      } else {
        return (Method) objMethod;
      }
    }
Ejemplo n.º 2
0
    private Method cacheMethod(
        Object obj, String methodName, Class[] methodParameters, HashMap methodCache) {
      Class objClass = obj.getClass();
      Method objMethod = null;

      // Look up inheritance hierarchy
      while (objClass != Object.class) {
        try {
          objMethod = objClass.getDeclaredMethod(methodName, methodParameters);
          objClass = Object.class; // executed only if call succeeds
        } catch (NoSuchMethodException nsmE) {
          objClass = objClass.getSuperclass();
        }
      }

      // Cache result
      if (objMethod == null) {
        methodCache.put(obj.getClass(), NONE);
      } else {
        objMethod.setAccessible(true); // monstrous, monstrous
        methodCache.put(obj.getClass(), objMethod);
      }
      return objMethod;
    }