예제 #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;
      }
    }
  }
 @Override
 public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   for (TypeElement elem : ElementFilter.typesIn(roundEnv.getRootElements())) {
     elements.add(elem.getQualifiedName());
   }
   return false;
 }
예제 #3
0
 public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
   Trees trees = Trees.instance(processingEnv);
   Test test = new Test();
   for (Element e : rEnv.getRootElements()) {
     Tree t = trees.getTree(e);
     test.scan(t, null);
   }
   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;
  }
예제 #5
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;
 }
예제 #6
0
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (processingEnv.getOptions().containsKey(Const.CONFIG_FILE_OPTION.getValue())) {
      String value = processingEnv.getOptions().get(Const.CONFIG_FILE_OPTION.getValue());

      // For multiple config files we are following the format
      // -Aconfig=foo.config:bar.config where : is the pathSeparatorChar
      StringTokenizer st = new StringTokenizer(value, File.pathSeparator);
      if (!st.hasMoreTokens()) {
        errorListener.error(
            null, Messages.OPERAND_MISSING.format(Const.CONFIG_FILE_OPTION.getValue()));
        return true;
      }

      while (st.hasMoreTokens()) {
        File configFile = new File(st.nextToken());
        if (!configFile.exists()) {
          errorListener.error(null, Messages.NON_EXISTENT_FILE.format());
          continue;
        }

        try {
          Collection<TypeElement> rootElements = new ArrayList<TypeElement>();
          filterClass(rootElements, roundEnv.getRootElements());
          ConfigReader configReader =
              new ConfigReader(processingEnv, rootElements, configFile, errorListener);

          Collection<Reference> classesToBeIncluded = configReader.getClassesToBeIncluded();
          J2SJAXBModel model =
              XJC.createJavaCompiler()
                  .bind(
                      classesToBeIncluded,
                      Collections.<QName, Reference>emptyMap(),
                      null,
                      processingEnv);

          SchemaOutputResolver schemaOutputResolver = configReader.getSchemaOutputResolver();

          model.generateSchema(schemaOutputResolver, errorListener);
        } catch (IOException e) {
          errorListener.error(e.getMessage(), e);
        } catch (SAXException e) {
          // the error should have already been reported
        }
      }
    }
    return true;
  }
예제 #7
0
 private Set<TypeElement> getTypesToProcess(State state, RoundEnvironment roundEnv) {
   if (rootOverride == null) {
     return ElementFilter.typesIn(roundEnv.getRootElements());
   }
   Set<TypeElement> toScan = new HashSet<TypeElement>();
   for (String binaryTypeName : rootOverride) {
     TypeElement found =
         state.elements.getTypeElement(BinaryName.toSourceName(binaryTypeName.trim()));
     if (found == null) {
       state.poison(null, Messages.noSuchType(binaryTypeName));
     } else {
       toScan.add(found);
     }
   }
   rootOverride = null;
   return toScan;
 }
예제 #8
0
 @Override
 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   for (TypeElement te : ElementFilter.typesIn(roundEnv.getRootElements())) {
     if (isSimpleName(te, "InvalidSource")) {
       for (Element c : te.getEnclosedElements()) {
         for (AnnotationMirror am : c.getAnnotationMirrors()) {
           Element ate = am.getAnnotationType().asElement();
           if (isSimpleName(ate, "ExpectInterfaces")) {
             checkInterfaces((TypeElement) c, getValue(am));
           } else if (isSimpleName(ate, "ExpectSupertype")) {
             checkSupertype((TypeElement) c, getValue(am));
           }
         }
       }
     }
   }
   return true;
 }
예제 #9
0
    @DefinedBy(Api.ANNOTATION_PROCESSING)
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
      try {
        Set<TypeElement> classes = getAllClasses(ElementFilter.typesIn(roundEnv.getRootElements()));
        if (classes.size() > 0) {
          checkMethodParameters(classes);
          g.setProcessingEnvironment(processingEnv);
          g.setClasses(classes);
          g.run();
        }
      } catch (CompletionFailure cf) {
        messager.printMessage(
            ERROR, getMessage("class.not.found", cf.sym.getQualifiedName().toString()));
      } catch (ClassNotFoundException cnfe) {
        messager.printMessage(ERROR, getMessage("class.not.found", cnfe.getMessage()));
      } catch (IOException ioe) {
        messager.printMessage(ERROR, getMessage("io.exception", ioe.getMessage()));
      } catch (Util.Exit e) {
        exit = e;
      }

      return true;
    }