/*
 * Copyright 2002-2017 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.core;

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

/**
 * {@link ParameterNameDiscoverer} implementation which uses JDK 8's reflection facilities
 * for introspecting parameter names (based on the "-parameters" compiler flag).
 *
 * @author Juergen Hoeller
 * @since 4.0
 * @see java.lang.reflect.Method#getParameters()
 * @see java.lang.reflect.Parameter#getName()
 */
public class StandardReflectionParameterNameDiscoverer implements ParameterNameDiscoverer {

	@Override
	public String[] getParameterNames(Method method) {
		Parameter[] parameters = method.getParameters();
		String[] parameterNames = new String[parameters.length];
		for (int i = 0; i < parameters.length; i++) {
			Parameter param = parameters[i];
			if (!param.isNamePresent()) {
				return null;
			}
			parameterNames[i] = param.getName();
		}
		return parameterNames;
	}

	@Override
	public String[] getParameterNames(Constructor<?> ctor) {
		Parameter[] parameters = ctor.getParameters();
		String[] parameterNames = new String[parameters.length];
		for (int i = 0; i < parameters.length; i++) {
			Parameter param = parameters[i];
			if (!param.isNamePresent()) {
				return null;
			}
			parameterNames[i] = param.getName();
		}
		return parameterNames;
	}

}

@@ -1235,37 +1235,35 @@
 od) %7B%0A%09%09
-Parameter%5B%5D p
+return getP
 arameter
 s = meth
@@ -1254,20 +1254,22 @@
 arameter
-s = 
+Names(
 method.g
@@ -1274,36 +1274,58 @@
 .getParameters()
+)
 ;%0A%09
-%09
+%7D%0A%0A%09@Override%0A%09public 
 String%5B%5D paramet
@@ -1309,33 +1309,36 @@
 public String%5B%5D 
-p
+getP
 arameterNames = 
@@ -1338,243 +1338,76 @@
 ames
- = new String%5Bparameters.length%5D;%0A%09%09for (int i = 0; i %3C parameters.length; i++) %7B%0A%09%09%09Parameter param = parameters%5Bi%5D;%0A%09%09%09if (!param.isNamePresent()) %7B%0A%09%09%09%09return null;%0A%09%09%09%7D%0A%09%09%09parameterNames%5Bi%5D = param.getName();%0A%09%09%7D%0A%09%09return p
+(Constructor%3C?%3E ctor) %7B%0A%09%09return getParameterNames(ctor.getP
 arameter
 Name
@@ -1406,37 +1406,26 @@
 eter
-Names
+s())
 ;%0A%09%7D%0A%0A%09
-@Override%0A%09public
+private
  Str
@@ -1452,79 +1452,33 @@
 mes(
-Constructor%3C?%3E ctor) %7B%0A%09%09Parameter%5B%5D parameters = ctor.getParameters();
+Parameter%5B%5D parameters) %7B
 %0A%09%09S
@@ -1744,11 +1744,10 @@
 mes;%0A%09%7D%0A
-%0A
 %7D%0A

Refactor duplicated code