当前位置: 首页>>代码示例>>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;未经允许,请勿转载。