All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.validator.parameternameprovider.ReflectionParameterNameProvider Maven / Gradle / Ivy

Go to download

JPMS Module-Info's for a few of the Jakarta Libraries. These will be removed as time goes by

There is a newer version: 62
Show newest version
/*
 * Hibernate Validator, declare and validate application constraints
 *
 * License: Apache License, Version 2.0
 * See the license.txt file in the root directory or .
 */
package org.hibernate.validator.parameternameprovider;

import static org.hibernate.validator.internal.util.CollectionHelper.newArrayList;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.List;

import jakarta.validation.ParameterNameProvider;

/**
 * @author Khalid Alqinyah
 * @since 5.2
 * @deprecated since 6.0 - getting the parameter names via reflection is now enabled by default. Planned for removal.
 */
@Deprecated
public class ReflectionParameterNameProvider implements ParameterNameProvider {

	@Override
	public List getParameterNames(Constructor constructor) {
		return getParameterNames( constructor.getParameters() );
	}

	@Override
	public List getParameterNames(Method method) {
		return getParameterNames( method.getParameters() );
	}

	private List getParameterNames(Parameter[] parameters) {
		List parameterNames = newArrayList();

		for ( Parameter parameter : parameters ) {
			// If '-parameters' is used at compile time, actual names will be returned. Otherwise, it will be arg0, arg1...
			parameterNames.add( parameter.getName() );
		}

		return parameterNames;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy