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:org.vulpe.commons.util.VulpeReflectUtil.java

/**
 * Checks if field is noted by <code>annotationClass</code>.
 *
 * @param <T>//from   w ww . j  a va2s  . c o m
 * @param annotationClass
 * @param clazz
 * @param fieldName
 * @return
 */
public static <T extends Annotation> T getAnnotationInField(final Class<T> annotationClass,
        final Class<?> clazz, final String fieldName) {
    final Field field = getField(clazz, fieldName);
    if (field != null && field.isAnnotationPresent(annotationClass)) {
        return field.getAnnotation(annotationClass);
    }
    final String name = VulpeStringUtil.upperCaseFirst(fieldName);
    Method method = getMethod(clazz, "get".concat(name));
    if (method != null && method.isAnnotationPresent(annotationClass)) {
        return method.getAnnotation(annotationClass);
    }
    method = getMethod(clazz, "set".concat(name));
    if (method != null && method.isAnnotationPresent(annotationClass)) {
        return method.getAnnotation(annotationClass);
    }
    return null;
}

From source file:com.ryantenney.metrics.spring.AnnotationFilter.java

@Override
public boolean matches(Method method) {
    return method.isAnnotationPresent(clazz);
}

From source file:tnt.common.monitoring.GuardedByAnnotationBeanPostProcessor.java

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    final List<Method> guardedMethods = new ArrayList<>();
    ReflectionUtils.doWithMethods(bean.getClass(), new MethodCallback() {
        @Override//ww  w  .  j  ava2  s  .  c  om
        public void doWith(Method method) {
            if (method.isAnnotationPresent(GuardedBy.class)) {
                guardedMethods.add(method);
            }
        }
    });
    return guardedMethods.isEmpty() ? bean : createProxy(bean, guardedMethods);
}

From source file:org.callimachusproject.rewrite.MissingAdvice.java

private String[] getMediaType(Method method) {
    if (method.isAnnotationPresent(type.class))
        return method.getAnnotation(type.class).value();
    return new String[0];
}

From source file:com.wavemaker.tools.apidocs.tools.spring.parser.SpringPathsParser.java

@Override
protected Collection<Method> filterRestMethods(final Collection<Method> methods) {
    List<Method> filteredMethods = new LinkedList<>();

    for (Method method : methods) {
        if (method.isAnnotationPresent(RequestMapping.class)) {
            filteredMethods.add(method);
        }//from w  w  w  .j  av  a 2s. c  o m
    }

    return filteredMethods;
}

From source file:org.callimachusproject.rewrite.MissingAdviceFactory.java

private StatusLine getStatusLine(Method method) {
    if (method.isAnnotationPresent(disabled.class)) {
        String[] phrase = method.getAnnotation(disabled.class).value();
        if (phrase.length < 1) {
            phrase = new String[] { "Disabled" };
        }//from  w w  w  .  j  a v  a 2  s . co m
        return new BasicStatusLine(HttpVersion.HTTP_1_1, 404, phrase[0]);
    }
    if (method.isAnnotationPresent(deleted.class)) {
        String[] phrase = method.getAnnotation(deleted.class).value();
        if (phrase.length < 1) {
            phrase = new String[] { "Deleted" };
        }
        return new BasicStatusLine(HttpVersion.HTTP_1_1, 410, phrase[0]);
    }
    throw new AssertionError();
}

From source file:com.capgemini.boot.core.factory.internal.DefaultAnnotationStrategy.java

@Override
public boolean isFactoryMethod(Method method) {
    return method.isAnnotationPresent(getFactoryMethodAnnotation());
}

From source file:org.shredzone.cilla.view.interceptor.FramedViewInterceptor.java

@Override
public void onViewHandlerInvocation(ViewContext context, Object bean, Method method) {
    if (method.isAnnotationPresent(Framed.class)) {
        try {//from w w  w .  j  a  v a 2 s  . c o  m
            HttpServletRequest req = context.getValueOfType(HttpServletRequest.class);
            HttpServletResponse resp = context.getValueOfType(HttpServletResponse.class);
            setupFrame(req, resp);
        } catch (ViewException ex) {
            // Should not happen. Just log the exception and do not set up the frame.
            log.error("No HTTP request", ex);
        }
    }
}

From source file:com.precioustech.fxtrading.tradingbot.spring.FindEventBusSubscribers.java

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    Method[] beanMethods = bean.getClass().getMethods();
    for (Method beanMethod : beanMethods) {
        if (beanMethod.isAnnotationPresent(Subscribe.class)) {
            eventBus.register(bean);//w  w  w  . j  ava 2 s .  c  om
            LOG.info(String.format("Found event bus subscriber class %s. Subscriber method name=%s",
                    bean.getClass().getSimpleName(), beanMethod.getName()));
            break;
        }
    }
    return bean;
}

From source file:com.payu.ratel.event.EventSubscriberPostProcessor.java

private boolean isSubscriber(Object o) {
    for (Method method : o.getClass().getMethods()) {
        return method.isAnnotationPresent(Subscribe.class);
    }//from  w w  w  . j  a v  a2  s.co m

    return false;
}