has Annotated Method - Java java.lang.annotation

Java examples for java.lang.annotation:Method Annotation

Description

has Annotated Method

Demo Code

/*// ww w .  j a v  a 2 s  .  c  o m
 * JFox - The most lightweight Java EE Application Server!
 * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
 *
 * JFox is licenced and re-distributable under GNU LGPL.
 */
//package com.java2s;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Field;

public class Main {


    public static boolean hasAnnotatedMethod(Class clz,
            Class<? extends Annotation> annotation) {
        Method[] allMethods = clz.getMethods();
        for (int i = 0; i < allMethods.length; i++) {
            if (isAnnotated(allMethods[i], annotation)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isAnnotated(Method method,
            Class<? extends Annotation> annotation) {
        return method.isAnnotationPresent(annotation);
    }

    public static boolean isAnnotated(Field field,
            Class<? extends Annotation> annotation) {
        return field.isAnnotationPresent(annotation);
    }
}

Related Tutorials