Exemplo n.º 1
0
 boolean process(String option, String operand) {
   Source source = Source.lookup(operand);
   if (source == null) {
     error("err.invalid.source", operand);
     return true;
   } else if (source.compareTo(Source.JDK1_5) > 0) {
     error("err.unsupported.source.version", operand);
     return true;
   }
   return super.process(option, operand);
 }
  public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) {
    this.context = context;
    log = Log.instance(context);
    source = Source.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    options = Options.instance(context);
    printProcessorInfo = options.isSet(XPRINTPROCESSORINFO);
    printRounds = options.isSet(XPRINTROUNDS);
    verbose = options.isSet(VERBOSE);
    lint = Lint.instance(context).isEnabled(PROCESSING);
    procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT);
    fatalErrors = options.isSet("fatalEnterError");
    showResolveErrors = options.isSet("showResolveErrors");
    werror = options.isSet(WERROR);
    platformAnnotations = initPlatformAnnotations();
    foundTypeProcessors = false;

    // Initialize services before any processors are initialized
    // in case processors use them.
    filer = new JavacFiler(context);
    messager = new JavacMessager(context, this);
    elementUtils = JavacElements.instance(context);
    typeUtils = JavacTypes.instance(context);
    processorOptions = initProcessorOptions(context);
    unmatchedProcessorOptions = initUnmatchedProcessorOptions();
    messages = JavacMessages.instance(context);
    initProcessorIterator(context, processors);
  }
    /**
     * 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);
      }
    }
Exemplo n.º 4
0
  /**
   * Process command line arguments: store all command line options in `options' table and return
   * all source filenames.
   *
   * @param args The array of command line arguments.
   */
  protected java.util.List<String> processArgs(String[] flags) {
    int ac = 0;
    while (ac < flags.length) {
      String flag = flags[ac];
      ac++;

      int j;
      for (j = 0; j < recognizedOptions.length; j++) if (recognizedOptions[j].matches(flag)) break;

      if (j == recognizedOptions.length) {
        error("err.invalid.flag", flag);
        return null;
      }

      Option option = recognizedOptions[j];
      if (option.hasArg()) {
        if (ac == flags.length) {
          error("err.req.arg", flag);
          return null;
        }
        String operand = flags[ac];
        ac++;
        if (option.process(flag, operand)) return null;
      } else {
        if (option.process(flag)) return null;
      }
    }

    String sourceString = options.get("-source");
    Source source =
        (sourceString != null)
            ? Source.lookup(sourceString)
            : Source.JDK1_5; // JDK 5 is the latest supported source version
    String targetString = options.get("-target");
    Target target =
        (targetString != null)
            ? Target.lookup(targetString)
            : Target.JDK1_5; // JDK 5 is the latest supported source version
    // We don't check source/target consistency for CLDC, as J2ME
    // profiles are not aligned with J2SE targets; moreover, a
    // single CLDC target may have many profiles.  In addition,
    // this is needed for the continued functioning of the JSR14
    // prototype.
    if (Character.isDigit(target.name.charAt(0)) && target.compareTo(source.requiredTarget()) < 0) {
      if (targetString != null) {
        if (sourceString == null) {
          warning(
              "warn.target.default.source.conflict", targetString, source.requiredTarget().name);
        } else {
          warning("warn.source.target.conflict", sourceString, source.requiredTarget().name);
        }
        return null;
      } else {
        options.put("-target", source.requiredTarget().name);
      }
    }
    return sourceFileNames;
  }
Exemplo n.º 5
0
  /**
   * Process command line arguments: store all command line options in `options' table and return
   * all source filenames.
   *
   * @param flags The array of command line arguments.
   */
  public List<File> processArgs(String[] flags) { // XXX sb protected
    int ac = 0;
    while (ac < flags.length) {
      String flag = flags[ac];
      ac++;

      int j;
      // quick hack to speed up file processing:
      // if the option does not begin with '-', there is no need to check
      // most of the compiler options.
      int firstOptionToCheck = flag.charAt(0) == '-' ? 0 : recognizedOptions.length - 1;
      for (j = firstOptionToCheck; j < recognizedOptions.length; j++)
        if (recognizedOptions[j].matches(flag)) break;

      if (j == recognizedOptions.length) {
        error("err.invalid.flag", flag);
        return null;
      }

      Option option = recognizedOptions[j];
      if (option.hasArg()) {
        if (ac == flags.length) {
          error("err.req.arg", flag);
          return null;
        }
        String operand = flags[ac];
        ac++;
        if (option.process(options, flag, operand)) return null;
      } else {
        if (option.process(options, flag)) return null;
      }
    }

    if (!checkDirectory("-d")) return null;
    if (!checkDirectory("-s")) return null;

    String sourceString = options.get("-source");
    Source source = (sourceString != null) ? Source.lookup(sourceString) : Source.DEFAULT;
    String targetString = options.get("-target");
    Target target = (targetString != null) ? Target.lookup(targetString) : Target.DEFAULT;
    // We don't check source/target consistency for CLDC, as J2ME
    // profiles are not aligned with J2SE targets; moreover, a
    // single CLDC target may have many profiles.  In addition,
    // this is needed for the continued functioning of the JSR14
    // prototype.
    if (Character.isDigit(target.name.charAt(0))) {
      if (target.compareTo(source.requiredTarget()) < 0) {
        if (targetString != null) {
          if (sourceString == null) {
            warning(
                "warn.target.default.source.conflict", targetString, source.requiredTarget().name);
          } else {
            warning("warn.source.target.conflict", sourceString, source.requiredTarget().name);
          }
          return null;
        } else {
          options.put("-target", source.requiredTarget().name);
        }
      } else {
        if (targetString == null && !source.allowGenerics()) {
          options.put("-target", Target.JDK1_4.name);
        }
      }
    }
    return filenames.toList();
  }
 public SourceVersion getSourceVersion() {
   return Source.toSourceVersion(source);
 }