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


Java Method.getDeclaredAnnotations方法代碼示例

本文整理匯總了Java中java.lang.reflect.Method.getDeclaredAnnotations方法的典型用法代碼示例。如果您正苦於以下問題:Java Method.getDeclaredAnnotations方法的具體用法?Java Method.getDeclaredAnnotations怎麽用?Java Method.getDeclaredAnnotations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.getDeclaredAnnotations方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateMethodMap

import java.lang.reflect.Method; //導入方法依賴的package包/類
private void generateMethodMap() {
  if(WXEnvironment.isApkDebugable()) {
    WXLogUtils.d(TAG, "extractMethodNames:" + mClazz.getSimpleName());
  }
  ArrayList<String> methods = new ArrayList<>();
  HashMap<String, Invoker> methodMap = new HashMap<>();
  try {
    for (Method method : mClazz.getMethods()) {
      // iterates all the annotations available in the method
      for (Annotation anno : method.getDeclaredAnnotations()) {
        if (anno != null && anno instanceof WXModuleAnno) {
          methods.add(method.getName());
          methodMap.put(method.getName(), new MethodInvoker(method));
          break;
        }
      }
    }
  } catch (Throwable e) {
    WXLogUtils.e("[WXModuleManager] extractMethodNames:", e);
  }
  mMethods = methods;
  mMethodMap = methodMap;
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:24,代碼來源:TypeModuleFactory.java

示例2: getName

import java.lang.reflect.Method; //導入方法依賴的package包/類
protected Optional<String> getName(Method method) {
	ObjectMapper objectMapper = context.getObjectMapper();
	SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
	if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
		String name = ClassUtils.getGetterFieldName(method);
		Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
		AnnotationMap annotationMap = buildAnnotationMap(declaredAnnotations);

		int paramsLength = method.getParameterAnnotations().length;
		AnnotationMap[] paramAnnotations = new AnnotationMap[paramsLength];
		for (int i = 0; i < paramsLength; i++) {
			AnnotationMap parameterAnnotationMap = buildAnnotationMap(method.getParameterAnnotations()[i]);
			paramAnnotations[i] = parameterAnnotationMap;
		}

		AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(method.getDeclaringClass(), serializationConfig);
		AnnotatedMethod annotatedField = AnnotatedMethodBuilder.build(annotatedClass, method, annotationMap, paramAnnotations);
		return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForGetterMethod(serializationConfig, annotatedField, name));
	}
	return Optional.empty();
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:22,代碼來源:JacksonResourceFieldInformationProvider.java

示例3: resolve

