Calculate a method's hash code considering its method
name, returning type, and its parameter types

@param method a method
@return its hash code
543547
static int getFingerprint(Method method) {
    int hashcode = method.getName().hashCode();
    hashcode =  hashcode + 31*method.getReturnType().getName().hashCode();
    for (Class<?> type : method.getParameterTypes()) {
      hashcode = 31*hashcode ^ type.getName().hashCode();
    }
    return hashcode;
  }
207584
private static boolean isGetterMethod(Method method) {
		return !Modifier.isStatic(method.getModifiers())
			&& (method.getName().startsWith("get") || method.getName().startsWith("is"))
			&& method.getParameterTypes().length == 0;
	}
313312
public static int match(Method[] methods, String name, Type... params) {
        int paramCount = params.length;
        int matchCount = methods.length;
        Method m;

        int[] costs = new int[matchCount];

        // Filter the available methods down to a smaller set, tossing
        // out candidates that could not possibly match because the name
        // differs, and the number of parameters differ. Also eliminate
        // ones in which the parameter types are not compatible at all
        // because no known conversion could be applied.

        int lowestTotalCost = Integer.MAX_VALUE;
        int length = matchCount;
        matchCount = 0;
        for (int i=0; i < length; i++) {
            m = methods[i];
            if (m.isBridge()) { continue; }
            
            if (name == null || m.getName().equals(name)) {
                Class<?>[] methodParams = m.getParameterTypes();
                
                int cnt = methodParams.length;
                if ((cnt == paramCount) || 
                    (m.isVarArgs() && paramCount >= cnt - 1)) {
                    
                    int j = 0;
                    int total = 0;
                    for (; j < paramCount; j++) {
                        MethodParam result = getMethodParameter(m, j, params[j]);
                        Type methodParam = result.type;
                        int cost = methodParam.convertableFrom(params[j], result.vararg);
                        if (cost < 0) { break; }
                        
                        // update total cost
                        total += cost;
                    }

                    if (j == paramCount) {
                        // increase cost for non-use of var args
                        if (m.isVarArgs() && j < methodParams.length) {
                            total++;
                        }
                        
                        costs[matchCount] = total;
                        methods[matchCount++] = m;
                        if (total < lowestTotalCost) {
                            lowestTotalCost = total;
                        }
                    }
                }
            }
        }

        if (matchCount <= 1) {
            return matchCount;
        }

        // Filter out those that have a cost higher than lowestTotalCost.
        length = matchCount;
        matchCount = 0;
        for (int i=0; i < length; i++) {
            if (costs[i] <= lowestTotalCost) {
                costs[matchCount] = costs[i];
                methods[matchCount++] = methods[i];
            }
        }

        if (matchCount <= 1) {
            return matchCount;
        }

        // If one match is non-varargs and remaining are varargs, always choose
        // the non-varargs.
        Method last = null;
        for (int i = 0; i < matchCount; i++) {
            m = methods[i];
            if (!m.isVarArgs()) {
                if (last == null) {
                    last = m;
                }
                else {
                    // multiple non-vararg methods found, so still ambiguous
                    last = null;
                    break;
                }
            }
        }
        
        if (last != null) {
            // ensure first result is set to match
            methods[0] = last;
            
            // return single result
            return 1;
        }
        
        // Filter further by matching parameters with the shortest distance
        // in the hierarchy. This matches each parameter to each matching method
        // to either find the best possible match where the method parameter is
        // the shortest. If multiple matches exist, the parameter is considered
        // ambiguous. If all parameters are ambiguous, then this will return -1
        // as a failiure. If multiple methods match for different parmaters,
        // then the result is also considered ambiguous and -1 returned. For
        // example, the methods:
        //     void doX(String a, Object b)
        //     void doX(Object a, String b)
        // with the method: 
        //     doX("string1", "string2")
        // will best match the first method as String is closer than object but
        // will best match the second method as again String is closer. Thus,
        // the result is ambiguous.

        // maintain the best matching method per parameter
        Method[] paramResults = new Method[paramCount];
        
        // search each parameter separately to find best matching method
        for (int j=0; j<paramCount; j++) {
            Class<?> lastMatch = null;
            Method bestFit = null;
            
            length = matchCount;
            int bestFits = 0;
            
            // search each matching method for the best match. If we have not
            // yet marked a best fit, then we mark the first method. Otherwise,
            // if the next method is closer (ie: the last match is assignable)
            // then we update the best fit. If the last match ever matches
            // the current match, then it is considered ambiguous and the best
            // fit is reset.
            
            for (int i = 0; i < length; i++) {
                m = methods[i];
                if (m.isBridge()) { continue; }
                
                MethodParam result = getMethodParameter(m, j, params[j]);
                Type methodType = result.type;
                Class<?> methodParam = methodType.getNaturalClass();
                
                // TODO: match against generics?
                //java.lang.reflect.Type methodType = methodType.getGeneric();

                Class<?> param = params[j].getNaturalClass();
                if (methodParam.isAssignableFrom(param)) {
                	
                	// check for ambiguity by determining if multiple methods
                	// have same type
                	
                    if (lastMatch != null) {
                        if (lastMatch.equals(methodParam)) {
                            bestFits++;
                        }
                        else { bestFits = 0; }
                    }

                    // if first time through or last match is assignable (ie:
                    // farther away), then update best fit
                    
                    if (lastMatch == null ||
                        lastMatch.isAssignableFrom(methodParam)) {
                        
                        bestFit = m;
                        lastMatch = methodParam;
                    }
                }
            }

            // set best fitting method if single match...otherwise, leave null
            // to denote ambiguous result
            
            if (bestFits == 0) {
            	paramResults[j] = bestFit;
            }
        }
        
        // check if multiple matching methods (ambiguous) or if all params are
        // ambiguous
        
        for (int i = 0; i < paramCount; i++) {
        	// update last match if not yet determined
        	if (last == null) {
        		last = paramResults[i];
        	}
        	
    		// check if non-match (ie: multiple matching methods), and return
        	// ambiguous (-1)
        	else if (!last.equals(paramResults[i])) {
        		return AMBIGUOUS;
        	}
        }
        
        // check if all ambiguous..no matches
        if (last == null) {
        	return AMBIGUOUS;
        }
        
        // ensure first result is set to match
        methods[0] = last;
        
        // return single result
        return 1;
    }
