Example usage for java.lang Class isAnnotationPresent

List of usage examples for java.lang Class isAnnotationPresent

Introduction

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

Prototype

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

Source Link

Usage

From source file:Main.java

public static void main(String[] unused) {
    try {//w  w  w  .  j  av  a2 s  .  c  om
        String n = "java.lang.Deprecated";
        Class c = Class.forName(n);
        Class d = Class.forName("java.util.Date");
        System.out.println(d.isAnnotationPresent(c));

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

private static boolean isAnnotationPresentOnInterfaces(Class<?> clazz, Class<? extends Annotation> a) {
    for (Class<?> i : clazz.getInterfaces()) {
        if (i.isAnnotationPresent(a))
            return true;
        if (isAnnotationPresentOnInterfaces(i, a))
            return true;
    }// w ww .jav  a  2s. com

    return false;
}

From source file:org.faster.opm.ResourceHelper.java

/**
 * ??//from w  w  w  . jav  a  2s . c  o m
 *
 * @param clazz ??
 * @return
 */
public static final boolean isResource(Class<?> clazz) {
    return clazz != null && clazz.isAnnotationPresent(Resource.class);
}

From source file:com.epam.jdi.uitests.web.selenium.elements.composite.WebSite.java

public static void init(String driverName, Class<?>... sites) {
    for (Class<?> site : sites) {
        if (site.isAnnotationPresent(JSite.class)) {
            String value = site.getAnnotation(JSite.class).value();
            if (isNotBlank(value))
                DOMAIN = value;/*from w w  w.  j a v  a2  s .  c  om*/
        }
        new WebCascadeInit().initStaticPages(site, driverName);
    }
    currentSite = sites[sites.length - 1];
}

From source file:Main.java

private static void recurse(List<Class<?>> classes, String packageName, Class<? extends Annotation> a)
        throws ClassNotFoundException {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    String path = packageName.replace('.', '/');
    URL resource = loader.getResource(path);
    if (resource != null) {
        String filePath = resource.getFile();
        if (filePath != null && new File(filePath).isDirectory()) {
            for (String file : new File(filePath).list()) {
                if (file.endsWith(".class")) {
                    String name = packageName + '.' + file.substring(0, file.indexOf(".class"));
                    Class<?> clazz = Class.forName(name);
                    if (clazz.isAnnotationPresent(a))
                        classes.add(clazz);
                } else if (new File(filePath, file).isDirectory()) {
                    recurse(classes, packageName + "." + file, a);
                }// w  ww. j a v a  2 s. c o  m
            }
        }
    }
}

From source file:com.khs.sherpa.util.Util.java

public static String getObjectName(Class<?> type) {
    String name = null;// w w  w . j  av a  2s .c  om
    if (type.isAnnotationPresent(Endpoint.class)) {
        name = type.getAnnotation(Endpoint.class).value();
    }

    if (StringUtils.isEmpty(name)) {
        name = type.getSimpleName();
    }
    return name;
}

From source file:com.webcohesion.ofx4j.io.AggregateIntrospector.java

/**
 * Get the aggregate meta information for the specified class.
 *
 * @param clazz the aggregate class.//from   w  w w .ja v  a  2 s  .c o m
 * @return The aggregate meta information, or null if the class isn't an aggregate.
 */
public static AggregateInfo getAggregateInfo(Class clazz) {
    AggregateInfo info = null;
    if (clazz.isAnnotationPresent(Aggregate.class)) {
        synchronized (INFO_MAP) {
            info = INFO_MAP.get(clazz);
            if (info == null) {
                info = new AggregateInfo(clazz);
                INFO_MAP.put(clazz, info);
            }
        }
    }
    return info;
}

From source file:org.jmingo.util.DocumentUtils.java

public static boolean isDocument(Class<?> documentType) {
    return documentType != null && documentType.isAnnotationPresent(Document.class);
}

From source file:com.shelfmap.stepsfinder.CandidateStepsFactory.java

public static List<Class<?>> findStepsClasses(Class<?> embedderClass) {
    final String classPath = packagePath(embedderClass);
    List<String> paths = new StoryFinder().findPaths(codeLocationFromParentPackage(embedderClass).getFile(),
            asList("**/*.class"), null);

    transform(paths, new Transformer() {
        @Override/* ww w. j  av  a2 s . c  om*/
        public Object transform(Object input) {
            return classPath + (removeEnd((String) input, ".class"));
        }
    });

    List<Class<?>> classes = new ArrayList<Class<?>>();
    for (String path : paths) {
        final String className = path.replace("/", ".");
        try {
            Class<?> clazz = Class.forName(className);
            if (clazz.isAnnotationPresent(Steps.class)) {
                classes.add(clazz);
            }
        } catch (ClassNotFoundException ex) {
            LOGGER.error("Could not load the class: " + className);
        }
    }
    return classes;
}

From source file:com.evolveum.midpoint.provisioning.ucf.api.UcfUtil.java

public static boolean hasAnnotation(PropertyDescriptor prop, Class<? extends Annotation> annotationClass) {
    Method readMethod = prop.getReadMethod();
    if (readMethod != null && readMethod.getAnnotation(annotationClass) != null) {
        return true;
    }/*from  w  w w.  j  a v a2s  . c o m*/
    Method writeMethod = prop.getWriteMethod();
    if (writeMethod != null && writeMethod.getAnnotation(annotationClass) != null) {
        return true;
    }
    Class<?> propertyType = prop.getPropertyType();
    if (propertyType.isAnnotationPresent(annotationClass)) {
        return true;
    }
    return false;
}