本文整理汇总了Java中java.lang.reflect.Parameter.isAnnotationPresent方法的典型用法代码示例。如果您正苦于以下问题:Java Parameter.isAnnotationPresent方法的具体用法?Java Parameter.isAnnotationPresent怎么用?Java Parameter.isAnnotationPresent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Parameter
的用法示例。
在下文中一共展示了Parameter.isAnnotationPresent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareQuery
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private void prepareQuery(JdbcQueryMethod method) {
try {
Method m = (Method) originalMethod.get(method);
if (!m.isAnnotationPresent(Query.class)) {
throw new IllegalStateException("Query annotation not present");
}
this.query = m.getAnnotation(Query.class).value();
parameterKeys = new ArrayList<>(m.getParameterCount());
for (Parameter parameter : m.getParameters()) {
if (parameter.isAnnotationPresent(Param.class)) {
parameterKeys.add(parameter.getAnnotation(Param.class).value());
} else {
parameterKeys.add(null);
}
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
示例2: support
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public boolean support(Parameter param) {
Class<?> vClazz = param.getType();
if (vClazz.isPrimitive() || vClazz == String.class || vClazz == Date.class) {
return param.isAnnotationPresent(Key.class);
}
return false;
}
示例3: findResourceMethods
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
/**
* Find all handler mehtods of the resource.
*
* @param resourceInstance The instance.
*/
private void findResourceMethods(Object resourceInstance) {
for (Method declaredMethod : resourceInstance.getClass().getDeclaredMethods()) {
Path methodPath = declaredMethod.getAnnotation(Path.class);
if (methodPath == null) {
continue;
}
Consumes consumes = declaredMethod.getAnnotation(Consumes.class);
Produces produces = declaredMethod.getAnnotation(Produces.class);
HTTPMethod method = HTTPMethod.GET;
if (declaredMethod.isAnnotationPresent(POST.class)) {
method = HTTPMethod.POST;
} else if (declaredMethod.isAnnotationPresent(DELETE.class)) {
method = HTTPMethod.DELETE;
} else if (declaredMethod.isAnnotationPresent(PUT.class)) {
method = HTTPMethod.PUT;
} else if (declaredMethod.isAnnotationPresent(PATCH.class)) {
method = HTTPMethod.PATCH;
}
ResourceMethod resourceMethod = new ResourceMethod(methodPath.value(), method,
consumes.value(), produces.value(), declaredMethod, resourceInstance);
for (Parameter parameter : declaredMethod.getParameters()) {
if (parameter.isAnnotationPresent(PostKey.class)) {
resourceMethod.addPostParam(parameter.getAnnotation(PostKey.class).value());
}
}
this.resourceMethods.put(methodPath.value(), resourceMethod);
}
}
示例4: supports
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public boolean supports(Parameter parameter) {
return parameter.isAnnotationPresent(Mock.class);
}
示例5: support
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public boolean support(Parameter param) {
return param.isAnnotationPresent(Mapper.class);
}
示例6: injectParameters
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public Object[] injectParameters() throws Throwable {
Object[] args = new Object[methodWrapper.getParamterLength()];
for (int i = 1; i < args.length; i++) {
// 当前方法参数的名称
String paramName = methodWrapper.getParameterName(i);
// 在请求参数中寻找和当前方法形参名相同的对应的参数值
String[] param = paramMap.get(paramName);
// 当前方法的参数对象
Parameter parameter = methodWrapper.getParameter(i);
// 当前方法参数的类型
Class<?> paramType = parameter.getType();
if (paramType == Transfer.class) {
// 操作request 和 session的类
args[i] = new Transfer(wrapper);
}
else if (paramType == Share.class) {
// 文件下载类
args[i] = new Share(wrapper);
}
else if (paramType == Multipart.class) {
// 文件上传的类
args[i] = multipartCheck(contextParameter.getMultipart());
}
else if (parameter.isAnnotationPresent(UrlHolder.class)) {
// 获取到方法参数内的@UrlHolder注解对象
UrlHolder urlVar = parameter.getAnnotation(UrlHolder.class);
// 在map中获取@UrlHolder value()方法中字符串对应的值
String string = contextParameter.getPlaceHolder(paramName);
if (string == null) {
string = contextParameter.getPlaceHolder(urlVar.value());
}
args[i] = BasicUtil.convert(paramType, string);
}
else if (BasicUtil.isCollection(paramType)) { // 当参数为集合时
// 当集合的泛型是primitive时 如 int long 这里也把String当做原生类型
if (BasicUtil.isCommonCollection(parameter.getParameterizedType())) {
args[i] = BasicUtil.convertList(paramType, param);
}
// 当集合的泛型为 除上面之外的其他java对象时
else {
existDateFormatAnnotation(parameter);
args[i] = resultList(parameter.getParameterizedType());
cycleControl();
}
}
else if (BasicUtil.isCommonType(paramType)) { // 当参数为基本类型时
// param数组为空时结束此次循环
if (BasicUtil.notNullAndLenNotZero(param))
continue;
args[i] = BasicUtil.convert(paramType, param[0]);
}
else if (paramType == Date.class) { // 当参数为时间类型时
// param数组为空时结束此次循环
if (BasicUtil.notNullAndLenNotZero(param))
continue;
existDateFormatAnnotation(parameter);
dateFormatCheck(format);
args[i] = DateUtil.resolve(param[0], format);
}
else { // 这里一般表示用户自定义的java对象
existDateFormatAnnotation(parameter);
args[i] = resultSingle(paramType, 0);
cycleControl();
}
}
return args;
}
示例7: isOptional
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private static boolean isOptional(Parameter p) {
return p.isAnnotationPresent(Optional.class);
}
示例8: isSender
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private static boolean isSender(Parameter p) {
return p.isAnnotationPresent(Sender.class) && subclassOf(CommandSender.class, p);
}
示例9: isCommand
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private static boolean isCommand(Parameter p) {
return p.isAnnotationPresent(Command.class) && subclassOf(org.bukkit.command.Command.class, p);
}
示例10: generateOperationsInfos
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private ModelMBeanOperationInfo[] generateOperationsInfos(Class sClass)
{
ArrayList<ModelMBeanOperationInfo> operations = new ArrayList<>();
for (Method method : sClass.getMethods())
{
if (!method.isAnnotationPresent(RemoteMethod.class))
{
continue;
}
RemoteMethod remoteMethod = method.getAnnotation(RemoteMethod.class);
MBeanParameterInfo[] parameterInfos = null;
if (method.getParameters().length > 0)
{
parameterInfos = new MBeanParameterInfo[method.getParameters().length];
int i = 0;
for (Parameter parameter : method.getParameters())
{
String name = parameter.getName();
String description = parameter.getName();
if (parameter.isAnnotationPresent(RemoteParameter.class))
{
RemoteParameter remoteParameter = parameter.getAnnotation(RemoteParameter.class);
name = remoteParameter.name();
description = remoteParameter.description();
}
parameterInfos[i++] = new MBeanParameterInfo(name, parameter.getType().getName(), description);
}
}
ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo(
method.getName(),
remoteMethod.description(),
parameterInfos,
method.getReturnType().getSimpleName(),
remoteMethod.impact());
operations.add(operation);
}
if (operations.size() > 0)
{
return operations.toArray(new ModelMBeanOperationInfo[operations.size()]);
}else {
//No attribute so return null is better
return null;
}
}