Exemplo n.º 1
0
  @Override
  protected void exitBean(AbstractBean bean) {
    beans.pop();

    if (bean.getProperties().isEmpty() == false) {
      return;
    }
    if (bean.getNestedBeans().isEmpty() == false) {
      return;
    }

    // metadata was specifically requested for this bean
    if (bean.getElement().getAnnotation(Meta.class) != null) {
      return;
    }

    // remove this bean because its empty

    if (beans.isEmpty()) {
      // top level bean
      space.remove(bean.getElement());
    } else {
      // nested bean
      beans.peek().getNestedBeans().remove(bean.getElement());
    }
  }
Exemplo n.º 2
0
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment round) {

    environment.getMessager().printMessage(Kind.NOTE, "MetaGen");

    logger.log("");
    logger.log("STARTED ROUND");
    logger.log("");

    BeanSpace beans = new BeanSpace();
    try {
      // TODO this should prob delegate to beanspace.add(element);
      // TODO beanspace should check if element is supported and error
      // otherwise
      for (TypeElement annotation : annotations) {
        logger.log("Processing annotation: %s", annotation.getQualifiedName());

        for (Element annotated : round.getElementsAnnotatedWith(annotation)) {
          TypeElement element = null;
          switch (annotated.getKind()) {
            case CLASS:
            case ENUM:
              element = (TypeElement) annotated;

              logger.log("Processing annotated class/enum: %s", element.getQualifiedName());

              if (accept(element)) {
                beans.add(element);
              }
              break;
            case FIELD:
            case METHOD:
              element = (TypeElement) annotated.getEnclosingElement();

              logger.log(
                  "Processing class/enum: %s derived from annotated element: %s",
                  element.getQualifiedName(), annotated.getSimpleName());

              if (accept(element)) {
                beans.add(element);
              }
              break;
            default:
              logger.log(
                  "Ignored element: %s of kind: %s",
                  annotated.getSimpleName(), annotated.getKind());
          }
        }
      }

      beans.accept(new PropertyResolvingVisitor(resolvers));
      // beans.accept(new PrintVisitor());
      beans.accept(new TrimmingVisitor());

      beans.accept(new ValidatingVisitor(environment));
      beans.accept(new SuperclassResolvingVisitor());

      beans.accept(new TrimmingVisitor());

      beans.accept(new CodeGeneratingVisitor(environment));

      logger.log("");
      logger.log("ROUND COMPLETED");
      logger.log("");

      // return false so we do not claim annotaitons like @Entity
      return false;
    } catch (RuntimeException e) {
      e.printStackTrace();
      logger.log("Error: %s", e.getMessage());
      environment.getMessager().printMessage(Kind.ERROR, e.getMessage());
      throw e;
    }
  }