本文整理汇总了Java中org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames方法的典型用法代码示例。如果您正苦于以下问题:Java LocalVariableTableParameterNameDiscoverer.getParameterNames方法的具体用法?Java LocalVariableTableParameterNameDiscoverer.getParameterNames怎么用?Java LocalVariableTableParameterNameDiscoverer.getParameterNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.core.LocalVariableTableParameterNameDiscoverer
的用法示例。
在下文中一共展示了LocalVariableTableParameterNameDiscoverer.getParameterNames方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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;
}
示例3: 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()]);
}
示例4: 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);
}
示例5: 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);
}
示例6: 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;
}
示例7: getConstructorNames
import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入方法依赖的package包/类
public static String[] getConstructorNames(Constructor<?> targetConstructor){
LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
return discoverer.getParameterNames(targetConstructor);
}
示例8: getApiParamMetaByASM
import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入方法依赖的package包/类
/**
* 通过ASM方式获得方法参数信息
* @param apiMethod
* @return
*/
private static ApiParamMeta[] getApiParamMetaByASM(Method apiMethod) {
LocalVariableTableParameterNameDiscoverer parameterNameDiscoverer =
new LocalVariableTableParameterNameDiscoverer();
String[] names = parameterNameDiscoverer.getParameterNames(apiMethod);
if (names != null) {
ApiParamMeta[] apiParamMetas = new ApiParamMeta[names.length];
for (int i = 0; i < names.length; i++) {
apiParamMetas[i] = new ApiParamMeta(names[i]);
}
return apiParamMetas;
}
return null;
}
示例9: getParamNames
import org.springframework.core.LocalVariableTableParameterNameDiscoverer; //导入方法依赖的package包/类
/**
* 获取方法的参数名
* @param method 方法
* @return 方法名称数组
*/
public static String[] getParamNames(Method method) {
LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer();
return u.getParameterNames(method);
}