当前位置: 首页>>代码示例>>Java>>正文


Java LocalVariableTableParameterNameDiscoverer类代码示例

本文整理汇总了Java中org.springframework.core.LocalVariableTableParameterNameDiscoverer的典型用法代码示例。如果您正苦于以下问题:Java LocalVariableTableParameterNameDiscoverer类的具体用法?Java LocalVariableTableParameterNameDiscoverer怎么用?Java LocalVariableTableParameterNameDiscoverer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LocalVariableTableParameterNameDiscoverer类属于org.springframework.core包,在下文中一共展示了LocalVariableTableParameterNameDiscoverer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getVariables

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
/**
 * 获取方法的参数
 *
 * @param context
 * @return
 */
public static List<Param> getVariables(ExtensionContext context) {
    List<Param> list = new ArrayList<Param>();
    Parameter[] Paramters = context.getTestMethod().get().getParameters();
    LocalVariableTableParameterNameDiscoverer u =
            new LocalVariableTableParameterNameDiscoverer();
    String[] params = u.getParameterNames(context.getTestMethod().get());
    for (int i = 0; i < Paramters.length; i++) {
        Param p = new Param();
        p.setName(params[i].trim());
        p.setType(Paramters[i].getType().getSimpleName());
        list.add(p);
    }

    return list;
}
 
开发者ID:ychaoyang,项目名称:autotest,代码行数:22,代码来源:DataDeal.java

示例2: setUp

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	this.resolver = new MatrixVariableMethodArgumentResolver();

	Method method = getClass().getMethod("handle", String.class, List.class, int.class);
	this.paramString = new MethodParameter(method, 0);
	this.paramColors = new MethodParameter(method, 1);
	this.paramYear = new MethodParameter(method, 2);

	this.paramColors.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());

	this.mavContainer = new ModelAndViewContainer();
	this.request = new MockHttpServletRequest();
	this.webRequest = new ServletWebRequest(request, new MockHttpServletResponse());

	Map<String, MultiValueMap<String, String>> params = new LinkedHashMap<String, MultiValueMap<String, String>>();
	this.request.setAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, params);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:MatrixVariablesMethodArgumentResolverTests.java

