Ejemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) return false;

    // We have: A sorted set of all priority levels: 'priorityLevels'

    // Step 1: Take all CUs which aren't already in the map. Give them the first priority level.

    for (Element element : roundEnv.getRootElements()) {
      JCCompilationUnit unit = toUnit(element);
      if (unit == null) continue;
      if (roots.containsKey(unit)) continue;
      roots.put(unit, priorityLevels[0]);
    }

    while (true) {
      // Step 2: For all CUs (in the map, not the roundEnv!), run them across all handlers at their
      // current prio level.

      for (long prio : priorityLevels) {
        List<JCCompilationUnit> cusForThisRound = new ArrayList<JCCompilationUnit>();
        for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) {
          Long prioOfCu = entry.getValue();
          if (prioOfCu == null || prioOfCu != prio) continue;
          cusForThisRound.add(entry.getKey());
        }
        transformer.transform(prio, processingEnv.getContext(), cusForThisRound);
      }

      // Step 3: Push up all CUs to the next level. Set level to null if there is no next level.

      Set<Long> newLevels = new HashSet<Long>();
      for (int i = priorityLevels.length - 1; i >= 0; i--) {
        Long curLevel = priorityLevels[i];
        Long nextLevel = (i == priorityLevels.length - 1) ? null : priorityLevels[i + 1];
        for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) {
          if (curLevel.equals(entry.getValue())) {
            entry.setValue(nextLevel);
            newLevels.add(nextLevel);
          }
        }
      }
      newLevels.remove(null);

      // Step 4: If ALL values are null, quit. Else, either do another loop right now or force a
      // resolution reset by forcing a new round in the annotation processor.

      if (newLevels.isEmpty()) return false;
      newLevels.retainAll(priorityLevelsRequiringResolutionReset);
      if (newLevels.isEmpty()) {
        // None of the new levels need resolution, so just keep going.
        continue;
      } else {
        // Force a new round to reset resolution. The next round will cause this method (process) to
        // be called again.
        forceNewRound((JavacFiler) processingEnv.getFiler());
        return false;
      }
    }
  }
Ejemplo n.º 2
0
 @Override
 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   // System.out.println("supported options: "+
   // Arrays.toString(getSupportedOptions().toArray()));
   if (!roundEnv.processingOver()) {
     for (TypeElement currAnno : annotations) {
       // System.out.println("Found " + currAnno.getQualifiedName());
       if (currAnno.getQualifiedName().contentEquals(GENERATE_POJO_BUILDER_CLASS.getName())) {
         Set<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(currAnno);
         // System.out.println("[GenerateBuilder] annotatedElements="+
         // Arrays.toString(annotatedElements.toArray()));
         for (Element elem : annotatedElements) {
           if (elem.getKind() == ElementKind.CLASS) {
             TypeElement typeElem = (TypeElement) elem;
             GeneratePojoBuilder annotation = typeElem.getAnnotation(GENERATE_POJO_BUILDER_CLASS);
             generatePojoBuilderProcessor.process(typeElem, annotation);
           } else if (elem.getKind() == ElementKind.METHOD) {
             ExecutableElement execElem = (ExecutableElement) elem;
             GeneratePojoBuilder annotation = execElem.getAnnotation(GENERATE_POJO_BUILDER_CLASS);
             generatePojoBuilderProcessor.process(execElem, annotation);
           }
         }
       }
     }
   }
   return false;
 }
Ejemplo n.º 3
0
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    // Are we finished, if so, clean up
    if (roundEnv.processingOver()) {
      state = null;
      return false;
    }

    // Newly initialized or being reused?
    if (state == null) {
      state = forceErrors ? new State.ForTesting(processingEnv) : new State(processingEnv);
      if (state.isPoisoned()) {
        // Could not initialize State object, bail out
        return false;
      }
      // Produce a "lite" map just for JRE-only clients
      state.setClientOnly(clientOnly);
      // Disallow @ProxyForName or @ServiceName that can't be resolved
      state.setMustResolveAllMappings(mustResolveAllMappings);
    }

    try {
      // Bootstrap the State's work queue
      new Finder().scan(getTypesToProcess(state, roundEnv), state);
      // Execute the work items
      state.executeJobs();
    } catch (HaltException ignored) {
      // Already logged. Let any unhandled RuntimeExceptions fall out.
    }
    return false;
  }
