org.springframework.core.DefaultParameterNameDiscoverer Java Examples

The following examples show how to use org.springframework.core.DefaultParameterNameDiscoverer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeaderMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setup() {
	@SuppressWarnings("resource")
	GenericApplicationContext cxt = new GenericApplicationContext();
	cxt.refresh();
	this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());

	Method method = ReflectionUtils.findMethod(getClass(), "handleMessage", (Class<?>[]) null);
	this.paramRequired = new SynthesizingMethodParameter(method, 0);
	this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 1);
	this.paramSystemPropertyDefaultValue = new SynthesizingMethodParameter(method, 2);
	this.paramSystemPropertyName = new SynthesizingMethodParameter(method, 3);
	this.paramNotAnnotated = new SynthesizingMethodParameter(method, 4);
	this.paramOptional = new SynthesizingMethodParameter(method, 5);
	this.paramNativeHeader = new SynthesizingMethodParameter(method, 6);

	this.paramRequired.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(this.paramRequired, HeaderMethodArgumentResolver.class);
}
 
Example #2
Source File: MethodBasedSpelExpression.java    From ddal with Apache License 2.0 6 votes vote down vote up
/**
 * DefaultParameterNameDiscoverer is supported spring 4.0
 * @return
 */
private String[] getParameterNames(Method method) {
    if (notSupportParameterNameDiscoverer) {
        return null;
    } else {
        try {
            ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();// only support
            // from spring4
            String[] strs = parameterNameDiscoverer.getParameterNames(method);
            if (strs == null) {
                notSupportParameterNameDiscoverer = true;
            }
            return strs;
        } catch (NoClassDefFoundError e) {
            notSupportParameterNameDiscoverer = true;
            return null;
        }
    }
}
 
Example #3
Source File: HeaderMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
	@SuppressWarnings("resource")
	GenericApplicationContext cxt = new GenericApplicationContext();
	cxt.refresh();
	this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());

	Method method = getClass().getDeclaredMethod("handleMessage",
			String.class, String.class, String.class, String.class, String.class);
	this.paramRequired = new SynthesizingMethodParameter(method, 0);
	this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 1);
	this.paramSystemProperty = new SynthesizingMethodParameter(method, 2);
	this.paramNotAnnotated = new SynthesizingMethodParameter(method, 3);
	this.paramNativeHeader = new SynthesizingMethodParameter(method, 4);

	this.paramRequired.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(this.paramRequired, HeaderMethodArgumentResolver.class);
}
 
Example #4
Source File: AbstractAspectJAdvice.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a ParameterNameDiscoverer to be used for argument binding.
 * <p>The default implementation creates a {@link DefaultParameterNameDiscoverer}
 * and adds a specifically configured {@link AspectJAdviceParameterNameDiscoverer}.
 */
protected ParameterNameDiscoverer createParameterNameDiscoverer() {
	// We need to discover them, or if that fails, guess,
	// and if we can't guess with 100% accuracy, fail.
	DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
	AspectJAdviceParameterNameDiscoverer adviceParameterNameDiscoverer =
			new AspectJAdviceParameterNameDiscoverer(this.pointcut.getExpression());
	adviceParameterNameDiscoverer.setReturningName(this.returningName);
	adviceParameterNameDiscoverer.setThrowingName(this.throwingName);
	// Last in chain, so if we're called and we fail, that's bad...
	adviceParameterNameDiscoverer.setRaiseExceptions(true);
	discoverer.addDiscoverer(adviceParameterNameDiscoverer);
	return discoverer;
}
 
