code: public void printMessage(Diagnostic.Kind kind, CharSequence msg,
                        Element e, AnnotationMirror a, AnnotationValue v) {
          JavaFileObject oldSource = null;
          JavaFileObject newSource = null;
          JCDiagnostic.DiagnosticPosition pos = null;
          JavacElements elemUtils = processingEnv.getElementUtils();
          Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v);
          if (treeTop != null) {
              newSource = treeTop.snd.sourcefile;
              if (newSource != null) {
                  // save the old version and reinstate it later
                  oldSource = log.useSource(newSource);
                  pos = treeTop.fst.pos();
              }
          }
          try {
              switch (kind) {
              case ERROR:
                  errorCount++;
                  boolean prev = log.multipleErrors;
                  log.multipleErrors = true;
                  try {
                      log.error(pos, "proc.messager", msg.toString());
                  } finally {
                      log.multipleErrors = prev;
                  }
                  break;
  
              case WARNING:
                  warningCount++;
                  log.warning(pos, "proc.messager", msg.toString());
                  break;
  
              case MANDATORY_WARNING:
                  warningCount++;
                  log.mandatoryWarning(pos, "proc.messager", msg.toString());
                  break;
  
              default:
                  log.note(pos, "proc.messager", msg.toString());
                  break;
              }
          } finally {
              // reinstate the saved version, only if it was saved earlier
              if (newSource != null)
                  log.useSource(oldSource);
          }
      }
docs: Prints a message of the specified kind at the location of the
  annotation value inside the annotation mirror of the annotated
  element.
  
  @param kind the kind of message
  @param msg  the message, or an empty string if none
  @param e    the annotated element
  @param a    the annotation containing the annotaiton value
  @param v    the annotation value to use as a position hint