Ejemplo n.º 4
0
 @Override
 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   // check if process was done on previous round
   if (OcelotProcessor.isDone()
       || roundEnv.processingOver()) { // Returns true if types generated by this round will not be
     // subject to a subsequent round of annotation processing; returns
     // false otherwise.
     return true; // if is it : stop
   }
   // Create provider of ocelot-services.js
   String js = createJSServicesProvider();
   // Create file ocelot-services.js
   try {
     FileObject resource = filer.createResource(StandardLocation.CLASS_OUTPUT, "", js);
     try (Writer writer = resource.openWriter()) {
       ElementVisitor visitor = new DataServiceVisitor(processingEnv);
       for (Element element : roundEnv.getElementsAnnotatedWith(DataService.class)) {
         messager.printMessage(
             Diagnostic.Kind.MANDATORY_WARNING, " javascript generation class : " + element);
         element.accept(visitor, writer);
       }
     }
   } catch (IOException e) {
     messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage());
   }
   OcelotProcessor.setDone(true);
   return true;
 }
Ejemplo n.º 5
0
 @Override
 public boolean process(Set<? extends TypeElement> types, RoundEnvironment env) {
   remainingTypes.putAll(providerMethodsByClass(env));
   for (Iterator<String> i = remainingTypes.keySet().iterator(); i.hasNext(); ) {
     String typeName = i.next();
     TypeElement type = processingEnv.getElementUtils().getTypeElement(typeName);
     List<ExecutableElement> providesTypes = remainingTypes.get(typeName);
     try {
       // Attempt to get the annotation. If types are missing, this will throw
       // IllegalStateException.
       Map<String, Object> parsedAnnotation = CodeGen.getAnnotation(Module.class, type);
       try {
         writeModuleAdapter(type, parsedAnnotation, providesTypes);
       } catch (IOException e) {
         error("Code gen failed: " + e, type);
       }
       i.remove();
     } catch (IllegalStateException e) {
       // a dependent type was not defined, we'll catch it on another pass
     }
   }
   if (env.processingOver() && remainingTypes.size() > 0) {
     processingEnv
         .getMessager()
         .printMessage(
             Diagnostic.Kind.ERROR,
             "Could not find types required by provides methods for " + remainingTypes.keySet());
   }
   return false; // FullGraphProcessor needs an opportunity to process.
 }
Ejemplo n.º 6
0
 public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
   try {
     if (renv.processingOver()) createSymbols();
   } catch (IOException e) {
     processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getLocalizedMessage());
   } catch (Throwable t) {
     Throwable cause = t.getCause();
     if (cause == null) cause = t;
     processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, cause.getLocalizedMessage());
   }
   return true;
 }
Ejemplo n.º 7
0
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
      return true;
    }

    for (Element element : roundEnv.getElementsAnnotatedWith(ServiceProvider.class)) {
      assert element.getKind().isClass();
      processElement((TypeElement) element);
    }

    return true;
  }
Ejemplo n.º 8
0
 @Override
 public boolean process(
     Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) {
   if (!roundEnvironment.processingOver()) {
     Set<? extends Element> elements = roundEnvironment.getRootElements();
     elements.forEach(
         element -> {
           JCTree tree = (JCTree) trees.getTree(element);
           tree.accept(visitor);
         });
   }
   return false;
 }
