Setter projection methods may have multiple parameters. One of them may be annotated with
{@link XBValue} to select it as value to be set.

@param method
@return index of fist parameter annotated with {@link XBValue} annotation.
423273
private static int findIndexOfValue(final Method method) {
        int index = 0;
        for (Annotation[] annotations : method.getParameterAnnotations()) {
            for (Annotation a : annotations) {
                if (XBValue.class.equals(a.annotationType())) {
                    return index;
                }
            }
            ++index;
        }
        return 0; // If no attribute is annotated, the first one is taken.
    }
956807
public static Set<String> buildPath(Method method) {
		Class<?> controller = method.getDeclaringClass();

		Set<String> paths = new HashSet<String>();
		Set<String> controllerMapping = new HashSet<String>();
		Set<String> methodMapping = new HashSet<String>();

		if (isAnnotated(controller, RequestMapping.class)) {
			RequestMapping requestMapping = getAnnotation(controller, RequestMapping.class);
			if (valueMapping(requestMapping).length > 0 || pathMapping(requestMapping).length > 0) {
				controllerMapping = new HashSet<String>(Arrays.asList(ObjectArrays.concat(requestMapping.value(), pathMapping(requestMapping), String.class)));
			}
		}

		if (isAnnotated(method, RequestMapping.class)) {
			RequestMapping requestMapping = getAnnotation(method, RequestMapping.class);
			if (requestMapping.value().length > 0 || pathMapping(requestMapping).length > 0) {
				methodMapping = new HashSet<String>(Arrays.asList(ObjectArrays.concat(requestMapping.value(), pathMapping(requestMapping), String.class)));
			}
		}

		// if no path has been specified then adds an empty path to enter the following loop
		if (controllerMapping.isEmpty()) {
			controllerMapping.add("");
		}
		if(methodMapping.isEmpty()) {
			methodMapping.add("");
		}

		for (String controllerPath : controllerMapping) {
			for (String methodPath : methodMapping) {
				String resolvedPath;
				if(needsToJoinWithSlash(controllerPath, methodPath)) {
					resolvedPath = controllerPath + "/" + methodPath;
				} else {
					resolvedPath = controllerPath + methodPath;
				}
				paths.add(resolvedPath);
			}
		}
		
		for (String path : paths) {
			if(path.equals("")) {
				paths.remove(path);
				paths.add("/");
			}
		}

		return paths;
	}
338787
public static Class getMethodGenericReturnType(Method method, int index) {
    	Type returnType = method.getGenericReturnType();
    	if(returnType instanceof ParameterizedType){
    	    ParameterizedType type = (ParameterizedType) returnType;
    	    Type[] typeArguments = type.getActualTypeArguments();
            if (index >= typeArguments.length || index < 0) {
				throw new IllegalArgumentException("index "+ (index<0 ? " must > 0 " : " over total arguments"));
			}
    	    return (Class)typeArguments[index];
    	}
    	return Object.class;
    }
1282236
public static void assertValidSetterName(final Method method, Class<? extends Annotation> annotation)
   {
      final String methodName = method.getName();
      final boolean correctMethodNameLength = methodName.length() > 3;
      final boolean isSetterMethodName = methodName.startsWith("set");
      final boolean isUpperCasedPropertyName = correctMethodNameLength ? Character.isUpperCase(methodName.charAt(3)) : false;

      if (!correctMethodNameLength || !isSetterMethodName || !isUpperCasedPropertyName)
      {
         throw annotation == null ? MESSAGES.methodDoesNotRespectJavaBeanSetterMethodName(method) : MESSAGES.methodDoesNotRespectJavaBeanSetterMethodName2(method, annotation);
      }
   }
757105
public String getName(Method method) {
        String name = getMethodName(method);

        if (method.isAnnotationPresent(JsonProperty.class) &&
            !"".equals(method.getAnnotation(JsonProperty.class).value())) {
            name = method.getAnnotation(JsonProperty.class).value();
        } else if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
            Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
            AnnotationMap annotationMap = buildAnnotationMap(declaredAnnotations);

            int paramsLength = method.getParameterAnnotations().length;
            AnnotationMap[] paramAnnotations = new AnnotationMap[paramsLength];
            for (int i = 0; i < paramsLength; i++) {
                AnnotationMap parameterAnnotationMap = buildAnnotationMap(method.getParameterAnnotations()[i]);
                paramAnnotations[i] = parameterAnnotationMap;
            }

            AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(method.getDeclaringClass(), serializationConfig);
            AnnotatedMethod annotatedField = AnnotatedMethodBuilder.build(annotatedClass, method, annotationMap, paramAnnotations);
            name = serializationConfig.getPropertyNamingStrategy().nameForGetterMethod(serializationConfig, annotatedField, name);
        }
        return name;
    }
