当前位置: 首页>>代码示例>>Java>>正文


Java Compiler.setErrorManager方法代码示例

本文整理汇总了Java中com.google.javascript.jscomp.Compiler.setErrorManager方法的典型用法代码示例。如果您正苦于以下问题:Java Compiler.setErrorManager方法的具体用法?Java Compiler.setErrorManager怎么用?Java Compiler.setErrorManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.jscomp.Compiler的用法示例。


在下文中一共展示了Compiler.setErrorManager方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCompiler

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
private Compiler createCompiler(CompilerOptions options) {
  Compiler compiler = new Compiler();
  MessageFormatter formatter =
      options.errorFormat.toFormatter(compiler, false);
  AntErrorManager errorManager = new AntErrorManager(formatter, this);
  compiler.setErrorManager(errorManager);
  return compiler;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:9,代码来源:CompileTask.java

示例2: build

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
public static String build(Task task, List<File> inputs) {
  List<SourceFile> externs;
  try {
    externs = CommandLineRunner.getDefaultExterns();
  } catch (IOException e) {
    throw new BuildException(e);
  }

  List<SourceFile> jsInputs = new ArrayList<SourceFile>();
  for (File f : inputs) {
    jsInputs.add(SourceFile.fromFile(f));
  }

  CompilerOptions options = new CompilerOptions();
  CompilationLevel.ADVANCED_OPTIMIZATIONS
      .setOptionsForCompilationLevel(options);
  WarningLevel.VERBOSE.setOptionsForWarningLevel(options);
  for (DiagnosticGroup dg : diagnosticGroups) {
    options.setWarningLevel(dg, CheckLevel.ERROR);
  }

  options.setCodingConvention(new GoogleCodingConvention());

  Compiler compiler = new Compiler();
  MessageFormatter formatter =
      options.errorFormat.toFormatter(compiler, false);
  AntErrorManager errorManager = new AntErrorManager(formatter, task);
  compiler.setErrorManager(errorManager);

  Result r = compiler.compile(externs, jsInputs, options);
  if (!r.success) {
    return null;
  }

  String wrapped = "(function(){" + compiler.toSource() + "})();\n";
  return wrapped;
}
 
开发者ID:google,项目名称:caja,代码行数:38,代码来源:ClosureCompiler.java

示例3: createCompiler

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
private Compiler createCompiler(CompilerOptions options) {
  Compiler compiler = new Compiler();
  MessageFormatter formatter =
      options.getErrorFormat().toFormatter(compiler, false);
  AntErrorManager errorManager = new AntErrorManager(formatter, this);
  compiler.setErrorManager(errorManager);
  return compiler;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:9,代码来源:CompileTask.java

示例4: parse

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
private Node parse(String source, String expected, LanguageMode languageIn) {
  CompilerOptions options = new CompilerOptions();
  options.setLanguageIn(languageIn);
  options.setLanguageOut(LanguageMode.ECMASCRIPT6_TYPED);
  options.setPreserveTypeAnnotations(true);
  options.setPrettyPrint(true);
  options.setLineLengthThreshold(80);
  options.setPreferSingleQuotes(true);

  Compiler compiler = new Compiler();
  compiler.setErrorManager(testErrorManager);
  compiler.initOptions(options);

  Node script = compiler.parse(SourceFile.fromCode("[test]", source));

  // Verifying that all warnings were seen
  assertTrue("Missing an error", testErrorManager.hasEncounteredAllErrors());
  assertTrue("Missing a warning", testErrorManager.hasEncounteredAllWarnings());

  if (script != null && testErrorManager.getErrorCount() == 0) {
    // if it can be parsed, it should round trip.
    String actual = new CodePrinter.Builder(script)
        .setCompilerOptions(options)
        .setTypeRegistry(compiler.getTypeIRegistry())
        .build() // does the actual printing.
        .trim();
    assertThat(actual).isEqualTo(expected);
  }

  return script;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:32,代码来源:TypeSyntaxTest.java

示例5: compile

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
/**
 * Public compiler call. Exposed in {@link #exportCompile}.
 */
public static ModuleOutput compile(Flags flags) {
  String[] unhandled = updateFlags(flags, defaultFlags);
  if (unhandled.length > 0) {
    throw new RuntimeException("Unhandled flag: " + unhandled[0]);
  }

  List<SourceFile> jsCode = fromFileArray(flags.jsCode, "Input_");
  ImmutableMap<String, SourceMapInput> sourceMaps = buildSourceMaps(flags.jsCode, "Input_");

  CompilerOptions options = new CompilerOptions();
  applyDefaultOptions(options);
  applyOptionsFromFlags(options, flags);
  options.setInputSourceMaps(sourceMaps);
  disableUnsupportedOptions(options);

  List<SourceFile> externs = fromFileArray(flags.externs, "Extern_");
  externs.addAll(createExterns(options.getEnvironment()));

  NodeErrorManager errorManager = new NodeErrorManager();
  Compiler compiler = new Compiler(new NodePrintStream());
  compiler.setErrorManager(errorManager);
  compiler.compile(externs, jsCode, options);

  ModuleOutput output = new ModuleOutput();
  output.compiledCode = writeOutput(compiler, flags.outputWrapper);
  output.errors = toNativeErrorArray(errorManager.errors);
  output.warnings = toNativeErrorArray(errorManager.warnings);

  if (flags.createSourceMap) {
    StringBuilder b = new StringBuilder();
    try {
      compiler.getSourceMap().appendTo(b, "");
    } catch (IOException e) {
      // ignore
    }
    output.sourceMap = b.toString();
  }

  return output;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:44,代码来源:GwtRunner.java

示例6: parseString

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
/**
 * Takes a source string and returns a google closure compiler. The caller must do the error checking and act
 * accordingly.
 */
private static Compiler parseString(String sourceString) {
    Compiler compiler = new Compiler();
    ErrorManager em = new ErrorManager() {
        private int numErrs = 0;
        private JSError err;

        @Override
        public void report(CheckLevel checkLevel, JSError jsError) {
            if (checkLevel.compareTo(CheckLevel.ERROR) == 0) {
                numErrs++;
                err = jsError;
            }
        }

        @Override
        public void generateReport() { }

        @Override
        public int getErrorCount() { return numErrs; }

        @Override
        public int getWarningCount() { return 0; }

        @Override
        public JSError[] getErrors() {
            // Useful for debugging and doesn't cost anything to have in here.
            JSError[] tmp = new JSError[1];
            tmp[0] = err;
            return tmp;
        }

        @Override
        public JSError[] getWarnings() { return new JSError[0]; }

        @Override
        public void setTypedPercent(double v) { }

        @Override
        public double getTypedPercent() { return 0; }
    };
    compiler.setErrorManager(em);
    CompilerOptions options = new CompilerOptions();
    // Try very hard to interpret the meaning of our code string.
    options.setIdeMode(true);
    options.setOutputCharset("UTF-8");
    // We only care about the AST, and that is gotten through "compiling" whitespace mode only.
    CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(options);

    JSSourceFile dummy = JSSourceFile.fromCode("dummy.js", "");

    compiler.compile(dummy, JSSourceFile.fromCode("input.js", sourceString), options);
    return compiler;
}
 
开发者ID:cursem,项目名称:ScriptCompressor,代码行数:58,代码来源:Unevalizer.java


注:本文中的com.google.javascript.jscomp.Compiler.setErrorManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。