Exemplo n.º 1
0
 private static void checkErrors() {
   int errors = ErrorUtil.errorCount();
   if (Options.treatWarningsAsErrors()) {
     errors += ErrorUtil.warningCount();
   }
   if (errors > 0) {
     System.exit(errors);
   }
 }
Exemplo n.º 2
0
  /**
   * Runs the entire J2Swift pipeline.
   *
   * @param fileArgs the files to process, same format as command-line args to {@link #main}.
   */
  public static void run(List<String> fileArgs) {
    File preProcessorTempDir = null;
    File strippedSourcesDir = null;
    try {
      JdtParser parser = createParser();

      List<ProcessingContext> inputs = Lists.newArrayList();
      GenerationBatch batch = new GenerationBatch();
      batch.processFileArgs(fileArgs);
      inputs.addAll(batch.getInputs());
      if (ErrorUtil.errorCount() > 0) {
        return;
      }
      InputFilePreprocessor inputFilePreprocessor = new InputFilePreprocessor(parser);
      inputFilePreprocessor.processInputs(inputs);
      if (ErrorUtil.errorCount() > 0) {
        return;
      }
      strippedSourcesDir = inputFilePreprocessor.getStrippedSourcesDir();
      if (strippedSourcesDir != null) {
        parser.prependSourcepathEntry(strippedSourcesDir.getPath());
      }

      Options.getHeaderMap().loadMappings();
      TranslationProcessor translationProcessor =
          new TranslationProcessor(parser, loadDeadCodeMap());
      translationProcessor.processInputs(inputs);
      translationProcessor.processBuildClosureDependencies();
      if (ErrorUtil.errorCount() > 0) {
        return;
      }
      translationProcessor.postProcess();

      Options.getHeaderMap().printMappings();
    } finally {
      FileUtil.deleteTempDir(preProcessorTempDir);
      FileUtil.deleteTempDir(strippedSourcesDir);
    }
  }
Exemplo n.º 3
0
  public static void translate(String[] args) {
    if (args.length == 0) {
      Options.help(true);
    }
    String[] files = null;
    try {
      files = Options.load(args);
      if (files.length == 0) {
        Options.usage("no source files");
      }
    } catch (IOException e) {
      ErrorUtil.error(e.getMessage());
      System.exit(1);
    }

    run(Arrays.asList(files));

    checkErrors();
  }