Creates a method for a class.
@param object the object to which the method belongs.
@param methodName name of method.
@param parameterTypes an array of parameter types for the method.
@throws NoSuchMethodException if method is not found on object.
762905
public Method createMethod(C object, String methodName, Class[] parameterTypes) throws NoSuchMethodException {
        Class clazz = object.getClass();

        try {
            @SuppressWarnings("unchecked")
            Method method = clazz.getMethod(methodName, parameterTypes);
            return method;

        } catch (NoSuchMethodException nsme) {
            String info = "The specified class " + clazz.getName();
            info += " does not have a method \"" + methodName + "\" as expected: ";
            info += nsme.getMessage();
            throw new NoSuchMethodException(info);
        }
    }
245859
public Node createOptionalParameters(JSType... parameterTypes) {
    FunctionParamBuilder builder = new FunctionParamBuilder(this);
    builder.addOptionalParams(parameterTypes);
    return builder.build();
  }
1155676
public static List<Method> findMethodsByNameAndNumParams(Object object, String method, int numParam) {
        LinkedList<Method> list = new LinkedList<Method>();
        Method[] methods = object.getClass().getMethods();
        for (Method m : methods) {
            String methodName = m.getName();
            if (ignoredMethodNames.indexOf(methodName) > -1) {
                log.debug("Skipping method: {}", methodName);
                continue;
            }
            if (log.isDebugEnabled()) {
                Class<?>[] params = m.getParameterTypes();
                log.debug("Method name: {} parameter count: {}", methodName, params.length);
                for (Class<?> param : params) {
                    log.debug("Parameter: {}", param);
                }
            }
            //check parameter length first since this should speed things up
            if (m.getParameterTypes().length != numParam) {
                log.debug("Param length not the same");
                continue;
            }
            //now try to match the name
            if (!methodName.equals(method)) {
                log.trace("Method name not the same");
                continue;
            }
            list.add(m);
        }
        return list;
    }
462391
public static synchronized void suppressMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes) {
		Method method = null;
		if (parameterTypes.length > 0) {
			method = Whitebox.getMethod(clazz, methodName, parameterTypes);
		} else {
			method = WhiteboxImpl.findMethodOrThrowException(clazz, methodName, parameterTypes);
		}
		MockRepository.addMethodToSuppress(method);
	}
297163
public static boolean methodParamsMatch(List<String> typeNames, Class<?>[] types)
    {
        if (typeNames.size() != types.length)
        {
            return false;
        }

        for (int i = 0; i < types.length; i++)
        {
            String typeName = typeNames.get(i);
            int typeNameEnd = typeName.length();

            Class<?> type = types[i];
            for (; type.isArray(); type = type.getComponentType())
            {
                if (typeNameEnd < 2 ||
                    typeName.charAt(--typeNameEnd) != ']' ||
                    typeName.charAt(--typeNameEnd) != '[')
                {
                    return false;
                }
            }

            if (!type.getName().regionMatches(0, typeName, 0, typeNameEnd))
            {
                return false;
            }
        }

        return true;
    }
831209
private CodeBlock methodCallCodeWithJMapperTypeParameters( MapperInstance instance, ImmutableList<? extends JMapperType> parameters ) {
        CodeBlock.Builder builder = initMethodCallCode( instance );
        return methodCallCodeWithJMapperTypeParameters( builder, parameters );
    }
87123
public static boolean hasMethod(Object obj, String name) {
		if (obj == null)
			throw new NullPointerException("Object cannot be null");
		if (name == null)
			throw new NullPointerException("Method name cannot be null");

		Class<?> objClass = obj.getClass();

		for (Method method : objClass.getMethods()) {
			if (matchMethod(method, name))
				return true;
		}

		return false;
	}
19768
public static Method getMethod(Object target, String methodName, Class... parameterTypes) {
        try {
            return target.getClass().getMethod(methodName, parameterTypes);
        } catch (NoSuchMethodException e) {
            throw handleException(methodName, e);
        }
    }