Ejemplo n.º 9
0
  @Override
  public void handle(ProcessorManager processorManager, RoundEnvironment roundEnvironment) {
    for (BaseContainerHandler containerHandler : handlers) {
      containerHandler.handle(processorManager, roundEnvironment);
    }

    ContentProviderValidator validator = new ContentProviderValidator();
    Collection<ContentProviderDefinition> contentProviderDefinitions = providerMap.values();
    for (ContentProviderDefinition contentProviderDefinition : contentProviderDefinitions) {
      if (validator.validate(processorManager, contentProviderDefinition)) {
        WriterUtils.writeBaseDefinition(contentProviderDefinition, processorManager);
      }
    }
    List<DatabaseWriter> databaseWriters = getManagerWriters();
    for (DatabaseWriter databaseWriter : databaseWriters) {
      try {
        JavaWriter javaWriter =
            new JavaWriter(
                processorManager
                    .getProcessingEnvironment()
                    .getFiler()
                    .createSourceFile(databaseWriter.getSourceFileName())
                    .openWriter());
        databaseWriter.write(javaWriter);
        javaWriter.close();
      } catch (IOException e) {
        processorManager.getMessager().printMessage(Diagnostic.Kind.WARNING, e.getMessage());
      }
    }

    if (roundEnvironment.processingOver()) {
      try {
        JavaWriter staticFlowManager =
            new JavaWriter(
                processorManager
                    .getProcessingEnvironment()
                    .getFiler()
                    .createSourceFile(
                        Classes.FLOW_MANAGER_PACKAGE
                            + "."
                            + Classes.DATABASE_HOLDER_STATIC_CLASS_NAME)
                    .openWriter());
        new FlowManagerHolderWriter(processorManager).write(staticFlowManager);

        staticFlowManager.close();
      } catch (IOException e) {
        processorManager.getMessager().printMessage(Diagnostic.Kind.WARNING, e.getMessage());
      }
    }
  }
 @Override
 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   this.metadataCollector.processing(roundEnv);
   Elements elementUtils = this.processingEnv.getElementUtils();
   TypeElement annotationType = elementUtils.getTypeElement(configurationPropertiesAnnotation());
   if (annotationType != null) { // Is @ConfigurationProperties available
     for (Element element : roundEnv.getElementsAnnotatedWith(annotationType)) {
       processElement(element);
     }
   }
   if (roundEnv.processingOver()) {
     writeMetaData();
   }
   return false;
 }
Ejemplo n.º 11
0
  @Override
  public boolean process(
      final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnvironment) {
    // nothing to do in the last round
    if (!roundEnvironment.processingOver()) {
      // process any mappers left over from previous rounds
      Set<TypeElement> deferredMappers = getAndResetDeferredMappers();
      processMapperElements(deferredMappers);

      // get and process any mappers from this round
      Set<TypeElement> mappers = getMappers(annotations, roundEnvironment);
      processMapperElements(mappers);
    }

    return ANNOTATIONS_CLAIMED_EXCLUSIVELY;
  }
Ejemplo n.º 12
0
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element elem : roundEnv.getElementsAnnotatedWith(FixedRecord.class)) {
      String classPackage =
          processingEnv.getElementUtils().getPackageOf(elem).getQualifiedName().toString();
      ClassWrapper classWrapper = new ClassWrapper(classPackage, elem.getSimpleName().toString());

      List<Element> listGetter = getFixedFieldAnnotateMethod(elem);

      for (Element elemMethod : listGetter) {
        TypeWrapper typeWrapper;
        MethodWrapper methodWrapper = new MethodWrapper();
        FixedField fixedField = elemMethod.getAnnotation(FixedField.class);
        String decoratorClass = getDecoratorClass(fixedField);

        methodWrapper.setName(elemMethod.getSimpleName().toString());
        methodWrapper.setFixedField(fixedField);
        methodWrapper.setDecoratorClass(decoratorClass);

        String fullName = ((ExecutableType) elemMethod.asType()).getReturnType().toString();
        if (fullName.contains("<") && fixedField.collectionSize() > 0) {
          fullName = fullName.substring(fullName.indexOf("<") + 1, fullName.indexOf(">"));
        }
        String packageName = fullName.substring(0, fullName.lastIndexOf("."));
        String typeName = fullName.substring(packageName.length() + 1);

        if (fixedField.length() == 0 && fixedField.collectionSize() == 0) {
          methodWrapper.setBean(true);
        } else if (fixedField.collectionSize() > 0) {
          methodWrapper.setList(true);
        }

        typeWrapper = new TypeWrapper(packageName, typeName);
        methodWrapper.setType(typeWrapper);
        classWrapper.addMethod(methodWrapper);
      }

      parser.createParserClass(classWrapper);
      // TODO
      processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "");
    }
    if (roundEnv.processingOver()) {
      parser.getJavaFileBuilder().writeJavaFile(processingEnv);
      return false;
    }
    return true; // no further processing of this annotation type
  }
 @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;
 }
