Example #1
0
  @Override
  protected boolean onProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e : roundEnv.getElementsAnnotatedWith(BeanFactoryExtension.class)) {
      TypeElement factoryElement = (TypeElement) e;
      factories.add(factoryElement.getQualifiedName().toString());
    }

    for (Element e : roundEnv.getElementsAnnotatedWith(AutoBeanFactory.Category.class)) {
      AnnotationMirror categoryAnnotation =
          MoreElements.getAnnotationMirror(e, AutoBeanFactory.Category.class).get();
      AnnotationValue value = AnnotationMirrors.getAnnotationValue(categoryAnnotation, "value");
      Collection<String> categories = extractValue(value);
      this.categories.addAll(categories);
    }

    if (!factories.isEmpty()) {
      debug("Generating composite bean factory");
      code(
          BEAN_FACTORY_TEMPLATE,
          BEAN_FACTORY_PACKAGE,
          BEAN_FACTORY_CLASS,
          () -> {
            Map<String, Object> context = new HashMap<>();
            context.put("packageName", BEAN_FACTORY_PACKAGE);
            context.put("className", BEAN_FACTORY_CLASS);
            context.put("factories", factories);
            context.put("categories", categories);
            return context;
          });

      info("Successfully generated composite bean factory [%s].", BEAN_FACTORY_CLASS);
      factories.clear();
      categories.clear();
    }
    return false;
  }