1123752
public FunctionType createFunctionTypeWithVarArgs(
      JSType returnType, JSType... parameterTypes) {
    return createFunctionType(
        returnType, createParametersWithVarArgs(parameterTypes));
  }
935035
public static Object invoke(Object object, String methodName, Object ... parameters) {
		Method method = getMethodThatMatchesParameters(object.getClass(), methodName, parameters);

		if (method != null) {
			try {
				return method.invoke(object, parameters);
			} catch (IllegalAccessException e) {
				throw new RuntimeException("Unable to invoke method", e);
			} catch (IllegalArgumentException e) {
				throw new RuntimeException("Unable to invoke method", e);
			} catch (InvocationTargetException e) {
				if (e.getCause() instanceof RuntimeException) {
					throw (RuntimeException)e.getCause();
				}

				throw new RuntimeException(e.getCause());
			}
		} else {
			throw new RuntimeException("No method that matches [" + methodName + "] for class " + object.getClass().getSimpleName());
		}
	}
621008
private static boolean implementsMethod(ClassNode classNode, String methodName, Class[] argTypes) {
        List methods = classNode.getMethods();
        if (argTypes == null || argTypes.length ==0) {
            for (Iterator i = methods.iterator(); i.hasNext();) {
                MethodNode mn = (MethodNode) i.next();
                boolean methodMatch = mn.getName().equals(methodName);
                if(methodMatch)return true;
                // TODO Implement further parameter analysis
            }
        }
        return false;
    }
552020
public JMethod getMethod(String name, JClass []paramTypes)
  {
    loop:
    for (JMethod method : getMethods()) {
      if (! method.getName().equals(name))
        continue;

      JClass []mParamTypes = method.getParameterTypes();
      if (mParamTypes.length != paramTypes.length)
        continue;

      for (int i = 0; i < paramTypes.length; i++) {
        if (! paramTypes[i].getName().equals(mParamTypes[i].getName()))
          continue loop;
      }


      return method;
    }

    return null;
  }
455819
public static Method getAccessibleMethod(final Object obj, final String methodName, final Class<?>... parameterTypes) {
		Asserts.notNull(obj, "object cannot be null.");

		for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) {
			try {
				Method method = superClass.getDeclaredMethod(methodName, parameterTypes);
				method.setAccessible(true);
				return method;
			} catch (NoSuchMethodException e) {//NOSONAR
				// Method不在当前类定义,继续向上转型
			}
		}
		return null;
	}
965645
function(object, methods) {
        _.each(methods, function(method, name) {
            if (!_.isFunction(method)) {
                throw new Error('Method "' + name + '" must be a function!');
            }
            object[name] = method
        });
    }
274113
public static Object[] findMethodWithExactParameters(Object service, String methodName, List<?> args) {
        Object[] arguments = new Object[args.size()];
        for (int i = 0; i < args.size(); i++) {
            arguments[i] = args.get(i);
        }
        return findMethodWithExactParameters(service, methodName, arguments);
    }
94218
public static Method  findMethodByArguments(Class<?> targetClass, String methodName, Object[] arguments)
	 throws NoSuchMethodException
	 {

			if(arguments == null || arguments.length == 0)
			{
				return targetClass.getDeclaredMethod(methodName,(Class<?>)null);
			}
			
			Class<?>[] parameterTypes = toParameterTypes(arguments);
			
			return targetClass.getDeclaredMethod(methodName,parameterTypes);
	}
699221
private CodeBlock methodCallCodeWithClassParameters( MapperInstance instance, ImmutableList<? extends JType> parameters ) {
        CodeBlock.Builder builder = initMethodCallCode( instance );
        return methodCallParametersCode( builder, Lists.transform( parameters, new Function<JType, CodeBlock>() {

            @Override
            public CodeBlock apply( JType jType ) {
                return CodeBlock.builder().add( "$T.class", typeName( jType ) ).build();
            }
        } ) );
    }