156628
private String getMethodName(Method method) {
        StatName statNameAnnotation = method.getAnnotation(StatName.class);
        return statNameAnnotation != null ? statNameAnnotation.value() : method.getName();
    }
34368
private static boolean isAsyncMethod(Method method) {
        Class<?>[] parameterTypes = method.getParameterTypes();
        for (Class<?> c : parameterTypes)
        {
            if (c.isAssignableFrom(javax.ws.rs.container.AsyncResponse.class))
                return true;
        }
        return false;
    }
469574
@Override
    protected void generateHashCodeMethod(ClassFile proxyClassType) {
        final ClassMethod method = proxyClassType.addMethod(AccessFlag.PUBLIC, HASH_CODE_METHOD, BytecodeUtils.INT_CLASS_DESCRIPTOR);
        final CodeAttribute b = method.getCodeAttribute();
        // MyProxyName.class.hashCode()
        b.loadClass(proxyClassType.getName());
        // now we have the class object on top of the stack
        b.invokevirtual("java.lang.Object", HASH_CODE_METHOD, EMPTY_PARENTHESES + BytecodeUtils.INT_CLASS_DESCRIPTOR);
        // now we have the hashCode
        b.returnInstruction();
    }
971197
public static boolean isEqualsMethod(Method method) {
		if (method == null || false == method.getName().equals("equals")) {
			return false;
		}
		final Class<?>[] paramTypes = method.getParameterTypes();
		return (1 == paramTypes.length && paramTypes[0] == Object.class);
	}
531260
private EJBMethodInfoImpl getEJBMethodInfo(Method method)
    {
        // Get target method signature.
        String targetSignature = MethodAttribUtils.methodSignature(method);

        // Search array of EJBMethodInfo object until the one that matches
        // target signature is found or all array elements are processed.
        EJBMethodInfoImpl minfo = null;
        int n = ivMdbMethods.length;
        for (int i = 0; i < n; ++i)
        {
            minfo = ivMdbMethods[i];
            if (targetSignature.equals(minfo.getMethodSignature()))
            {
                return minfo;
            }
        }

        // Method not found, so return null.
        return null;
    }
1364366
public Method getMethod(Class clz, String mangledMethodName) {

		Map<String, Method> methods = methodsByComponentType.get(clz);

		if (methods == null) {
			methods = new HashMap<String, Method>();
			methodsByComponentType.put(clz, methods);

			for (Method method : clz.getDeclaredMethods()) {
				Class<?>[] param = method.getParameterTypes();
				String mangledName1 = method.getName() + "__" + param.length;
				String mangledName2 = AbstractSkeleton
						.mangleName(method, false);

				if (param.length == 0 || !methods.containsKey(method.getName())) {
					methods.put(method.getName(), method);
				}

				methods.put(mangledName1, method);
				methods.put(mangledName2, method);
			}
		}

		return (Method) methods.get(mangledMethodName);
	}
