List of usage examples for javax.lang.model.element TypeElement getAnnotationMirrors
@Override
List<? extends AnnotationMirror> getAnnotationMirrors();
To get inherited annotations as well, use Elements#getAllAnnotationMirrors(Element) getAllAnnotationMirrors .
From source file:com.github.pellaton.jazoon2012.JazoonProcessor.java
private void processElement(TypeElement typeElement) { for (AnnotationMirror annotation : typeElement.getAnnotationMirrors()) { Element annotationTypeElement = annotation.getAnnotationType().asElement(); if (annotationTypeElement.equals(this.configurationTypeElement)) { List<? extends Element> enclosedElements = typeElement.getEnclosedElements(); processClass(typeElement, ElementFilter.constructorsIn(enclosedElements)); for (ExecutableElement method : ElementFilter.methodsIn(enclosedElements)) { processMethod(typeElement, method); }/*from w w w . j a v a2s.c om*/ } } }
From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java
public static boolean isInjectionTarget(CompilationController controller, TypeElement typeElement) { if (ElementKind.INTERFACE != typeElement.getKind()) { List<? extends AnnotationMirror> annotations = typeElement.getAnnotationMirrors(); boolean found = false; for (AnnotationMirror m : annotations) { Name qualifiedName = ((TypeElement) m.getAnnotationType().asElement()).getQualifiedName(); if (qualifiedName.contentEquals("javax.jws.WebService")) { //NOI18N found = true;//from w ww.j a va2 s .c o m break; } if (qualifiedName.contentEquals("javax.jws.WebServiceProvider")) { //NOI18N found = true; break; } } if (found) { return true; } } return false; }
From source file:com.contentful.vault.compiler.Processor.java
private void parseSpace(TypeElement element, Map<TypeElement, SpaceInjection> spaces, Map<TypeElement, ModelInjection> models) { Space annotation = element.getAnnotation(Space.class); String id = annotation.value(); if (id.isEmpty()) { error(element, "@%s id may not be empty. (%s)", Space.class.getSimpleName(), element.getQualifiedName()); return;//from ww w .j ava 2 s. c o m } TypeMirror spaceMirror = elementUtils.getTypeElement(Space.class.getName()).asType(); List<ModelInjection> includedModels = new ArrayList<>(); for (AnnotationMirror mirror : element.getAnnotationMirrors()) { if (typeUtils.isSameType(mirror.getAnnotationType(), spaceMirror)) { Set<? extends Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>> items = mirror .getElementValues().entrySet(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : items) { if ("models".equals(entry.getKey().getSimpleName().toString())) { List l = (List) entry.getValue().getValue(); if (l.size() == 0) { error(element, "@%s models must not be empty. (%s)", Space.class.getSimpleName(), element.getQualifiedName()); return; } Set<String> modelIds = new LinkedHashSet<>(); for (Object model : l) { TypeElement e = (TypeElement) ((Type) ((Attribute) model).getValue()).asElement(); ModelInjection modelInjection = models.get(e); if (modelInjection == null) { return; } else { String rid = modelInjection.remoteId; if (!modelIds.add(rid)) { error(element, "@%s includes multiple models with the same id \"%s\". (%s)", Space.class.getSimpleName(), rid, element.getQualifiedName()); return; } includedModels.add(modelInjection); } } } } } } List<String> locales = Arrays.asList(annotation.locales()); Set<String> checked = new HashSet<>(); for (int i = locales.size() - 1; i >= 0; i--) { String code = locales.get(i); if (!checked.add(code)) { error(element, "@%s contains duplicate locale code '%s'. (%s)", Space.class.getSimpleName(), code, element.getQualifiedName()); return; } else if (code.contains(" ") || code.isEmpty()) { error(element, "Invalid locale code '%s', must not be empty and may not contain spaces. (%s)", code, element.getQualifiedName()); return; } } if (checked.size() == 0) { error(element, "@%s at least one locale must be configured. (%s)", Space.class.getSimpleName(), element.getQualifiedName()); return; } ClassName injectionClassName = getInjectionClassName(element, SUFFIX_SPACE); String dbName = "space_" + SqliteUtils.hashForId(id); String copyPath = StringUtils.defaultIfBlank(annotation.copyPath(), null); spaces.put(element, new SpaceInjection(id, injectionClassName, element, includedModels, dbName, annotation.dbVersion(), copyPath, locales)); }
From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java
private boolean hasAnnotation(final TypeElement classElement, final String annotation) { Element actionElement = processingEnv.getElementUtils().getTypeElement(annotation); TypeMirror actionType = actionElement.asType(); if (null != classElement) { List<? extends AnnotationMirror> mirrors = classElement.getAnnotationMirrors(); if (null != mirrors && !mirrors.isEmpty()) { for (AnnotationMirror m : mirrors) { if (m.getAnnotationType().equals(actionType)) { return true; }//from ww w .ja v a 2 s . co m } } } return false; }