private void test(String js, FunctionInformationMap expected) {
   Compiler compiler = new Compiler();
   compiler.init(
       new JSSourceFile[] {JSSourceFile.fromCode("externs", "")},
       new JSSourceFile[] {JSSourceFile.fromCode("testcode", js)},
       new CompilerOptions());
   test(compiler, expected);
 }
示例#2
0
  /**
   * @return a mutable list
   * @throws IOException
   */
  public static List<JSSourceFile> getDefaultExterns() throws IOException {
    InputStream input = CommandLineRunner.class.getResourceAsStream("/externs.zip");
    ZipInputStream zip = new ZipInputStream(input);
    Map<String, JSSourceFile> externsMap = Maps.newHashMap();
    for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null; ) {
      LimitInputStream entryStream = new LimitInputStream(zip, entry.getSize());
      externsMap.put(
          entry.getName(),
          JSSourceFile.fromInputStream(
              // Give the files an odd prefix, so that they do not conflict
              // with the user's files.
              "externs.zip//" + entry.getName(), entryStream));
    }

    Preconditions.checkState(
        externsMap.keySet().equals(Sets.newHashSet(DEFAULT_EXTERNS_NAMES)),
        "Externs zip must match our hard-coded list of externs.");

    // Order matters, so the resources must be added to the result list
    // in the expected order.
    List<JSSourceFile> externs = Lists.newArrayList();
    for (String key : DEFAULT_EXTERNS_NAMES) {
      externs.add(externsMap.get(key));
    }

    return externs;
  }
 private void test(JSModule[] modules, FunctionInformationMap expected) {
   Compiler compiler = new Compiler();
   compiler.init(
       new JSSourceFile[] {JSSourceFile.fromCode("externs", "")}, modules, new CompilerOptions());
   test(compiler, expected);
 }