示例3: testAutowireCandidateWithConstructorDescriptor

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
@Ignore
@Test
public void testAutowireCandidateWithConstructorDescriptor() throws Exception {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
	lbf.registerBeanDefinition(JUERGEN, person1);
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	lbf.registerBeanDefinition(MARK, person2);
	MethodParameter param = new MethodParameter(QualifiedTestBean.class.getDeclaredConstructor(Person.class), 0);
	DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(param, false);
	param.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
	assertEquals("tpb", param.getParameterName());
	assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
	assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
	assertFalse(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:QualifierAnnotationAutowireBeanFactoryTests.java

示例4: getMethodParameters

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
protected List<MethodParameterInfo> getMethodParameters(Method method) {
    ArrayList<MethodParameterInfo> params = new ArrayList<>();

    Class<?>[] parameterTypes = method.getParameterTypes();

    LocalVariableTableParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
    String[] parameterNames = parameterNameDiscoverer.getParameterNames(method);

    if (parameterTypes != null) {
        for (int i = 0; i < parameterTypes.length; i++) {
            String parameterName = parameterNames != null ? parameterNames[i] : "arg" + i;
            MethodParameterInfo parameterInfo = new MethodParameterInfo(parameterTypes[i].getName(), parameterName, null);
            params.add(parameterInfo);
        }
    }
    return params;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:18,代码来源:AbstractBeansMetadata.java

示例5: getSignatures

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
public static String[] getSignatures() {
    List<String> signatures = new ArrayList<String>();
    Method[] methods = ModelAttributeScriptHelper.class.getMethods();
    LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
    for (Method method : methods) {
        if (method.getDeclaringClass().equals(ModelAttributeScriptHelper.class) && Modifier.isPublic(method.getModifiers())
                && !Modifier.isStatic(method.getModifiers())) {
            StringBuilder sig = new StringBuilder(method.getName());
            sig.append("(");
            String[] names = discoverer.getParameterNames(method);
            for (String name : names) {
                sig.append(name);
                sig.append(",");

            }
            if (names.length > 0) {
                sig.replace(sig.length() - 1, sig.length(), ")");
            } else {
                sig.append(")");
            }
            signatures.add(sig.toString());
        }
    }
    Collections.sort(signatures);
    return signatures.toArray(new String[signatures.size()]);
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:27,代码来源:ModelAttributeScriptHelper.java

示例6: setup

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
@SuppressWarnings("resource")
@Before
public void setup() throws Exception {
	DefaultListableBeanFactory dlbf = new DefaultListableBeanFactory();
	dlbf.registerSingleton("mvcValidator", testValidator());
	GenericApplicationContext ctx = new GenericApplicationContext(dlbf);
	ctx.refresh();
	this.resolver = new PayloadArgumentResolver(ctx, new MethodParameterConverter(
			new ObjectMapper(), new GenericConversionService()));
	this.payloadMethod = getClass().getDeclaredMethod("handleMessage", String.class,
			String.class, String.class, String.class, String.class, String.class,
			String.class, Integer.class);

	this.paramAnnotated = getMethodParameter(this.payloadMethod, 0);
	this.paramAnnotatedNotRequired = getMethodParameter(this.payloadMethod, 1);
	this.paramAnnotatedRequired = getMethodParameter(this.payloadMethod, 2);
	this.paramWithSpelExpression = getMethodParameter(this.payloadMethod, 3);
	this.paramValidated = getMethodParameter(this.payloadMethod, 4);
	this.paramValidated.initParameterNameDiscovery(
			new LocalVariableTableParameterNameDiscoverer());
	this.paramValidatedNotAnnotated = getMethodParameter(this.payloadMethod, 5);
	this.paramNotAnnotated = getMethodParameter(this.payloadMethod, 6);
}
 
开发者ID:ralscha,项目名称:wampspring,代码行数:24,代码来源:PayloadArgumentResolverTest.java

示例7: around

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
@Around(value = "", anno = Controller.class)
public Object around(Invocation invocation, ProxyChain proxyChain) {
    Method method = invocation.getMethod();

    BeanContext beanContext = BeanContextManager.get();
    HttpServletRequest request = (HttpServletRequest) beanContext.getBean("HttpServletRequest");
    beanContext.setBean("model", new Model(request), BeanScope.request);

    LocalVariableTableParameterNameDiscoverer u =
            new LocalVariableTableParameterNameDiscoverer();

    Class<?>[] parameterTypes = method.getParameterTypes();
    String[] paramName = u.getParameterNames(method);
    Object[] params = new Object[paramName.length];
    for (int i = 0; i < paramName.length; i++) {
        if (String.class.isAssignableFrom(parameterTypes[i])) {
            params[i] = request.getParameter(paramName[i]);
        } else if (Integer.class.isAssignableFrom(parameterTypes[i]) || int.class.isAssignableFrom(parameterTypes[i])) {
            params[i] = Integer.parseInt(request.getParameter(paramName[i]));
        } else if (Double.class.isAssignableFrom(parameterTypes[i]) || double.class.isAssignableFrom(parameterTypes[i])) {
            params[i] = Double.parseDouble(request.getParameter(paramName[i]));
        } else if (Boolean.class.isAssignableFrom(parameterTypes[i]) || boolean.class.isAssignableFrom(parameterTypes[i])) {
            params[i] = Boolean.parseBoolean(request.getParameter(paramName[i]));
        }
    }

    for (int i = 0; i < parameterTypes.length; i++) {
        System.out.println(parameterTypes[i]);
        if (params[i] == null) {
            params[i] = beanContext.getBean(parameterTypes[i]);
        }
    }

    invocation.setArgs(params);
    return proxyChain.doProxyChain(invocation);
}
 
开发者ID:omsfuk,项目名称:Samurai,代码行数:37,代码来源:ParameterAspect.java

示例8: parseKey

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
/**
 * <p>
 * 获取缓存的key key 定义在注解上,支持SPEL表达式
 * </p>
 *
 * @param args
 * @return key 调用方设置的key
 * @author fulei.yang
 * @date 2016/11/03
 * @version 0.0.1
 */
private String parseKey(String key, Method method, Object[] args) {
    // 获取被拦截方法参数名列表(使用Spring支持类库)
    LocalVariableTableParameterNameDiscoverer localVariableTableParameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
    String[] paraNameArr = localVariableTableParameterNameDiscoverer.getParameterNames(method);
    // 使用SPEL进行key的解析
    ExpressionParser parser = new SpelExpressionParser();
    // SPEL上下文
    StandardEvaluationContext context = new StandardEvaluationContext();
    // 把方法参数放入SPEL上下文中
    for (int i = 0; i < paraNameArr.length; i++) {
        context.setVariable(paraNameArr[i], args[i]);
    }
    return parser.parseExpression(key).getValue(context, String.class);
}
 
开发者ID:wangmeng1314,项目名称:Code-warehouse,代码行数:26,代码来源:CacheValuesOperation.java

示例9: setup

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	this.resolver = new PayloadArgumentResolver(new StringMessageConverter(), testValidator());
	this.payloadMethod = PayloadArgumentResolverTests.class.getDeclaredMethod("handleMessage",
			String.class, String.class, Locale.class, String.class, String.class, String.class, String.class);

	this.paramAnnotated = new SynthesizingMethodParameter(this.payloadMethod, 0);
	this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(this.payloadMethod, 1);
	this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
	this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
	this.paramValidated = new SynthesizingMethodParameter(this.payloadMethod, 4);
	this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
	this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(this.payloadMethod, 5);
	this.paramNotAnnotated = new SynthesizingMethodParameter(this.payloadMethod, 6);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:PayloadArgumentResolverTests.java

示例10: setUp

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	resolver = new RequestParamMethodArgumentResolver(null, true);

	ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();

	Method method = getClass().getMethod("params", String.class, String[].class,
			Map.class, MultipartFile.class, List.class, MultipartFile[].class,
			Part.class, List.class, Part[].class, Map.class,
			String.class, MultipartFile.class, List.class, Part.class,
			MultipartFile.class, String.class, String.class, Optional.class);

	paramNamedDefaultValueString = new SynthesizingMethodParameter(method, 0);
	paramNamedStringArray = new SynthesizingMethodParameter(method, 1);
	paramNamedMap = new SynthesizingMethodParameter(method, 2);
	paramMultipartFile = new SynthesizingMethodParameter(method, 3);
	paramMultipartFileList = new SynthesizingMethodParameter(method, 4);
	paramMultipartFileArray = new SynthesizingMethodParameter(method, 5);
	paramPart = new SynthesizingMethodParameter(method, 6);
	paramPartList  = new SynthesizingMethodParameter(method, 7);
	paramPartArray  = new SynthesizingMethodParameter(method, 8);
	paramMap = new SynthesizingMethodParameter(method, 9);
	paramStringNotAnnot = new SynthesizingMethodParameter(method, 10);
	paramStringNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
	paramMultipartFileNotAnnot = new SynthesizingMethodParameter(method, 11);
	paramMultipartFileNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
	paramMultipartFileListNotAnnot = new SynthesizingMethodParameter(method, 12);
	paramMultipartFileListNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
	paramPartNotAnnot = new SynthesizingMethodParameter(method, 13);
	paramPartNotAnnot.initParameterNameDiscovery(paramNameDiscoverer);
	paramRequestPartAnnot = new SynthesizingMethodParameter(method, 14);
	paramRequired = new SynthesizingMethodParameter(method, 15);
	paramNotRequired = new SynthesizingMethodParameter(method, 16);
	paramOptional = new SynthesizingMethodParameter(method, 17);

	request = new MockHttpServletRequest();
	webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:RequestParamMethodArgumentResolverTests.java

示例11: createModelFactory

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
private ModelFactory createModelFactory(String methodName, Class<?>... parameterTypes) throws Exception{
	Method method = TestController.class.getMethod(methodName, parameterTypes);

	HandlerMethodArgumentResolverComposite argResolvers = new HandlerMethodArgumentResolverComposite();
	argResolvers.addResolver(new ModelMethodProcessor());

	InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(this.controller, method);
	handlerMethod.setHandlerMethodArgumentResolvers(argResolvers);
	handlerMethod.setDataBinderFactory(null);
	handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());

	return new ModelFactory(Arrays.asList(handlerMethod), null, this.sessionAttrsHandler);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ModelFactoryTests.java

示例12: createBinderFactory

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
private WebDataBinderFactory createBinderFactory(String methodName, Class<?>... parameterTypes)
		throws Exception {

	Object handler = new InitBinderHandler();
	Method method = handler.getClass().getMethod(methodName, parameterTypes);

	InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(handler, method);
	handlerMethod.setHandlerMethodArgumentResolvers(argumentResolvers);
	handlerMethod.setDataBinderFactory(new DefaultDataBinderFactory(null));
	handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());

	return new InitBinderDataBinderFactory(Arrays.asList(handlerMethod), bindingInitializer);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:InitBinderDataBinderFactoryTests.java

示例13: testAutowireCandidateWithMethodDescriptor

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
@Ignore
@Test
public void testAutowireCandidateWithMethodDescriptor() throws Exception {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
	lbf.registerBeanDefinition(JUERGEN, person1);
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	lbf.registerBeanDefinition(MARK, person2);
	MethodParameter qualifiedParam =
			new MethodParameter(QualifiedTestBean.class.getDeclaredMethod("autowireQualified", Person.class), 0);
	MethodParameter nonqualifiedParam =
			new MethodParameter(QualifiedTestBean.class.getDeclaredMethod("autowireNonqualified", Person.class), 0);
	DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(qualifiedParam, false);
	DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(nonqualifiedParam, false);
	qualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
	assertEquals("tpb", qualifiedParam.getParameterName());
	nonqualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
	assertEquals("tpb", nonqualifiedParam.getParameterName());
	assertTrue(lbf.isAutowireCandidate(JUERGEN, null));
	assertTrue(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor));
	assertTrue(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor));
	assertTrue(lbf.isAutowireCandidate(MARK, null));
	assertTrue(lbf.isAutowireCandidate(MARK, nonqualifiedDescriptor));
	assertFalse(lbf.isAutowireCandidate(MARK, qualifiedDescriptor));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:QualifierAnnotationAutowireBeanFactoryTests.java

示例14: getMethodParamNames

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
/**
 * 获取参数名列表
 * 
 * @param method
 * @return
 */
public static String[] getMethodParamNames(Method method) {
	// 获取被拦截方法参数名列表(使用Spring支持类库)
	LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer();
	String[] paraNameArr = u.getParameterNames(method);
	return paraNameArr;
}
 
开发者ID:leiyong0326,项目名称:phone,代码行数:13,代码来源:AopUtil.java

示例15: buildKey

import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入依赖的package包/类
/**
 * @param invocation
 * @return
 * @throws NoSuchMethodException
 */
public Object buildKey(String key, ProceedingJoinPoint invocation) throws NoSuchMethodException {

    if (key.indexOf("#") == -1) {// 如果不是表达式,直接返回字符串
        return key;
    }

    String keySpEL = "";
    String pre = "";
    String str[] = key.split("\\#");
    if (str.length > 1) {
        pre = str[0];
        for (int i = 1; i < str.length; i++) {
            keySpEL = keySpEL + "#" + str[i];
        }
    } else keySpEL = key;


    MethodSignature signature = (MethodSignature) invocation.getSignature();
    Method method = signature.getMethod();
    Class<?>[] parameterTypes = method.getParameterTypes();
    ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
    String[] parameterNames = parameterNameDiscoverer.getParameterNames(invocation.getTarget().getClass().getDeclaredMethod(method.getName(), parameterTypes));
    StandardEvaluationContext context = new StandardEvaluationContext();

    for (int i = 0; i < parameterNames.length; i++) {
        context.setVariable(parameterNames[i], invocation.getArgs()[i]);
    }

    Expression expression = expCache.get(keySpEL);
    if (null == expression) {
        expression = parser.parseExpression(keySpEL);
        expCache.put(keySpEL, expression);
    }

    Object value = expression.getValue(context, Object.class);

    if (!StringUtils.isEmpty(pre)) return pre + value;
    else return value;

}
 
开发者ID:jayqqaa12,项目名称:jbase,代码行数:46,代码来源:SpelKeyGenerator.java


注:本文中的org.springframework.core.LocalVariableTableParameterNameDiscoverer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。