import java.lang.reflect.Method; //導入方法依賴的package包/類
public static HttpMethod resolve(final Method method) {
    // 1. Method checking.
    Fn.flingUp(null == method, LOGGER,
            MethodNullException.class, MethodResolver.class);
    final Annotation[] annotations = method.getDeclaredAnnotations();
    // 2. Method ignore
    HttpMethod result = null;
    for (final Annotation annotation : annotations) {
        final Class<?> key = annotation.annotationType();
        if (METHODS.containsKey(key)) {
            result = METHODS.get(key);
            break;
        }
    }
    // 2. Ignore this method.
    if (null == result) {
        LOGGER.info(Info.METHOD_IGNORE, method.getName());
    }
    return result;
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:21,代碼來源:MethodResolver.java

示例4: addLoader

import java.lang.reflect.Method; //導入方法依賴的package包/類
public void addLoader(Class<?> loaderClass) {
    try {
        for (Method method : loaderClass.getMethods())
            for (Annotation annotation : method.getDeclaredAnnotations())
                if (annotation.annotationType().equals(Load.class))
                    if (method.getParameterCount() == 0 || (FMLStateEvent.class.isAssignableFrom(method.getParameterTypes()[0]) && method.getParameterTypes()[0].equals(((Load) annotation).value().getEvent().getClass()))) {
                        Collection<Method> methods = stateLoaderMap.getOrDefault(((Load) annotation).value(), new ArrayList<>());
                        if (!methods.contains(method))
                            methods.add(method);
                        stateLoaderMap.put(((Load) annotation).value(), methods);
                    }
        loaderInstanceMap.put(loaderClass, loaderClass.newInstance());
    } catch (Exception e) {
        FoodCraftReloaded.getLogger().warn("Un-able to register loader " + loaderClass.getName(), e);
    }
}
 
開發者ID:LasmGratel,項目名稱:FoodCraft-Reloaded,代碼行數:17,代碼來源:LoaderManager.java

示例5: collectAnnotations

import java.lang.reflect.Method; //導入方法依賴的package包/類
private Map<Class<? extends Annotation>, Annotation> collectAnnotations(Iterable<Method> methods) {
    Map<Class<? extends Annotation>, Annotation> annotations = Maps.newLinkedHashMap();
    for (Method method : methods) {
        for (Annotation annotation : method.getDeclaredAnnotations()) {
            // Make sure more specific annotation doesn't get overwritten with less specific one
            if (!annotations.containsKey(annotation.annotationType())) {
                annotations.put(annotation.annotationType(), annotation);
            }
        }
    }
    return Collections.unmodifiableMap(annotations);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:13,代碼來源:PropertyAccessorExtractionContext.java

示例6: invokeAnnotationByMethod

import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
 * Invokes the annotation of the given method
 *
 * @param method          method
 * @param annotationClazz annotation
 * @param <T>             returnType
 * @return returnValue
 */
public static <T extends Annotation> T invokeAnnotationByMethod(Method method, Class<T> annotationClazz) {
    if (method == null)
        throw new IllegalArgumentException("Method cannot be null!");
    if (annotationClazz == null)
        throw new IllegalArgumentException("AnnotationClass cannot be null!");
    for (final Annotation annotation : method.getDeclaredAnnotations()) {
        if (annotation.annotationType() == annotationClazz)
            return (T) annotation;
    }
    return null;
}
 
開發者ID:Shynixn,項目名稱:PetBlocks,代碼行數:20,代碼來源:ReflectionUtils.java

示例7: EventEar

import java.lang.reflect.Method; //導入方法依賴的package包/類
public EventEar(Object declaringInstance, Class<?> eventType, Class<?> eventClass, Method method) {
    this.declaringInstance = declaringInstance;
    this.eventType = eventType;
    this.eventClass = eventClass;
    this.method = method;

    for(Annotation a : method.getDeclaredAnnotations()) {
        for(Method m : a.getClass().getMethods()) {
            if(m.getName().equals(PRIORITY_METHOD)) {
                priority = (EventPriority) ReflectionUtil.invokeMethod(m, a);
            }
        }
    }
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:15,代碼來源:EventEar.java

示例8: JavaCompilerUtils

import java.lang.reflect.Method; //導入方法依賴的package包/類
public JavaCompilerUtils(String name) throws ClassNotFoundException {
    Class clazz = this.getClass().getClassLoader().loadClass(name);

    Method[] methods = clazz.getDeclaredMethods();
    List<String> methodList = new ArrayList<>();
    for (Method method : methods){
        String param = new String();
        for (Class paramClass : method.getParameterTypes()){
            param += paramClass.getName()+", ";
        }
        String temp = "";
        if(param.length()>0){
            temp = method.getName()+" ("+param.substring(0, param.length()-2)+")<br>";
        }else{
            temp = method.getName()+" ()<br>";
        }
        if(method.getDeclaredAnnotations().length>0){
            Annotation[] t = method.getDeclaredAnnotations();
            for (Annotation tt : t){
                if (tt.annotationType().equals(java.lang.Deprecated.class)){
                    temp = "@Deprecated "+temp;
                }
            }
        }
        methodList.add(temp);
    }
    methodList = methodList.stream().sorted().collect(Collectors.toList());
    methodList.forEach(item ->{
        System.out.println(item);
    });

}
 
開發者ID:caoyj1991,項目名稱:Core-Java,代碼行數:33,代碼來源:JavaCompilerUtils.java

示例9: listAPIs

import java.lang.reflect.Method; //導入方法依賴的package包/類
public void listAPIs() {
    Iterator it = apis.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();

        API p = (API) pairs.getValue();
        Method[] methods = p.methods;

        for (Method m : methods) {
            // get class and method
            MLog.d(TAG, pairs.getKey() + " = " + m.getName());

            Annotation[] annotations = m.getDeclaredAnnotations();

            for (Annotation annotation2 : annotations) {

                MLog.d(TAG, annotation2.toString() + " " + annotation2.annotationType().getSimpleName() + " "
                        + ProtoMethod.class.getSimpleName());

                if (annotation2.annotationType().getSimpleName().equals(ProtoMethod.class.getSimpleName())) {
                    String desc = ((ProtoMethod) annotation2).description();
                    String example = ((ProtoMethod) annotation2).example();
                    MLog.d(TAG, desc);
                }
            }

        }
        it.remove(); // avoids mContext ConcurrentModificationException
    }

}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:32,代碼來源:APIManager.java

示例10: searchPageAnnotation

import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
 * 如果切點方法有使用 @AutoPage 注解,則依照注解說明去取參數
 * */
private void searchPageAnnotation(Object[] args, Integer[] params, Method targetMethod) {
    Annotation[] annotations = targetMethod.getDeclaredAnnotations();
    for (Annotation annotation : annotations){
        if (annotation instanceof AutoPage){
            AutoPage page = (AutoPage) annotation;
            if (page.value()){
                params[0] = (Integer) args[page.pageNum()];
                params[1] = (Integer) args[page.pageSize()];
            }
            return;
        }
    }
}
 
開發者ID:weiwei02,項目名稱:Yoghurt,代碼行數:17,代碼來源:SelectPageFilter.java

示例11: getOnEventMethod

import java.lang.reflect.Method; //導入方法依賴的package包/類
private List<Method> getOnEventMethod(Object object) {
    Class clazz = object.getClass();
    if (cacheMethodMap.containsKey(clazz)) {
        return cacheMethodMap.get(clazz);
    }
    Method[] declaredMethods = clazz.getDeclaredMethods();
    if (declaredMethods != null) {
        for (Method method : declaredMethods) {
            Annotation[] annotations = method.getDeclaredAnnotations();
            if (annotations != null) {
                for (Annotation annotation : annotations) {
                    if (annotation instanceof OnEvent) {
                        //cacheMethodMap.put(clazz, method);
                        List<Method> methodList = cacheMethodMap.get(clazz);
                        if (methodList == null) {
                            methodList = new ArrayList<>();
                            List<Method> tmp = cacheMethodMap.putIfAbsent(clazz, methodList);
                            if (tmp != null) {
                                methodList = tmp;
                            }
                        }
                        methodList.add(method);
                    }
                }
            }
        }
    }
    return cacheMethodMap.get(clazz);
}
 
開發者ID:zongwu233,項目名稱:Summer,代碼行數:30,代碼來源:ProtocolEventBus.java

示例12: 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

示例13: addClass

import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
 * add mContext new class to extract the methods
 *
 * @param c
 */
public void addClass(Class c, boolean b) {

    try {
        // api docs
        APIManagerClass apiClass = new APIManagerClass();
        apiClass.name = c.getSimpleName().substring(1).toLowerCase();
        apiClass.isMainObject = b;
        MLog.d(TAG, "" + c.getName());

        // getting all the methods
        Method m[] = c.getDeclaredMethods();
        for (Method element : m) {

            // get method
            APIManagerMethod apiMethod = new APIManagerMethod();
            apiMethod.id = methodCount++;
            apiMethod.parent = apiClass.name;
            apiMethod.name = element.getName();

            // get parameter types
            Class<?>[] param = element.getParameterTypes();
            String[] paramsType = new String[param.length];

            for (int j = 0; j < param.length; j++) {
                String p = param[j].getSimpleName().toString();
                paramsType[j] = p;
            }
            apiMethod.paramsType = paramsType;

            // return type
            apiMethod.returnType = element.getReturnType().getSimpleName().toString();

            // get method information
            if (apiMethod.name.contains("$") == false) {
                Annotation[] annotations = element.getDeclaredAnnotations();
                // check if annotation exists and add apidocs
                for (Annotation annotation2 : annotations) {

                    // description and example
                    if (annotation2.annotationType().getSimpleName().equals(ProtoMethod.class.getSimpleName())) {
                        apiMethod.description = ((ProtoMethod) annotation2).description();
                        apiMethod.example = ((ProtoMethod) annotation2).example();

                    }

                    // get parameters names
                    if (annotation2.annotationType().getSimpleName().equals(ProtoMethodParam.class.getSimpleName())) {
                        apiMethod.parametersName = ((ProtoMethodParam) annotation2).params();
                        MLog.d(TAG, "getting names " + apiMethod.parametersName);
                    }

                }

                apiClass.apiMethods.add(apiMethod);
            }
        }

        doc.apiClasses.add(apiClass);

        // classes and methods
        // apis.put(c.getSimpleName(), new API(c, m));

    } catch (Throwable e) {
        System.err.println(e);
    }

}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:73,代碼來源:APIManager.java


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