@Override
 public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment round) {
   try {
     StaticEnvironment.init(annotations, round, processingEnv);
     if (!round.processingOver() && !round.errorRaised()) {
       process();
     }
     StaticEnvironment.shutdown();
   } catch (Exception ex) {
     processingEnv
         .getMessager()
         .printMessage(
             Diagnostic.Kind.ERROR,
             getClass().getName() + " threw " + Throwables.getStackTraceAsString(ex));
   }
   return false;
 }
Beispiel #2
0
  /** {@inheritDoc} */
  @Override
  public boolean process(
      final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {

    for (final Element element : roundEnv.getElementsAnnotatedWith(Emits.class)) {
      final TypeElement typeElement = (TypeElement) element;
      for (final Emit emit : typeElement.getAnnotation(Emits.class).value()) {
        processEmit(emit, typeElement);
      }
    }
    for (final Element element : roundEnv.getElementsAnnotatedWith(Emit.class)) {
      final TypeElement typeElement = (TypeElement) element;
      processEmit(typeElement.getAnnotation(Emit.class), typeElement);
    }
    if (roundEnv.processingOver() && !roundEnv.errorRaised()) {
      try {
        final PrintWriter metaWriter =
            new PrintWriter(
                processingEnv
                    .getFiler()
                    .createResource(
                        StandardLocation.SOURCE_OUTPUT,
                        "",
                        "META-INF/services/javax.annotation.processing.Processor",
                        elementCollection.toArray(new Element[0]))
                    .openWriter());
        for (final String processor : annotationProcessors) {
          metaWriter.println(processor);
        }
        metaWriter.close();
      } catch (final IOException e) {
        final String msg =
            MessageFormat.format(
                LOG.getResourceBundle().getString("ioerror"),
                "META-INF/services/javax.annotation.processing.Processor",
                e.getMessage());
        processingEnv.getMessager().printMessage(Kind.ERROR, msg);
        throw new IllegalStateException(msg, e);
      }
    }
    return true;
  }