Example #5
Source File: Methods.java    From verifydata with Apache License 2.0 5 votes vote down vote up
public static void addVerify(List<Verify> list, Method method, List<String> parmsType, List<String> parmsName, List<Object> verifyGroup) {
    // 校验组
    verifyGroup.addAll(Arrays.asList(method.getAnnotationsByType(Validation.class)[0].value()));
    // 设置参数名
    DefaultParameterNameDiscoverer defaultParameterNameDiscoverer = new DefaultParameterNameDiscoverer();
    parmsName.addAll(Arrays.asList(defaultParameterNameDiscoverer.getParameterNames(method)));

    Parameter[] parameters = method.getParameters();
    for (int i = 0; i < parameters.length; i++) {
        parmsType.add(parameters[i].getType().getName());
        if (parameters[i].isAnnotationPresent(Verify.class)) list.add(i, parameters[i].getAnnotationsByType(Verify.class)[0]);
        else list.add(null);
    }
}
 
Example #6
Source File: DestinationVariableMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	this.resolver = new DestinationVariableMethodArgumentResolver(new DefaultConversionService());

	Method method = getClass().getDeclaredMethod("handleMessage", String.class, String.class, String.class);
	this.paramAnnotated = new MethodParameter(method, 0);
	this.paramAnnotatedValue = new MethodParameter(method, 1);
	this.paramNotAnnotated = new MethodParameter(method, 2);

	this.paramAnnotated.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(this.paramAnnotated, DestinationVariableMethodArgumentResolver.class);
	this.paramAnnotatedValue.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(this.paramAnnotatedValue, DestinationVariableMethodArgumentResolver.class);
}
 
Example #7
Source File: AbstractAspectJAdvice.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a ParameterNameDiscoverer to be used for argument binding.
 * <p>The default implementation creates a {@link DefaultParameterNameDiscoverer}
 * and adds a specifically configured {@link AspectJAdviceParameterNameDiscoverer}.
 */
protected ParameterNameDiscoverer createParameterNameDiscoverer() {
	// We need to discover them, or if that fails, guess,
	// and if we can't guess with 100% accuracy, fail.
	DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
	AspectJAdviceParameterNameDiscoverer adviceParameterNameDiscoverer =
			new AspectJAdviceParameterNameDiscoverer(this.pointcut.getExpression());
	adviceParameterNameDiscoverer.setReturningName(this.returningName);
	adviceParameterNameDiscoverer.setThrowingName(this.throwingName);
	// Last in chain, so if we're called and we fail, that's bad...
	adviceParameterNameDiscoverer.setRaiseExceptions(true);
	discoverer.addDiscoverer(adviceParameterNameDiscoverer);
	return discoverer;
}
 
Example #8
Source File: AbstractAspectJAdvice.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a ParameterNameDiscoverer to be used for argument binding.
 * <p>The default implementation creates a {@link DefaultParameterNameDiscoverer}
 * and adds a specifically configured {@link AspectJAdviceParameterNameDiscoverer}.
 */
protected ParameterNameDiscoverer createParameterNameDiscoverer() {
	// We need to discover them, or if that fails, guess,
	// and if we can't guess with 100% accuracy, fail.
	DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
	AspectJAdviceParameterNameDiscoverer adviceParameterNameDiscoverer =
			new AspectJAdviceParameterNameDiscoverer(this.pointcut.getExpression());
	adviceParameterNameDiscoverer.setReturningName(this.returningName);
	adviceParameterNameDiscoverer.setThrowingName(this.throwingName);
	// Last in chain, so if we're called and we fail, that's bad...
	adviceParameterNameDiscoverer.setRaiseExceptions(true);
	discoverer.addDiscoverer(adviceParameterNameDiscoverer);
	return discoverer;
}
 
Example #9
Source File: DestinationVariableMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
	this.resolver = new DestinationVariableMethodArgumentResolver(new DefaultConversionService());

	Method method = getClass().getDeclaredMethod("handleMessage", String.class, String.class, String.class);
	this.paramAnnotated = new MethodParameter(method, 0);
	this.paramAnnotatedValue = new MethodParameter(method, 1);
	this.paramNotAnnotated = new MethodParameter(method, 2);

	this.paramAnnotated.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(this.paramAnnotated, DestinationVariableMethodArgumentResolver.class);
	this.paramAnnotatedValue.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(this.paramAnnotatedValue, DestinationVariableMethodArgumentResolver.class);
}
 
