Example usage for java.lang.reflect Method isAnnotationPresent

List of usage examples for java.lang.reflect Method isAnnotationPresent

Introduction

In this page you can find the example usage for java.lang.reflect Method isAnnotationPresent.

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:cz.muni.fi.editor.database.test.helpers.AbstractDAOTest.java

protected static void checkMethods(Class testClass, Class testingInterface) {
    Set<String> testMethods = new HashSet<>();
    for (Method m : testClass.getDeclaredMethods()) {
        if (m.isAnnotationPresent(Test.class)) {
            testMethods.add(m.getName());
        }//from   www  .  j  a v a 2 s.  com
    }

    List<String> targetMethods = new ArrayList<>(
            Arrays.asList("create", "update", "getById", "delete", "getAll", "getClassType"));
    targetMethods.addAll(new ArrayList<>(Arrays.asList(testingInterface.getDeclaredMethods())).stream()
            .map(m -> m.getName()).collect(Collectors.toList()));
    testMethods.forEach(targetMethods::remove);

    Assert.assertEquals("Following method(s) are missing in DAO test :" + targetMethods.toString(), 0,
            targetMethods.size());
}

From source file:com.example.administrator.mytestdemo.premission.yzjpermission.PermissionUtils.java

static <T extends Annotation> Method[] findMethodForRequestCode(Class<?> source, Class<T> annotation,
        int requestCode) {
    List<Method> methods = new ArrayList<>(1);
    for (Method method : source.getDeclaredMethods())
        if (method.isAnnotationPresent(annotation))
            if (isSameRequestCode(method, annotation, requestCode))
                methods.add(method);/*from  w  w w  .j  a v  a2s  . com*/
    return methods.toArray(new Method[methods.size()]);
}

From source file:net.ymate.platform.core.beans.intercept.InterceptAnnoHelper.java

public static Clean getCleanIntercepts(Method targetMethod) {
    if (targetMethod.isAnnotationPresent(Clean.class)) {
        return targetMethod.getAnnotation(Clean.class);
    }//  ww  w  . jav  a 2  s. c  om
    return null;
}

From source file:com.shigengyu.hyperion.server.RestServer.java

private static Collection<ControllerMethod> extractControllerMethods(
        Iterable<ResourceProvider> resourceProviders) {

    TreeMap<String, ControllerMethod> controllerMethods = Maps.newTreeMap(new Comparator<String>() {

        @Override//from w ww  .  j  av  a  2s .co m
        public int compare(String first, String second) {
            return first.compareTo(second);
        }
    });

    for (ResourceProvider resourceProvider : resourceProviders) {
        String controllerPath = resourceProvider.getResourceClass().getAnnotation(Path.class).value();
        for (Method method : resourceProvider.getResourceClass().getMethods()) {
            if (!method.isAnnotationPresent(Path.class)) {
                continue;
            }

            String methodPath = method.getAnnotation(Path.class).value();

            String httpMethod = null;
            if (method.isAnnotationPresent(GET.class)) {
                httpMethod = HttpMethods.GET;
            } else if (method.isAnnotationPresent(POST.class)) {
                httpMethod = HttpMethods.POST;
            }

            ControllerMethod controllerMethod = new ControllerMethod(httpMethod, controllerPath, methodPath);
            controllerMethods.put(controllerMethod.getUrl(), controllerMethod);
        }
    }

    return controllerMethods.values();
}

From source file:com.mmj.app.common.notify.NotifyUtils.java

public static Result getListenedEvent(Map<EventType, Set<MethodDescriptor>> container,
        NotifyListener listener) {/*from w  w  w  .j  av  a 2  s  .  c  om*/
    if (logger.isDebugEnabled()) {
        logger.debug("getListenedEvent for? " + listener.getClass() + "...");
    }
    try {
        Result result = Result.success();
        Method[] methods = listener.getClass().getMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(EventConfig.class)) {
                parserAnnotation(result, listener, method, container);
            }
        }
        return result;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return Result.failed(e.getMessage());
    }
}

From source file:org.blocks4j.reconf.client.elements.ConfigurationItemElement.java

private static void checkAnnotations(Method method) {
    if (!(method.isAnnotationPresent(ConfigurationItem.class)
            || method.isAnnotationPresent(UpdateConfigurationRepository.class))) {
        throw new ReConfInitializationError(msg.format("error.not.configured.method", method.toString()));
    }//from   w w  w. j av  a2  s. c o m
}

From source file:com.facebook.stetho.inspector.MethodDispatcher.java

/**
 * Determines if the method is a {@link ChromeDevtoolsMethod}, and validates accordingly
 * if it is.//from   w  w  w .jav a  2s .  c  o m
 *
 * @throws IllegalArgumentException Thrown if it is a {@link ChromeDevtoolsMethod} but
 *     it otherwise fails to satisfy requirements.
 */
private static boolean isDevtoolsMethod(Method method) throws IllegalArgumentException {
    if (!method.isAnnotationPresent(ChromeDevtoolsMethod.class)) {
        return false;
    } else {
        Class<?> args[] = method.getParameterTypes();
        String methodName = method.getDeclaringClass().getSimpleName() + "." + method.getName();
        Util.throwIfNot(args.length == 2, "%s: expected 2 args, got %s", methodName, args.length);
        Util.throwIfNot(args[0].equals(JsonRpcPeer.class), "%s: expected 1st arg of JsonRpcPeer, got %s",
                methodName, args[0].getName());
        Util.throwIfNot(args[1].equals(JSONObject.class), "%s: expected 2nd arg of JSONObject, got %s",
                methodName, args[1].getName());

        Class<?> returnType = method.getReturnType();
        if (!returnType.equals(void.class)) {
            Util.throwIfNot(JsonRpcResult.class.isAssignableFrom(returnType),
                    "%s: expected JsonRpcResult return type, got %s", methodName, returnType.getName());
        }
        return true;
    }
}

From source file:com.curl.orb.servlet.InstanceManagementUtil.java

/** 
 * check @DoNotShare annotation/*w w  w  .  jav a  2 s .c o  m*/
 */
public static boolean isDoNotShare(Method method) {
    return method.isAnnotationPresent(DoNotShare.class);
}

From source file:com.example.captain_miao.grantap.utils.PermissionUtils.java

public static List<Method> findAnnotationMethods(Class clazz, Class<? extends Annotation> clazz1) {
    List<Method> methods = new ArrayList<>();
    for (Method method : clazz.getDeclaredMethods()) {
        if (method.isAnnotationPresent(clazz1)) {
            methods.add(method);//from   ww w.  j  a v  a2s  .  c  o  m
        }
    }
    return methods;
}

From source file:com.example.captain_miao.grantap.utils.PermissionUtils.java

public static <A extends Annotation> Method findMethodPermissionDeniedWithRequestCode(Class clazz,
        Class<A> permissionFailClass, int requestCode) {
    for (Method method : clazz.getDeclaredMethods()) {
        if (method.isAnnotationPresent(permissionFailClass)) {
            if (requestCode == method.getAnnotation(PermissionDenied.class).requestCode()) {
                return method;
            }//ww w  . j  a  va2s  . co  m
        }
    }
    return null;
}