has Annotation With Name - Java java.lang.annotation

Java examples for java.lang.annotation:Annotation Attribute

Description

has Annotation With Name

Demo Code


//package com.java2s;

import javax.lang.model.element.AnnotationMirror;

import javax.lang.model.element.Element;

public class Main {
    public static boolean hasAnnotationWithName(Element element,
            String simpleName) {/*  w  ww  .  java 2s. c o m*/
        for (AnnotationMirror mirror : element.getAnnotationMirrors()) {
            String annotationName = mirror.getAnnotationType().asElement()
                    .getSimpleName().toString();
            if (simpleName.equals(annotationName)) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials