コード例 #1
0
    ProcessorState(Processor p, Log log, Source source, ProcessingEnvironment env) {
      processor = p;
      contributed = false;

      try {
        processor.init(env);

        checkSourceVersionCompatibility(source, log);

        supportedAnnotationPatterns = new ArrayList<Pattern>();
        for (String importString : processor.getSupportedAnnotationTypes()) {
          supportedAnnotationPatterns.add(importStringToPattern(importString, processor, log));
        }

        supportedOptionNames = new ArrayList<String>();
        for (String optionName : processor.getSupportedOptions()) {
          if (checkOptionName(optionName, log)) supportedOptionNames.add(optionName);
        }

      } catch (ClientCodeException e) {
        throw e;
      } catch (Throwable t) {
        throw new AnnotationProcessingError(t);
      }
    }
コード例 #2
0
    /**
     * Checks whether or not a processor's source version is compatible with the compilation source
     * version. The processor's source version needs to be greater than or equal to the source
     * version of the compile.
     */
    private void checkSourceVersionCompatibility(Source source, Log log) {
      SourceVersion procSourceVersion = processor.getSupportedSourceVersion();

      if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0) {
        log.warning(
            "proc.processor.incompatible.source.version",
            procSourceVersion,
            processor.getClass().getName(),
            source.name);
      }
    }
コード例 #3
0
 /**
  * Convert import-style string for supported annotations into a regex matching that string. If the
  * string is a valid import-style string, return a regex that won't match anything.
  */
 private static Pattern importStringToPattern(String s, Processor p, Log log) {
   if (isValidImportString(s)) {
     return validImportStringToPattern(s);
   } else {
     log.warning("proc.malformed.supported.string", s, p.getClass().getName());
     return noMatches; // won't match any valid identifier
   }
 }
コード例 #4
0
 private boolean callProcessor(
     Processor proc, Set<? extends TypeElement> tes, RoundEnvironment renv) {
   try {
     return proc.process(tes, renv);
   } catch (BadClassFile ex) {
     log.error("proc.cant.access.1", ex.sym, ex.getDetailValue());
     return false;
   } catch (CompletionFailure ex) {
     StringWriter out = new StringWriter();
     ex.printStackTrace(new PrintWriter(out));
     log.error("proc.cant.access", ex.sym, ex.getDetailValue(), out.toString());
     return false;
   } catch (ClientCodeException e) {
     throw e;
   } catch (Throwable t) {
     throw new AnnotationProcessingError(t);
   }
 }
コード例 #5
0
 private boolean checkOptionName(String optionName, Log log) {
   boolean valid = isValidOptionName(optionName);
   if (!valid)
     log.error("proc.processor.bad.option.name", optionName, processor.getClass().getName());
   return valid;
 }