853836
static <T extends Annotation> T findAnnotation(Method method, Class<T> clazz) {
		T annotation = AnnotationUtils.findAnnotation(method, clazz);
		if (annotation == null) {
			try {
				annotation = AnnotationUtils.findAnnotation(method.getDeclaringClass()
						.getMethod(method.getName(), method.getParameterTypes()), clazz);
			}
			catch (NoSuchMethodException | SecurityException ex) {
				if (log.isDebugEnabled()) {
					log.debug("Exception occurred while tyring to find the annotation",
							ex);
				}
			}
		}
		return annotation;
	}
1145112
public static List<List<Annotation>> findAndMergeParameterAnnotations(Method method) {
        List<List<Annotation>> res = new ArrayList<List<Annotation>>(method.getParameterTypes().length);
        for (int i = 0; i < method.getParameterTypes().length; i++) {
            res.add(new LinkedList<Annotation>());
        }
        findAndMergeAnnotations(method.getDeclaringClass(), method, res);
        return res;
    }
130971
public MethodDoc getMatchingMethod(MethodDoc method) {

        MethodDoc[] methods = getMethods();
        for (int i = 0; i < methods.length; i++) {

            if (method.getName().equals(methods[i].getName()) &&
                method.getSignature().equals(methods[i].getSignature())) {

                return methods[i];
            }
        }
        return null;
    }
908361
public void setMethod(String method) {
	method = method.toLowerCase();
	if (method.equals("loop")) this.method = MODE_LOOP;
	else if (method.equals("exittag")) this.method = MODE_EXIT_TAG;
	else if (method.equals("exittemplate")) this.method = MODE_EXIT_TEMPLATE;
    }
1121356
@SuppressWarnings("null")
    public static Method getMethod(EvaluationContext ctx, Object base, Object property,
            Class<?>[] paramTypes, Object[] paramValues)
            throws MethodNotFoundException {
        if (base == null || property == null) {
            throw new MethodNotFoundException(MessageFactory.get(
                    "error.method.notfound", base, property,
                    paramString(paramTypes)));
        }

        String methodName = (property instanceof String) ? (String) property
                : property.toString();

        int paramCount;
        if (paramTypes == null) {
            paramCount = 0;
        } else {
            paramCount = paramTypes.length;
        }

        Method[] methods = base.getClass().getMethods();
        Map<Method,MatchResult> candidates = new HashMap<>();

        for (Method m : methods) {
            if (!m.getName().equals(methodName)) {
                // Method name doesn't match
                continue;
            }

            Class<?>[] mParamTypes = m.getParameterTypes();
            //149852 - This was removed due to a findBugs error we felt was worthy of a change.
            //m.getParameterTypes will ALWAYS return an array, it may be of length 0 though
            int mParamCount = mParamTypes.length;

            // Check the number of parameters
            if (!(paramCount == mParamCount ||
                    (m.isVarArgs() && paramCount >= mParamCount))) {
                // Method has wrong number of parameters
                continue;
            }

            // Check the parameters match
            int exactMatch = 0;
            int assignableMatch = 0;
            int coercibleMatch = 0;
            boolean noMatch = false;
            for (int i = 0; i < mParamCount; i++) {
                // Can't be null
                if (mParamTypes[i].equals(paramTypes[i])) {
                    exactMatch++;
                } else if (i == (mParamCount - 1) && m.isVarArgs()) {
                    Class<?> varType = mParamTypes[i].getComponentType();
                    for (int j = i; j < paramCount; j++) {
                        if (isAssignableFrom(paramTypes[j], varType)) {
                            assignableMatch++;
                        } else {
                            if (paramValues == null) {
                                noMatch = true;
                                break;
                            } else {
                                if (isCoercibleFrom(ctx, paramValues[j], varType)) {
                                    coercibleMatch++;
                                } else {
                                    noMatch = true;
                                    break;
                                }
                            }
                        }
                        // Don't treat a varArgs match as an exact match, it can
                        // lead to a varArgs method matching when the result
                        // should be ambiguous
                    }
                } else if (isAssignableFrom(paramTypes[i], mParamTypes[i])) {
                    assignableMatch++;
                } else {
                    if (paramValues == null) {
                        noMatch = true;
                        break;
                    } else {
                        if (isCoercibleFrom(ctx, paramValues[i], mParamTypes[i])) {
                            coercibleMatch++;
                        } else {
                            noMatch = true;
                            break;
                        }
                    }
                }
            }
            if (noMatch) {
                continue;
            }

            // If a method is found where every parameter matches exactly,
            // return it
            if (exactMatch == paramCount) {
                return getMethod(base.getClass(), m);
            }

            candidates.put(m, new MatchResult(
                    exactMatch, assignableMatch, coercibleMatch, m.isBridge()));
        }

        // Look for the method that has the highest number of parameters where
        // the type matches exactly
        MatchResult bestMatch = new MatchResult(0, 0, 0, false);
        Method match = null;
        boolean multiple = false;
        for (Map.Entry<Method, MatchResult> entry : candidates.entrySet()) {
            int cmp = entry.getValue().compareTo(bestMatch);
            if (cmp > 0 || match == null) {
                bestMatch = entry.getValue();
                match = entry.getKey();
                multiple = false;
            } else if (cmp == 0) {
                multiple = true;
            }
        }
        if (multiple) {
            if (bestMatch.getExact() == paramCount - 1) {
                // Only one parameter is not an exact match - try using the
                // super class
                match = resolveAmbiguousMethod(candidates.keySet(), paramTypes);
            } else {
                match = null;
            }

            if (match == null) {
                // If multiple methods have the same matching number of parameters
                // the match is ambiguous so throw an exception
                throw new MethodNotFoundException(MessageFactory.get(
                        "error.method.ambiguous", base, property,
                        paramString(paramTypes)));
                }
        }

        // Handle case where no match at all was found
        if (match == null) {
            throw new MethodNotFoundException(MessageFactory.get(
                        "error.method.notfound", base, property,
                        paramString(paramTypes)));
        }

        return getMethod(base.getClass(), match);
    }
