<commit_before>/*
 * Copyright 2004-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.expression.spel.reflection;

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.TypeConverter;
import org.springframework.expression.spel.SpelException;
import org.springframework.expression.spel.SpelMessages;

/**
 * Utility methods used by the reflection resolver code to discover the correct methods/constructors and fields that
 * should be used in expressions.
 * 
 * @author <NAME>
 * 
 */
@SuppressWarnings("unchecked")
public class ReflectionUtils {

	/**
	 * Locate a constructor on a type. There are three kinds of match that might occur:
	 * <ol>
	 * <li>An exact match where the types of the arguments match the types of the constructor
	 * <li>An in-exact match where the types we are looking for are subtypes of those defined on the constructor
	 * <li>A match where we are able to convert the arguments into those expected by the constructor, according to the
	 * registered type converter.
	 * </ol>
	 * 
	 * @param typeConverter a converter that can be used to determine if the supplied arguments can be converted to
	 * expected arguments
	 * @param type the type being searched for a valid constructor
	 * @param argumentTypes the types of the arguments we want the constructor to have
	 * @return a DiscoveredConstructor object or null if non found
	 * @throws SpelException 
	 */
	public static DiscoveredMethod findMethod(TypeConverter typeConverter, String name, Class<?>[] argumentTypes,
			Class<?> type, boolean conversionAllowed) throws SpelException {
		Method[] methods = type.getMethods();
		Method closeMatch = null;
		Integer[] argsToConvert = null;
		boolean multipleOptions = false;
		Method matchRequiringConversion = null;
		for (int i = 0; i < methods.length; i++) {
			Method method = methods[i];
			if (method.isBridge()) {
				continue;
			}
			if (method.getName().equals(name)) {
				ArgumentsMatchInfo matchInfo = null;
				if (method.isVarArgs() && argumentTypes.length>=(method.getParameterTypes().length-1)) {
					// *sigh*  complicated
					matchInfo = compareArgumentsVarargs(method.getParameterTypes(), argumentTypes, typeConverter, conversionAllowed);
				} else if (method.getParameterTypes().length == argumentTypes.length) {
					// name and parameter number match, check the arguments
					matchInfo = compareArguments(method.getParameterTypes(), argumentTypes, typeConverter, conversionAllowed);
				}
				if (matchInfo != null) {
					if (matchInfo.kind == ArgsMatchKind.EXACT) {
						return new DiscoveredMethod(method, null);
					} else if (matchInfo.kind == ArgsMatchKind.CLOSE) {
						if (matchRequiringConversion!=null) {
							int stop = 1;
						}
						closeMatch = method;
					} else if (matchInfo.kind == ArgsMatchKind.REQUIRES_CONVERSION) {
						if (matchRequiringConversion!=null) {
							multipleOptions = true;
						}
						argsToConvert = matchInfo.argsRequiringConversion;
						matchRequiringConversion = method;
					}
				}
			}
		}<commit_msg>Removed unused code<commit_after>/*
 * Copyright 2004-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.expression.spel.reflection;

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.TypeConverter;
import org.springframework.expression.spel.SpelException;
import org.springframework.expression.spel.SpelMessages;

/**
 * Utility methods used by the reflection resolver code to discover the correct methods/constructors and fields that
 * should be used in expressions.
 * 
 * @author <NAME>
 * 
 */
@SuppressWarnings("unchecked")
public class ReflectionUtils {

	/**
	 * Locate a constructor on a type. There are three kinds of match that might occur:
	 * <ol>
	 * <li>An exact match where the types of the arguments match the types of the constructor
	 * <li>An in-exact match where the types we are looking for are subtypes of those defined on the constructor
	 * <li>A match where we are able to convert the arguments into those expected by the constructor, according to the
	 * registered type converter.
	 * </ol>
	 * 
	 * @param typeConverter a converter that can be used to determine if the supplied arguments can be converted to
	 * expected arguments
	 * @param type the type being searched for a valid constructor
	 * @param argumentTypes the types of the arguments we want the constructor to have
	 * @return a DiscoveredConstructor object or null if non found
	 * @throws SpelException 
	 */
	public static DiscoveredMethod findMethod(TypeConverter typeConverter, String name, Class<?>[] argumentTypes,
			Class<?> type, boolean conversionAllowed) throws SpelException {
		Method[] methods = type.getMethods();
		Method closeMatch = null;
		Integer[] argsToConvert = null;
		boolean multipleOptions = false;
		Method matchRequiringConversion = null;
		for (int i = 0; i < methods.length; i++) {
			Method method = methods[i];
			if (method.isBridge()) {
				continue;
			}
			if (method.getName().equals(name)) {
				ArgumentsMatchInfo matchInfo = null;
				if (method.isVarArgs() && argumentTypes.length>=(method.getParameterTypes().length-1)) {
					// *sigh*  complicated
					matchInfo = compareArgumentsVarargs(method.getParameterTypes(), argumentTypes, typeConverter, conversionAllowed);
				} else if (method.getParameterTypes().length == argumentTypes.length) {
					// name and parameter number match, check the arguments
					matchInfo = compareArguments(method.getParameterTypes(), argumentTypes, typeConverter, conversionAllowed);
				}
				if (matchInfo != null) {
					if (matchInfo.kind == ArgsMatchKind.EXACT) {
						return new DiscoveredMethod(method, null);
					} else if (matchInfo.kind == ArgsMatchKind.CLOSE) {
						closeMatch = method;
					} else if (matchInfo.kind == ArgsMatchKind.REQUIRES_CONVERSION) {
						if (matchRequiringConversion!=null) {
							multipleOptions = true;
						}
						argsToConvert = matchInfo.argsRequiringConversion;
						matchRequiringConversion = method;
					}
				}
			}
		}
{'fraction_non_alphanumeric': 0.08657220850123488, 'fraction_numerical': 0.0037696607305342518, 'mean_word_length': 4.061842105263158, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6993411', 'n_tokens_mistral': 2254, 'n_tokens_neox': 1982, 'n_words': 739}