Introduced DefaultParameterNameDiscoverer which checks JDK 8's standard reflection first and then falls back to ASM-based debug symbol analysis

Also, StandardReflectionParameterNameDiscoverer calls "Parameter.isNamePresent()" now to return null (and pass on to the next discoverer) if no JDK 8 parameters are available. Note that this requires OpenJDK 8 b100 or higher to compile now.

Issue: SPR-10532
This commit is contained in:
Juergen Hoeller
2013-08-07 16:56:45 +02:00
committed by unknown
parent f9325a8376
commit 1420b970a7
13 changed files with 97 additions and 51 deletions

View File

@@ -22,7 +22,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.cache.Cache;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
@@ -46,7 +46,7 @@ class ExpressionEvaluator {
private final SpelExpressionParser parser = new SpelExpressionParser();
// shared param discoverer since it caches data internally
private final ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
private final ParameterNameDiscoverer paramNameDiscoverer = new DefaultParameterNameDiscoverer();
private final Map<String, Expression> keyCache = new ConcurrentHashMap<String, Expression>(64);

View File

@@ -30,7 +30,7 @@ import javax.management.modelmbean.ModelMBeanOperationInfo;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.jmx.support.JmxUtils;
@@ -180,7 +180,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean
private boolean exposeClassDescriptor = false;
private ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
/**
@@ -262,7 +262,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean
/**
* Set the ParameterNameDiscoverer to use for resolving method parameter
* names if needed (e.g. for parameter names of MBean operation methods).
* <p>The default is {@link LocalVariableTableParameterNameDiscoverer}.
* <p>Default is a {@link DefaultParameterNameDiscoverer}.
*/
public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer) {
this.parameterNameDiscoverer = parameterNameDiscoverer;

View File

@@ -42,7 +42,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.MessageSource;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.io.Resource;
import org.springframework.util.ClassUtils;
@@ -93,7 +93,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
private ConstraintValidatorFactory constraintValidatorFactory;
private ParameterNameDiscoverer parameterNameDiscoverer;
private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
private Resource[] mappingLocations;
@@ -161,7 +161,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
/**
* Set the ParameterNameDiscoverer to use for resolving method and constructor
* parameter names if needed for message interpolation.
* <p>Default is a {@link org.springframework.core.LocalVariableTableParameterNameDiscoverer}.
* <p>Default is a {@link org.springframework.core.DefaultParameterNameDiscoverer}.
*/
public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer) {
this.parameterNameDiscoverer = parameterNameDiscoverer;
@@ -269,8 +269,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
Configuration.class.getMethod("parameterNameProvider", parameterNameProviderClass);
final Object defaultProvider = ReflectionUtils.invokeMethod(
Configuration.class.getMethod("getDefaultParameterNameProvider"), configuration);
final ParameterNameDiscoverer discoverer = (this.parameterNameDiscoverer != null ?
this.parameterNameDiscoverer : new LocalVariableTableParameterNameDiscoverer());
final ParameterNameDiscoverer discoverer = this.parameterNameDiscoverer;
Object parameterNameProvider = Proxy.newProxyInstance(getClass().getClassLoader(),
new Class[] {parameterNameProviderClass}, new InvocationHandler() {
@Override