Ejemplo n.º 14
0
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
      return true;
    }
    final List<LabelTemplateMethod> methods = new ArrayList<LabelTemplateMethod>();
    for (Element element : roundEnv.getElementsAnnotatedWith(MessageBundle.class)) {
      if (element.getKind() != ElementKind.INTERFACE) {
        continue;
      }
      final TypeElement bundleType = (TypeElement) element;
      processLabels(bundleType, methods);
      try {

        FileObject file = null;
        switch (generationType) {
          case SOURCE:
            file =
                processingEnv
                    .getFiler()
                    .createSourceFile(getTargetClassName(bundleType), bundleType);
            break;

          case RESSOURCE:
            file =
                processingEnv
                    .getFiler()
                    .createResource(
                        SOURCE_OUTPUT,
                        bundleType.getEnclosingElement().toString(),
                        getTargetSimpleName(bundleType) + ".properties");
            break;
        }

        final Writer writer = file.openWriter();
        writer.write(getCode(bundleType, methods));
        writer.close();
      } catch (IOException e) {
        processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), bundleType);
      } finally {
        methods.clear();
      }
    }
    return false;
  }
Ejemplo n.º 15
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;
  }
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    try {

      if (verbose) {
        processingEnv
            .getMessager()
            .printMessage(Diagnostic.Kind.NOTE, "Adding classes to " + outputFile);
      }

      // Loop around elements
      for (Element elem : roundEnv.getElementsAnnotatedWith(GenerateBeanInfo.class)) {
        // Only process class level elements
        if (elem.getKind().equals(ElementKind.CLASS)) {
          // Create XYZBeanInfo.java for each element
          createBeanInfo((TypeElement) elem);
          // Add class name to XstreamJavabeans.properties file
          beanNames.add(((TypeElement) elem).getQualifiedName().toString());
        }
      }

      // If we are done processing, write the file
      if (roundEnv.processingOver()) {
        appendExistingClasses(beanNames);
        FileObject fo =
            processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", outputFile);
        try (PrintWriter w = new PrintWriter(fo.openWriter())) {
          for (String name : beanNames) {
            w.println(name);
          }
        }
        beanNames.clear();
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    return true;
  }
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    TYPES = processingEnv.getTypeUtils();
    ELEMENTS = processingEnv.getElementUtils();

    processingEnv
        .getMessager()
        .printMessage(Diagnostic.Kind.NOTE, "Running " + getClass().getSimpleName());

    if (roundEnv.processingOver() || annotations.size() == 0) {
      return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }

    if (roundEnv.getRootElements() == null || roundEnv.getRootElements().isEmpty()) {
      processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "No sources to process");
      return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }

    conf = createConfiguration(roundEnv);
    context = new Context();
    Set<Class<? extends Annotation>> entityAnnotations = conf.getEntityAnnotations();
    TypeMappings typeMappings = conf.getTypeMappings();
    QueryTypeFactory queryTypeFactory = conf.getQueryTypeFactory();
    this.typeFactory =
        new ExtendedTypeFactory(
            processingEnv, conf, entityAnnotations, typeMappings, queryTypeFactory);
    elementHandler = new TypeElementHandler(conf, typeFactory, typeMappings, queryTypeFactory);
    this.roundEnv = roundEnv;

    // process annotations
    processAnnotations();

    validateMetaTypes();

    // serialize created types
    serializeMetaTypes();

    return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
  }
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

    if (!roundEnv.processingOver()) {
      //			System.out.println("Processing Annotations: " + annotations);
      //			System.out.println();

      for (TypeElement typeElement : annotations) {
        //				System.out.println("Processing: " + typeElement);
        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(typeElement);
        //				System.out.println("Processing Elements: " + elements);
        //				System.out.println();
        for (Element element : elements) {
          if (element.getKind() == ElementKind.CLASS
              && !element.getSimpleName().toString().contains("$")
              && !element.getModifiers().contains(Modifier.STATIC)
              && !element.getModifiers().contains(Modifier.PRIVATE)) {
            processClass(element);
          }
        }
      }
    }
    return true;
  }
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    try {
      if (roundEnv.processingOver()) {
        return false;
      }

      // collect all exposed properties
      Multimap<TypeElement, Element /*member decls*/> props = LinkedListMultimap.create();

      for (Element exported : roundEnv.getElementsAnnotatedWith(Exported.class)) {
        props.put((TypeElement) exported.getEnclosingElement(), exported);
      }

      Set<String> exposedBeanNames = scanExisting();

      for (Entry<TypeElement, Collection<Element>> e : props.asMap().entrySet()) {
        exposedBeanNames.add(e.getKey().getQualifiedName().toString());

        final Properties javadocs = new Properties();
        for (Element md : e.getValue()) {
          switch (md.getKind()) {
            case FIELD:
            case METHOD:
              String javadoc = getJavadoc(md);
              if (javadoc != null) javadocs.put(md.getSimpleName().toString(), javadoc);
              break;
            default:
              throw new AssertionError("Unexpected element type: " + md);
          }
          // TODO: possibly a proper method signature generation, but it's too tedious
          // way too tedious.
          // private String getSignature(MethodDeclaration m) {
          //    final StringBuilder buf = new StringBuilder(m.getSimpleName());
          //    buf.append('(');
          //    boolean first=true;
          //    for (ParameterDeclaration p : m.getParameters()) {
          //        if(first)   first = false;
          //        else        buf.append(',');
          //        p.getType().accept(new SimpleTypeVisitor() {
          //            public void visitPrimitiveType(PrimitiveType pt) {
          //                buf.append(pt.getKind().toString().toLowerCase());
          //            }
          //            public void visitDeclaredType(DeclaredType dt) {
          //                buf.append(dt.getDeclaration().getQualifiedName());
          //            }
          //
          //            public void visitArrayType(ArrayType at) {
          //                at.getComponentType().accept(this);
          //                buf.append("[]");
          //            }
          //
          //            public void visitTypeVariable(TypeVariable tv) {
          //
          //                // TODO
          //                super.visitTypeVariable(typeVariable);
          //            }
          //
          //            public void visitVoidType(VoidType voidType) {
          //                // TODO
          //                super.visitVoidType(voidType);
          //            }
          //        });
          //    }
          //    buf.append(')');
          //    // TODO
          //    return null;
          // }
        }

        String javadocFile =
            e.getKey().getQualifiedName().toString().replace('.', '/') + ".javadoc";
        notice("Generating " + javadocFile, e.getKey());
        writePropertyFile(javadocs, javadocFile);
      }

      FileObject beans = createResource(STAPLER_BEAN_FILE);
      PrintWriter w = new PrintWriter(new OutputStreamWriter(beans.openOutputStream(), "UTF-8"));
      for (String beanName : exposedBeanNames) w.println(beanName);
      w.close();

    } catch (IOException x) {
      error(x);
    } catch (RuntimeException e) {
      // javac sucks at reporting errors in annotation processors
      e.printStackTrace();
      throw e;
    } catch (Error e) {
      e.printStackTrace();
      throw e;
    }
    return false;
  }