988857
protected String isSetter(final Method<?, ?> method)
   {
      String methodName = method.getName();

      if (!methodName.startsWith(ClassUtils.JAVABEAN_SET_PREFIX))
      {
         return null;
      }

      String propertyName = methodName.substring(ClassUtils.JAVABEAN_SET_PREFIX.length());

      return StringUtils.decapitalize(propertyName);
   }
810608
private IndexedPropertyMethodMetadata<?> getIndexedPropertyMethodMetadata(Collection<MethodMetadata<?, ?>> methodMetadataOfType) {
        for (MethodMetadata methodMetadata : methodMetadataOfType) {
            AnnotatedMethod annotatedMethod = methodMetadata.getAnnotatedMethod();
            Annotation indexedAnnotation = annotatedMethod.getByMetaAnnotation(IndexDefinition.class);
            if (indexedAnnotation != null) {
                if (!(methodMetadata instanceof PrimitivePropertyMethodMetadata)) {
                    throw new XOException("Only primitive properties are allowed to be used for indexing.");
                }
                return new IndexedPropertyMethodMetadata<>((PropertyMethod) annotatedMethod, (PrimitivePropertyMethodMetadata) methodMetadata,
                        metadataFactory.createIndexedPropertyMetadata((PropertyMethod) annotatedMethod));
            }
        }
        return null;
    }
856482
public ImmutableList<ASTParameter> getParameters(Method method) {
        return getParameters(method.getParameterTypes(), method.getGenericParameterTypes(), method.getParameterAnnotations());
    }
325082
public static List<Class> getMethodGenericParameterTypes(Method method, int index) {
    	List<Class> results = new ArrayList<Class>();
    	Type[] genericParameterTypes = method.getGenericParameterTypes();
    	if (index >= genericParameterTypes.length ||index < 0) {
			throw new IllegalArgumentException("index "+ (index<0 ? " must > 0 " : " over total arguments"));
		}
    	Type genericParameterType = genericParameterTypes[index];
    	if(genericParameterType instanceof ParameterizedType){
    	     ParameterizedType aType = (ParameterizedType) genericParameterType;
    	     Type[] parameterArgTypes = aType.getActualTypeArguments();
    	     for(Type parameterArgType : parameterArgTypes){
    	         Class parameterArgClass = (Class) parameterArgType;
    	         results.add(parameterArgClass);
    	     }
    	     return results;
    	}
    	return results;
    }
196211
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationClass) {
        A annotation = method.getAnnotation(annotationClass);
        if (annotation == null) {
            for (Annotation metaAnnotation : method.getAnnotations()) {
                annotation = metaAnnotation.annotationType().getAnnotation(annotationClass);
                if (annotation != null) {
                    return annotation;
                }
            }
            Method superclassMethod = getOverriddenMethod(method);
            if (superclassMethod != null) {
                annotation = getAnnotation(superclassMethod, annotationClass);
            }
        }
        return annotation;
    }
244383
@Override
    public void setMethod(MethodValues method) {
        this.myMethod = method;
        super.setFirstLineChanged();
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(tc, "setMethod(v): " + (null != method ? method.getName() : null));
        }
    }
1167797
public void setMethodDefaults(String method)
  {
        String defaultMethod = m_properties.getProperty(OutputKeys.METHOD);
 
        if((null == defaultMethod) || !defaultMethod.equals(method)
         // bjm - add the next condition as a hack
         // but it is because both output_xml.properties and
         // output_unknown.properties have the same method=xml
         // for their default. Otherwise we end up with
         // a ToUnknownStream wraping a ToXMLStream even
         // when the users says method="xml"
         //
         || defaultMethod.equals("xml")
         )
        {
            Properties savedProps = m_properties;
            Properties newDefaults = 
                OutputPropertiesFactory.getDefaultMethodProperties(method);
            m_properties = new Properties(newDefaults);
            copyFrom(savedProps, false);
        }
  }