當前位置: 首頁>>代碼示例>>Java>>正文


Java Method.getDeclaredAnnotation方法代碼示例

本文整理匯總了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;
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:21,代碼來源:ReceiptExtractor.java

示例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()");
}
 
開發者ID:eclipse,項目名稱:microprofile-fault-tolerance,代碼行數:23,代碼來源:PureJ2SERetryVisibilityTest.java

示例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;
}
 
開發者ID:eclecticlogic,項目名稱:eclectic-orc,代碼行數:12,代碼來源:GenInfo.java

示例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初始化成功!");
}
 
開發者ID:darren-fu,項目名稱:RestyPass,代碼行數:43,代碼來源:RestyCommandContext.java

示例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);
    }
 
開發者ID:drinkwater-io,項目名稱:drinkwater-java,代碼行數:16,代碼來源:RestHelper.java

示例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;
}
 
開發者ID:DreamYa0,項目名稱:zeratul,代碼行數:13,代碼來源:AnnotationUtils.java

示例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();
    }
}
 
開發者ID:n15g,項目名稱:spring-boot-gae,代碼行數:21,代碼來源:MethodSearchFieldMetadata.java

示例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;
}
 
開發者ID:kawhii,項目名稱:wolf,代碼行數:14,代碼來源:DefaultMenuScanStrategy.java

示例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);
        }
    }
}
 
開發者ID:NekoooGuilds,項目名稱:NekoooGuilds,代碼行數:11,代碼來源:Commands.java

示例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);
        }
    }
}
 
開發者ID:NekoooGuilds,項目名稱:NekoooGuilds,代碼行數:11,代碼來源:Commands.java

示例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()");
}
 
開發者ID:eclipse,項目名稱:microprofile-fault-tolerance,代碼行數:15,代碼來源:PureJ2SERetryVisibilityTest.java

示例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));
        }
    }
}
 
開發者ID:anand1st,項目名稱:sshd-shell-spring-boot,代碼行數:12,代碼來源:SshdShellAutoConfiguration.java

示例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);
        }
    }
 
開發者ID:max089,項目名稱:artdeco,代碼行數:28,代碼來源:DecorationMethodHandler.java

示例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();
}
 
開發者ID:austinv11,項目名稱:ETF-Java,代碼行數:46,代碼來源:ReflectionUtils.java

示例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");
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:12,代碼來源:BaseAim.java


注:本文中的java.lang.reflect.Method.getDeclaredAnnotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。