Annotation-processing 如何从 Method 获取其参数的 Annotations?

How to get from a Method to the Annotations of its Parameters during Annotation-processing?

注解处理中我目前正在处理一个方法的注解:

@Override
public boolean process(Set<? extends TypeElement> elements, RoundEnvironment env) {
  Messager msg = processingEnv.getMessager();
  for (TypeElement te : elements) {
    for (Element e : env.getElementsAnnotatedWith(te)) {
      processAnnotation(e, msg);
    }
  }
  return true;
}

private void processAnnotation(Element method, Messager msg) {
  final Info ann = method.getAnnotation(Info.class);
  assert method.getKind() == ElementKind.METHOD;
  ....

我可以通过

获取参数的类型(或其镜像)
  final ExecutableType emeth = (ExecutableType)method.asType();
  final List<? extends TypeMirror> parameterTypes = emeth.getParameterTypes();

但是我如何获得它的注释呢?我想检查正在考虑的方法是否有任何带有注释 @Input 的参数。例如,处理后的源可以是:

@Info
void myMethodOk(@Input String input) {  }

@Info
void myMethodNotOk(@Input String input) { }

如果将方法 Element 转换为 ExecutableElement,则可以调用 executableElement.getParamerers()。此 returns 是 VariableElement 的列表,您可以从中获取注释。