/* * Copyright 2002-2014 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 org.jephyr.parameters.ParameterNamesCache; import org.springframework.asm.Type; /** * Implementation of {@link ParameterNameDiscoverer} that uses the LocalVariableTable * information in the method attributes to discover parameter names. Returns * {@code null} if the class file was compiled without debug information. * * <p>Uses ObjectWeb's ASM library for analyzing class files. Each discoverer instance * caches the ASM discovered information for each introspected Class, in a thread-safe * manner. It is recommended to reuse ParameterNameDiscoverer instances as far as possible. * * @author Adrian Colyer * @author Costin Leau * @author Juergen Hoeller * @author Chris Beams * @since 2.0 */ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer { @Override public String[] getParameterNames(Method method) { Class<?> cls = method.getDeclaringClass(); return ParameterNamesCache.getParameterNames(cls.getClassLoader(), Type.getInternalName(cls), method.getName(), Type.getMethodDescriptor(method)); } @Override public String[] getParameterNames(Constructor<?> ctor) { Class<?> cls = ctor.getDeclaringClass(); return ParameterNamesCache.getParameterNames(cls.getClassLoader(), Type.getInternalName(cls), "<init>", Type.getConstructorDescriptor(ctor)); } }