List of usage examples for javax.lang.model.element ExecutableElement getAnnotationMirrors
@Override
List<? extends AnnotationMirror> getAnnotationMirrors();
To get inherited annotations as well, use Elements#getAllAnnotationMirrors(Element) getAllAnnotationMirrors .
From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java
public static TypeElement getXmlRepresentationClass(TypeElement typeElement, String defaultSuffix) { List<ExecutableElement> methods = ElementFilter.methodsIn(typeElement.getEnclosedElements()); for (ExecutableElement method : methods) { List<? extends AnnotationMirror> anmirs = method.getAnnotationMirrors(); AnnotationMirror mirrorHttpMethod = findAnnotation(anmirs, RestConstants.GET); if (mirrorHttpMethod != null) { TypeMirror tm = method.getReturnType(); if (tm != null && tm.getKind() == TypeKind.DECLARED) { TypeElement returnType = (TypeElement) ((DeclaredType) tm).asElement(); if (returnType.getSimpleName().toString().endsWith(defaultSuffix)) { return returnType; }//from w w w . j av a2s. co m } } } return null; }
From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java
public static Collection<String> getAnnotationValuesForAllMethods(JavaSource source, final String annotation) { final Collection<String> results = new HashSet<>(); try {/*from w w w .ja v a2s. c om*/ source.runUserActionTask(new AbstractTask<CompilationController>() { public void run(CompilationController controller) throws IOException { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); TypeElement classElement = getTopLevelClassElement(controller); if (classElement == null) { return; } List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements()); for (ExecutableElement method : methods) { for (AnnotationMirror mirror : method.getAnnotationMirrors()) { if (((TypeElement) mirror.getAnnotationType().asElement()).getQualifiedName() .contentEquals(annotation)) { for (AnnotationValue value : mirror.getElementValues().values()) { results.add(value.getValue().toString()); } } } } } }, true); } catch (IOException ex) { Exceptions.printStackTrace(ex); } return results; }
From source file:com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessor.java
private void processAutowiredConstructor(ExecutableElement constructor) { List<? extends AnnotationMirror> annotations = constructor.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotations) { Element annotationTypeElement = annotationMirror.getAnnotationType().asElement(); if (annotationTypeElement.equals(this.autowiredTypeElement)) { printMessage(SpringConfigurationMessage.AUTOWIRED_CONSTRUCTOR, constructor, annotationMirror); }/*from w w w.java 2 s .com*/ } }
From source file:org.netbeans.jcode.core.util.JavaSourceHelper.java
public static Collection<String> getAnnotationValuesForAllMethods(JavaSource source, final String annotation) { final Collection<String> results = new HashSet<String>(); try {/*from w w w.j a va2s .co m*/ source.runUserActionTask(new AbstractTask<CompilationController>() { public void run(CompilationController controller) throws IOException { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); TypeElement classElement = getTopLevelClassElement(controller); if (classElement == null) { return; } List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements()); for (ExecutableElement method : methods) { for (AnnotationMirror mirror : method.getAnnotationMirrors()) { if (((TypeElement) mirror.getAnnotationType().asElement()).getQualifiedName() .contentEquals(annotation)) { for (AnnotationValue value : mirror.getElementValues().values()) { results.add(value.getValue().toString()); } } } } } }, true); } catch (IOException ex) { Exceptions.printStackTrace(ex); } return results; }