本文整理匯總了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;
}
}