本文整理汇总了Java中java.lang.reflect.Method.getDeclaredAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java Method.getDeclaredAnnotation方法的具体用法?Java Method.getDeclaredAnnotation怎么用?Java Method.getDeclaredAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Method
的用法示例。
在下文中一共展示了Method.getDeclaredAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extract
import java.lang.reflect.Method; //导入方法依赖的package包/类
private Receipt extract(final Method method) {
// 1. Scan whole Endpoints
final Class<?> clazz = method.getDeclaringClass();
final Annotation annotation = method.getDeclaredAnnotation(Address.class);
final String address = Instance.invoke(annotation, "value");
// 2. Ensure address incoming.
Fn.flingUp(!ADDRESS.contains(address), LOGGER,
AddressWrongException.class,
this.getClass(), address, clazz, method);
final Receipt receipt = new Receipt();
receipt.setMethod(method);
receipt.setAddress(address);
// Fix: Instance class for proxy
final Object proxy = Instance.singleton(clazz);
receipt.setProxy(proxy);
return receipt;
}
示例2: checkRetryVisibilityOnRetryServiceMethodSuppressLevel
import java.lang.reflect.Method; //导入方法依赖的package包/类
@Test
public void checkRetryVisibilityOnRetryServiceMethodSuppressLevel() throws Exception {
Retry foundAnnotation;
Method m = RetryOnClassServiceNoAnnotationOnOveriddenMethod.class.getDeclaredMethod("service");
foundAnnotation = m.getDeclaredAnnotation(Retry.class);
Assert.assertNull(foundAnnotation,
"no Retry annotation should be found on RetryOnClassServiceNoAnnotationOnOveriddenMethod#service() via getDeclaredAnnotation()");
foundAnnotation = m.getAnnotation(Retry.class);
Assert.assertNull(foundAnnotation,
"no Retry annotation should be found on RetryOnClassServiceNoAnnotationOnOveriddenMethod#service() via getAnnotation()");
foundAnnotation = RetryOnClassServiceNoAnnotationOnOveriddenMethod.class.getDeclaredAnnotation(Retry.class);
Assert.assertNull(foundAnnotation,
"no Retry annotation should be found on RetryOnClassServiceNoAnnotationOnOveriddenMethod class via getDeclaredAnnotation()");
foundAnnotation = RetryOnClassServiceNoAnnotationOnOveriddenMethod.class.getAnnotation(Retry.class);
Assert.assertNotNull(foundAnnotation,
"a Retry annotation should have been found because of inheritance on RetryOnClassServiceNoAnnotationOnOveriddenMethod " +
"class via getAnnotation()");
}
示例3: getAnnotation
import java.lang.reflect.Method; //导入方法依赖的package包/类
default <A extends Annotation> A getAnnotation(Class<? extends A> clz) {
Method theMethod = null;
if (Enum.class.isAssignableFrom(getColumnClassType())) {
// For enums, we need to get the annotation from the enum annotated method.
theMethod = GeneratorUtil.getAnnotatedMethodInEnum((Class<? extends Enum<?>>) getColumnClassType()) //
.orElse(null);
} else {
theMethod = getLastAccessorMethod();
}
return theMethod == null ? null : theMethod.isAnnotationPresent(clz) ? theMethod.getDeclaredAnnotation(clz) : null;
}
示例4: initContextForService
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* 为service创建Resty配置
*
* @param serviceClz the service clz
*/
public void initContextForService(Class serviceClz) {
RestyService restyService = (RestyService) serviceClz.getDeclaredAnnotation(RestyService.class);
if (restyService == null) {
return;
}
String serviceName = restyService.serviceName();
// class->@RestyService
this.storeRestyService(serviceClz, restyService);
AsyncHttpClientConfig httpClientConfig = AsyncHttpConfigFactory.createConfig(restyService.connectTimeout(), restyService.requestTimeout());
HttpClientWrapper clientHolder = new HttpClientWrapper(httpClientConfig);
httpClientPool.putIfAbsent(serviceName, clientHolder);
SpringAnnotationWrapper wrapper = new SpringAnnotationWrapper();
RestyCommandConfig commandProperties = new RestyCommandConfig.DefaultRestyCommandConfig();
processRestyServiceAnnotation(restyService, commandProperties);
for (Method method : serviceClz.getMethods()) {
//存储 httpMethod 和 restyCommandConfig
RestyMethod restyMethod = method.getDeclaredAnnotation(RestyMethod.class);
if (restyMethod != null) {
storeRestyMethod(method, restyMethod);
processRestyMethodAnnotation(restyMethod, commandProperties);
}
commandPropertiesMap.putIfAbsent(method, commandProperties);
// 存储 httpMethod 和 requestTemplate
RestyRequestTemplate restyRequestTemplate = wrapper.processAnnotation(serviceClz, method);
requestTemplateMap.putIfAbsent(method, restyRequestTemplate);
serviceMethodTable.put(serviceName, restyRequestTemplate.getPath(), method);
}
log.info("RestyCommandContext初始化成功!");
}
示例5: httpMethodFor
import java.lang.reflect.Method; //导入方法依赖的package包/类
public static HttpMethod httpMethodFor(Method method) {
HttpMethod defaultHttpMethod = HttpMethod.GET;
drinkwater.rest.HttpMethod methodAsAnnotation = method.getDeclaredAnnotation(drinkwater.rest.HttpMethod.class);
if (methodAsAnnotation != null) {
return mapToUnirestHttpMethod(methodAsAnnotation);
}
return List.ofAll(prefixesMap.entrySet())
.filter(prefix -> startsWithOneOf(method.getName(), prefix.getValue()))
.map(entryset -> entryset.getKey())
.getOrElse(defaultHttpMethod);
}
示例6: isIgnoreAnnotation
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* 判断测试方法上是否有@Ignore注解
* @param method 测试方法
* @return 是否有
*/
public static boolean isIgnoreAnnotation(Method method) {
Ignore ignore = method.getDeclaredAnnotation(Ignore.class);
if (ignore == null) {
return false;
}
return true;
}
示例7: MethodSearchFieldMetadata
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Create a new instance.
*
* @param entityType Entity class.
* @param method For this method.
* @param indexTypeRegistry Determine the index type with this lookup.
*/
public MethodSearchFieldMetadata(Class<?> entityType, Method method, IndexTypeRegistry indexTypeRegistry) {
this.entityType = entityType;
this.method = method;
this.indexName = NAME_CALCULATOR.apply(method);
this.encodedName = NAME_ENCODER.apply(indexName);
SearchIndex annotation = method.getDeclaredAnnotation(SearchIndex.class);
if (annotation == null || annotation.type() == IndexType.AUTO) {
this.indexType = indexTypeRegistry.apply(method.getGenericReturnType());
} else {
this.indexType = annotation.type();
}
}
示例8: process
import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public Menu process(Object target) throws ScanException {
Method method = (Method) target;
com.carl.wolf.core.annotation.Menu menu = method.getDeclaredAnnotation(com.carl.wolf.core.annotation.Menu.class);
Menu menuVo = new Menu();
menuVo.setIcon(menu.icon())
.setOrder(menu.order())
.setPath(menu.path())
.setTitle(menu.title())
.setTarget(target)
.setPros(propertiesResolve(menu.pros()));
return menuVo;
}
示例9: registerCommandClass
import java.lang.reflect.Method; //导入方法依赖的package包/类
public void registerCommandClass(Class clazz) {
for (Method method : clazz.getDeclaredMethods()) {
method.setAccessible(true);
Annotation annotation = method.getDeclaredAnnotation(CommandInfo.class);
if (annotation != null) {
this.registerCommandMethod(method, null, (CommandInfo) annotation);
}
}
}
示例10: registerCommandObject
import java.lang.reflect.Method; //导入方法依赖的package包/类
public void registerCommandObject(Object object) {
for (Method method : object.getClass().getDeclaredMethods()) {
method.setAccessible(true);
Annotation annotation = method.getDeclaredAnnotation(CommandInfo.class);
if (annotation != null) {
this.registerCommandMethod(method, object, (CommandInfo) annotation);
}
}
}
示例11: check_BASE_ROM_RETRY_MISSING_ON_METHOD
import java.lang.reflect.Method; //导入方法依赖的package包/类
@Test
public void check_BASE_ROM_RETRY_MISSING_ON_METHOD() throws Exception {
Retry foundAnnotation;
Method m = RetryOnMethodServiceNoAnnotationOnOverridedMethod.class.getDeclaredMethod("service");
foundAnnotation = m.getDeclaredAnnotation(Retry.class);
Assert.assertNull(foundAnnotation,
"no Retry annotation should be found on RetryOnMethodServiceNoAnnotationOnOverridedMethod#service() " +
"via getDeclaredAnnotation()");
foundAnnotation = m.getAnnotation(Retry.class);
Assert.assertNull(foundAnnotation,
"no Retry annotation should be found on RetryOnMethodServiceNoAnnotationOnOverridedMethod#service() via getAnnotation()");
}
示例12: loadMethodLevelCommandSupplier
import java.lang.reflect.Method; //导入方法依赖的package包/类
private void loadMethodLevelCommandSupplier(Class<?> clazz, Map<String, CommandExecutableDetails> map, Object obj)
throws NoSuchMethodException, SecurityException, InterruptedException {
for (Method method : clazz.getDeclaredMethods()) {
if (method.isAnnotationPresent(SshdShellCommand.class)) {
log.debug("{}.#{} is marked with annotation {}", clazz.getName(), method.getName(),
SshdShellCommand.class.getName());
SshdShellCommand command = method.getDeclaredAnnotation(SshdShellCommand.class);
map.put(command.value(), getMethodSupplier(command, method, obj));
}
}
}
示例13: invoke
import java.lang.reflect.Method; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object targetDecoratingObject = null;
Method targetDecoratingMethod = null;
for (Object decoratingMethodObject : decoratingMethodsObjects){
Method[] methods = decoratingMethodObject.getClass().getMethods();
for (Method candidateDecoratingMethod : methods){
if (MethodUtils.equals(candidateDecoratingMethod,method)
&& candidateDecoratingMethod.getDeclaredAnnotations()!=null
&& candidateDecoratingMethod.getDeclaredAnnotation(Decorates.class)!=null){
targetDecoratingMethod = candidateDecoratingMethod;
targetDecoratingObject = decoratingMethodObject;
}
}
}
if (targetDecoratingMethod != null && targetDecoratingObject !=null){
boolean assesible = targetDecoratingMethod.isAccessible();
targetDecoratingMethod.setAccessible(true);
Object value = targetDecoratingMethod.invoke(targetDecoratingObject,args);
targetDecoratingMethod.setAccessible(assesible);
return value;
} else {
return method.invoke(delegateObject,args);
}
}
示例14: PropertyManager
import java.lang.reflect.Method; //导入方法依赖的package包/类
public PropertyManager(Object instance, Field field) {
this.instance = instance;
field.setAccessible(true);
IPropertyAccessor accessor = null;
boolean isFinal = Modifier.isFinal(field.getModifiers());
IPropertyMutator mutator = isFinal ? NOPAccessorAndMutator.INSTANCE : null;
for (Method m : getAllMethods(instance.getClass())) {
if (mutator != null && accessor != null)
break;
m.setAccessible(true);
if (m.getName().equals(String.format("get%s", capitalize(field.getName())))) {
accessor = new MethodAccessorAndMutator(instance, m);
continue;
} else if (!isFinal
&& m.getName().equals(String.format("set%s", capitalize(field.getName())))
&& m.getParameterCount() == 1 && m.getParameterTypes()[0].equals(field.getType())) {
mutator = new MethodAccessorAndMutator(instance, m);
continue;
} else if (m.getDeclaredAnnotation(GetterMethod.class) != null) {
if (m.getDeclaredAnnotation(GetterMethod.class).value().equals(field.getName())) {
accessor = new MethodAccessorAndMutator(instance, m);
continue;
}
} else if (!isFinal && m.getDeclaredAnnotation(SetterMethod.class) != null
&& m.getParameterCount() == 1) {
if (m.getDeclaredAnnotation(SetterMethod.class).value().equals(field.getName())) {
mutator = new MethodAccessorAndMutator(instance, m);
continue;
}
}
}
if (accessor == null)
accessor = new FieldAccessorAndMutator(instance, field);
if (mutator == null)
mutator = new FieldAccessorAndMutator(instance, field);
this.accessor = accessor;
this.mutator = mutator;
this.name = field.getName();
}
示例15: address
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Get event bus address.
*
* @param event
* @return
*/
protected String address(final Event event) {
final Method method = event.getAction();
final Annotation annotation = method.getDeclaredAnnotation(Address.class);
return Instance.invoke(annotation, "value");
}