Ejemplo n.º 20
0
  @Override
  @SuppressWarnings("unchecked")
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
      return false;
    }

    Set<String> beans = new TreeSet<String>();

    // JavaBean is a type only annotation, so cast to TypeElement is safe
    for (TypeElement type : (Set<TypeElement>) roundEnv.getElementsAnnotatedWith(JavaBean.class)) {
      beans.add(type.getQualifiedName().toString());
    }

    // remove any existing values; we append to the file
    Filer filer = processingEnv.getFiler();

    FileObject manifest = null;

    try {
      processingEnv.getMessager().printMessage(Kind.NOTE, "Attempting to open manifest...");

      manifest = filer.getResource(StandardLocation.SOURCE_PATH, "", "META-INF/MANIFEST.MF");

      if (manifest != null) {
        processingEnv.getMessager().printMessage(Kind.NOTE, "Succeeded: " + manifest.getName());

        BufferedReader r = null;

        try {
          processingEnv
              .getMessager()
              .printMessage(Kind.NOTE, "Attempting to find previously defined Java beans");

          r = new BufferedReader(new InputStreamReader(manifest.openInputStream(), "UTF-8"));

          String possibleBean = null;

          for (String line = r.readLine(); line != null; line = r.readLine()) {
            if (possibleBean == null) {
              if (line.startsWith("Name: ") && line.endsWith(".class")) {
                possibleBean =
                    line.substring("Name: ".length(), line.length() - ".class".length())
                        .replace('/', '.');

                try {
                  Class.forName(possibleBean);
                } catch (ClassNotFoundException notABean) {
                  possibleBean = null;
                }
              }
            } else {
              if (line.equals("Java-Bean: True")) {
                processingEnv
                    .getMessager()
                    .printMessage(Kind.NOTE, possibleBean + " already defined");
                beans.remove(possibleBean);
              }

              possibleBean = null;
            }
          }

          r.close();

        } catch (FileNotFoundException ignore) {
          processingEnv.getMessager().printMessage(Kind.NOTE, "Manifest not found");
        } catch (IOException e) {
          throw new RuntimeException("Failed to read current Java-Bean information", e);
        } finally {
          if (r != null) {
            try {
              r.close();
            } catch (IOException ignore) {
            }
          }
        }
      }
    } catch (FileNotFoundException ignore) {
      // no file to process
      processingEnv.getMessager().printMessage(Kind.NOTE, "Manifest does not exist...");
    } catch (IOException e) {
      processingEnv
          .getMessager()
          .printMessage(
              Kind.ERROR, "Failed to load existing manifest for Java-Bean processing:\n" + e);

      return false;
    }

    try {
      processingEnv
          .getMessager()
          .printMessage(Kind.NOTE, "Attempting to create output manifest...");

      manifest = filer.createResource(StandardLocation.SOURCE_OUTPUT, "", "META-INF/MANIFEST.MF");

      processingEnv.getMessager().printMessage(Kind.NOTE, "Succeeded: " + manifest.getName());
    } catch (IOException e) {
      processingEnv
          .getMessager()
          .printMessage(Kind.ERROR, "Cannot create manifest for Java-Bean processing:\n" + e);

      return false;
    }

    processingEnv.getMessager().printMessage(Kind.NOTE, "Appending Java-Beans to MANIFEST.MF");
    processingEnv.getMessager().printMessage(Kind.NOTE, beans.toString());

    PrintWriter pw = null;

    try {
      pw = new PrintWriter(new OutputStreamWriter(manifest.openOutputStream(), "UTF-8"));

      pw.println();

      for (String value : beans) {
        pw.println("Name: " + value + ".class");
        pw.println("Java-Bean: True");
        pw.println();
      }
    } catch (IOException e) {
      throw new RuntimeException("Failed to write Java-Bean information", e);
    } finally {
      if (pw != null) {
        pw.close();
      }
    }

    return false;
  }
  @Override
  public boolean process(
      Set<? extends TypeElement> typeElements, RoundEnvironment roundEnvironment) {

    long start = System.currentTimeMillis();

    // setup transfuse processor with manifest and R classes
    File manifestFile = manifestLocator.findManifest();
    Manifest manifest = manifestParser.readManifest(manifestFile);

    RResourceComposite r =
        new RResourceComposite(
            buildR(rBuilder, manifest.getApplicationPackage() + ".R"),
            buildR(rBuilder, "android.R"));

    configurationScope.enter();

    configurationScope.seed(
        ScopeKey.of(File.class)
            .annotatedBy("@javax.inject.Named(value=" + TransfuseAndroidModule.MANIFEST_FILE + ")"),
        manifestFile);
    configurationScope.seed(ScopeKey.of(RResource.class), r);
    configurationScope.seed(
        ScopeKey.of(Manifest.class)
            .annotatedBy(
                "@javax.inject.Named(value=" + TransfuseAndroidModule.ORIGINAL_MANIFEST + ")"),
        manifest);

    TransfuseProcessor transfuseProcessor = processorProvider.get();

    if (!baseModuleConfiguration) {
      transfuseProcessor.submit(
          TransfuseModule.class,
          reloadableASTElementFactory.buildProviders(
              Collections.singleton(elements.getTypeElement(APIModule.class.getName()))));
      baseModuleConfiguration = true;
    }

    transfuseProcessor.submit(
        Application.class, buildASTCollection(roundEnvironment, Application.class));
    transfuseProcessor.submit(
        TransfuseModule.class, buildASTCollection(roundEnvironment, TransfuseModule.class));
    transfuseProcessor.submit(
        ImplementedBy.class, buildASTCollection(roundEnvironment, ImplementedBy.class));
    transfuseProcessor.submit(Factory.class, buildASTCollection(roundEnvironment, Factory.class));
    transfuseProcessor.submit(Activity.class, buildASTCollection(roundEnvironment, Activity.class));
    transfuseProcessor.submit(
        BroadcastReceiver.class, buildASTCollection(roundEnvironment, BroadcastReceiver.class));
    transfuseProcessor.submit(Service.class, buildASTCollection(roundEnvironment, Service.class));
    transfuseProcessor.submit(Fragment.class, buildASTCollection(roundEnvironment, Fragment.class));

    transfuseProcessor.execute();

    if (roundEnvironment.processingOver()) {
      transfuseProcessor.checkForErrors();
    }

    logger.info("Transfuse took " + (System.currentTimeMillis() - start) + "ms to process");

    configurationScope.exit();

    return true;
  }