852853
int getMethodIndex(ExecutableElement method)
    {
        TypeElement declaringClass = (TypeElement) method.getEnclosingElement();
        String fullyQualifiedname = declaringClass.getQualifiedName().toString();
        return getRefIndex(Methodref.class, fullyQualifiedname, method.getSimpleName().toString(), Descriptor.getDesriptor(method));
    }
856482
public ImmutableList<ASTParameter> getParameters(Method method) {
        return getParameters(method.getParameterTypes(), method.getGenericParameterTypes(), method.getParameterAnnotations());
    }
86115
String getCppName(Method method) {
        ClassMapping mapping = mappings.get(method.getDeclaringClass());

        if (mapping != null) {
            String name = method.getName() + "(" + Datatype.generateJNISignature(method.getParameterTypes()) + ")";
            Wrappe wrappedMethod = mapping.getMethods().findWrappe(name);
            if (wrappedMethod != null && !Utils.isNullOrEmpty(wrappedMethod.getCppName())) {
                return wrappedMethod.getCppName();
            }
        }
        Java4CppWrappe annot = method.getAnnotation(Java4CppWrappe.class);
        if (annot != null && !Utils.isNullOrEmpty(annot.value())) {
            return annot.value();
        }
        return mappings.escapeName(method.getName());
    }
431696
function(method){
            method = this.string(method);
            if(methods.indexOf(method.toLowerCase()) < 0){
                throw new TypeError('a method in [' + methods.join(', ') + '] is expected, but ' + method + ' given');
            }
            return method.toLowerCase();
        }
1347499
public static MethodMetadata build(Method method) {
        return new MethodMetadata(method.getName(), method.getDeclaringClass(), method,
            method.getParameterTypes());
    }
763915
public static Type parameterizedRequestType(Method method) {
    if (method != null && method.getGenericParameterTypes().length > 0) {
      Type type = method.getGenericParameterTypes()[0];
      if (type instanceof ParameterizedType) {
        return ((ParameterizedType) type).getActualTypeArguments()[0];
      }
    }

    return Object.class;
  }
568247
private boolean isBoxingMethod(ExecutableElement method) {
    TypeElement declaringClass = ElementUtil.getDeclaringClass(method);
    // Autoboxing methods.
    if (typeUtil.isBoxedType(declaringClass.asType())) {
      String name = ElementUtil.getName(method);
      TypeMirror returnType = method.getReturnType();
      List<? extends VariableElement> params = method.getParameters();
      if (name.equals("valueOf") && params.size() == 1
          && params.get(0).asType().getKind().isPrimitive()) {
        return true;
      }
      if (params.isEmpty() && returnType.getKind().isPrimitive()
          && name.equals(TypeUtil.getName(returnType) + "Value")) {
        return true;
      }
    }
    return false;
  }
842529
public MethodInfo addMethod(Method method) {
        Modifiers modifiers = new Modifiers(method.getModifiers());
        modifiers.setAbstract(this.getModifiers().isInterface());

        TypeVariableDesc[] typeParams = lookupTypeVariables(method);
        TypeDesc ret = TypeDesc.forClass(method.getReturnType(),
                                         method.getGenericReturnType());

        MethodDescriptor methodDescriptor = lookupMethodDescriptor(method);

        Class<?>[] paramClasses = method.getParameterTypes();
        Type[] paramTypes = method.getGenericParameterTypes();
        TypeDesc[] params = new TypeDesc[paramClasses.length];
        String[] paramNames = new String[paramClasses.length];
        for (int i = 0; i < paramClasses.length; i++) {
            params[i] = TypeDesc.forClass(paramClasses[i], paramTypes[i]);
            if(methodDescriptor != null) {
                paramNames[i] =
                    methodDescriptor.getParameterDescriptors()[i].getName();
            } else {
                paramNames[i] = "param$" + i;
            }
        }

        MethodInfo mi = addMethod(modifiers, method.getName(), typeParams,
                                  ret, params, paramNames);

        // exception stuff...
        // TODO: generic exceptions
        Class<?>[] exceptions = method.getExceptionTypes();
        for (int i=0; i<exceptions.length; i++) {
            mi.addException(exceptions[i].getName());
        }

        return mi;
    }