Example #10
Source File: AbstractAspectJAdvice.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a ParameterNameDiscoverer to be used for argument binding.
 * <p>The default implementation creates a {@link DefaultParameterNameDiscoverer}
 * and adds a specifically configured {@link AspectJAdviceParameterNameDiscoverer}.
 */
protected ParameterNameDiscoverer createParameterNameDiscoverer() {
	// We need to discover them, or if that fails, guess,
	// and if we can't guess with 100% accuracy, fail.
	DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
	AspectJAdviceParameterNameDiscoverer adviceParameterNameDiscoverer =
			new AspectJAdviceParameterNameDiscoverer(this.pointcut.getExpression());
	adviceParameterNameDiscoverer.setReturningName(this.returningName);
	adviceParameterNameDiscoverer.setThrowingName(this.throwingName);
	// Last in chain, so if we're called and we fail, that's bad...
	adviceParameterNameDiscoverer.setRaiseExceptions(true);
	discoverer.addDiscoverer(adviceParameterNameDiscoverer);
	return discoverer;
}
 
Example #11
Source File: ReflectionAdapterImpl.java    From score with Apache License 2.0 4 votes vote down vote up
public ReflectionAdapterImpl() {
    this.parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
    this.cacheBeans = new ConcurrentHashMap<>();
    this.cacheMethods = new ConcurrentHashMap<>();
    this.cacheParamNames = new ConcurrentHashMap<>();
}
 
Example #12
Source File: Application.java    From evernote-rest-webapp with Apache License 2.0 4 votes vote down vote up
/**
 * To maximize the caching feature in name discoverer, inject as a bean instead of creating every time.
 */
@Bean
public ParameterNameDiscoverer parameterNameDiscoverer() {
	return new DefaultParameterNameDiscoverer();
}
 
Example #13
Source File: RequestParametersSnippetTest.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
private void initParameters(HandlerMethod handlerMethod) {
    for (MethodParameter parameter : handlerMethod.getMethodParameters()) {
        parameter.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
    }
}
 
Example #14
Source File: RequestHeaderSnippetTest.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
private void initParameters(HandlerMethod handlerMethod) {
    for (MethodParameter parameter : handlerMethod.getMethodParameters()) {
        parameter.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
    }
}
 
Example #15
Source File: PathParametersSnippetTest.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
private void initParameters(HandlerMethod handlerMethod) {
    for (MethodParameter parameter : handlerMethod.getMethodParameters()) {
        parameter.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
    }
}
 
Example #16
Source File: AbstractRequestAttributesArgumentResolverTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private MethodParameter initMethodParameter(int parameterIndex) {
	MethodParameter param = new SynthesizingMethodParameter(this.handleMethod, parameterIndex);
	param.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(param, this.resolver.getClass());
	return param;
}
 
Example #17
Source File: SessionAttributeMethodArgumentResolverTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private MethodParameter initMethodParameter(int parameterIndex) {
	MethodParameter param = new SynthesizingMethodParameter(this.handleMethod, parameterIndex);
	param.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(param, this.resolver.getClass());
	return param;
}
 
Example #18
Source File: ApplicationConfig.java    From java-master with Apache License 2.0 4 votes vote down vote up
@Bean
public ParameterNameDiscoverer parameterNameDiscoverer() {
    return new DefaultParameterNameDiscoverer();
}
 
Example #19
Source File: AbstractRequestAttributesArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private MethodParameter initMethodParameter(int parameterIndex) {
	MethodParameter param = new SynthesizingMethodParameter(this.handleMethod, parameterIndex);
	param.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(param, this.resolver.getClass());
	return param;
}
 
Example #20
Source File: SessionAttributeMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private MethodParameter initMethodParameter(int parameterIndex) {
	MethodParameter param = new SynthesizingMethodParameter(this.handleMethod, parameterIndex);
	param.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(param, this.resolver.getClass());
	return param;
}