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

org.hibernate.validator.internal.engine.DefaultParameterNameProvider Maven / Gradle / Ivy

There is a newer version: 8.0.1.Final
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.internal.engine;

import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.validation.ParameterNameProvider;

/**
 * A default {@link ParameterNameProvider} implementation which returns parameter names obtained from the Java
 * reflection API as mandated by the BV specification.
 *
 * @author Hardy Ferentschik
 * @author Gunnar Morling
 */
public class DefaultParameterNameProvider implements ParameterNameProvider {

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

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

	private List doGetParameterNames(Executable executable) {
		Parameter[] parameters = executable.getParameters();
		List parameterNames = new ArrayList<>( parameters.length );

		for ( Parameter parameter : parameters ) {
			parameterNames.add( parameter.getName() );
		}

		return Collections.unmodifiableList( parameterNames );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy