com.google.javascript.jscomp.Compiler.hasErrors()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 JavaScript  
字(9.6k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中com.google.javascript.jscomp.Compiler.hasErrors()方法的一些代码示例,展示了Compiler.hasErrors()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Compiler.hasErrors()方法的具体详情如下:
包路径:com.google.javascript.jscomp.Compiler
类名称:Compiler
方法名:hasErrors

Compiler.hasErrors介绍

[英]Consults the ErrorManager to see if we've encountered errors that should halt compilation.

If CompilerOptions#ideMode is true, this function always returns false without consulting the error manager. The error manager will continue to be told about new errors and warnings, but the compiler will complete compilation of all inputs.
[中]咨询ErrorManager,查看是否遇到了应停止编译的错误。
如果CompilerOptions#ideMode为true,则此函数始终返回false,而无需咨询错误管理器。错误管理器将继续被告知新的错误和警告,但编译器将完成所有输入的编译。

代码示例

代码示例来源:origin: com.google.javascript/closure-compiler

/**
 * Instrument code for coverage.
 *
 * <p>{@code parseForCompilation()} must be called before this method is called.
 *
 * <p>The caller is responsible for also calling {@code generateReport()} to generate a report of
 * warnings and errors to stderr. See the invocation in {@link #compile} for a good example.
 *
 * <p>This method is mutually exclusive with stage1Passes() and stage2Passes().
 * Either call those two methods or this one, but not both.
 */
public void instrumentForCoverage() {
 checkState(moduleGraph != null, "No inputs. Did you call init() or initModules()?");
 checkState(!hasErrors());
 runInCompilerThread(
   () -> {
    checkState(options.getInstrumentForCoverageOnly());
    checkState(!hasErrors());
    instrumentForCoverageInternal(options.instrumentBranchCoverage);
    return null;
   });
}

代码示例来源:origin: com.google.javascript/closure-compiler

/**
 * Perform compiler passes for stage 1 of compilation.
 *
 * <p>Stage 1 consists primarily of error and type checking passes.
 *
 * <p>{@code parseForCompilation()} must be called before this method is called.
 *
 * <p>The caller is responsible for also calling {@code generateReport()} to generate a report of
 * warnings and errors to stderr. See the invocation in {@link #compile} for a good example.
 */
public void stage1Passes() {
 checkState(moduleGraph != null, "No inputs. Did you call init() or initModules()?");
 checkState(!hasErrors());
 checkState(!options.getInstrumentForCoverageOnly());
 runInCompilerThread(
   () -> {
    performChecksAndTranspilation();
    return null;
   });
}

代码示例来源:origin: com.google.javascript/closure-compiler

@GwtIncompatible("Unnecessary")
private Result performStage1andSave(String filename) {
 Result result;
 try (BufferedOutputStream serializedOutputStream =
   new BufferedOutputStream(new FileOutputStream(filename))) {
  compiler.parseForCompilation();
  if (!compiler.hasErrors()) {
   compiler.stage1Passes();
  }
  if (!compiler.hasErrors()) {
   compiler.saveState(serializedOutputStream);
  }
  compiler.performPostCompilationTasks();
 } catch (IOException e) {
  compiler.report(JSError.make(COULD_NOT_SERIALIZE_AST, filename));
 } finally {
  // Make sure we generate a report of errors and warnings even if the compiler throws an
  // exception somewhere.
  compiler.generateReport();
 }
 result = compiler.getResult();
 return result;
}

代码示例来源:origin: com.google.javascript/closure-compiler

@GwtIncompatible("Unnecessary")
private Result performFullCompilation() {
 Result result;
 try {
  compiler.parseForCompilation();
  if (!compiler.hasErrors()) {
   compiler.stage1Passes();
   if (!compiler.hasErrors()) {
    compiler.stage2Passes();
   }
   compiler.performPostCompilationTasks();
  }
 } finally {
  // Make sure we generate a report of errors and warnings even if the compiler throws an
  // exception somewhere.
  compiler.generateReport();
 }
 result = compiler.getResult();
 return result;
}

代码示例来源:origin: org.apache.shindig/shindig-gadgets

private Compiler mockRealJsCompiler(JSError error, Result res, String toSource) {
 Compiler result = createMock(Compiler.class);
 expect(result.compile(EasyMock.<List<JSSourceFile>>anyObject(),
   EasyMock.<List<JSSourceFile>>anyObject(),
   isA(CompilerOptions.class))).andReturn(res);
 if (error != null) {
  expect(result.hasErrors()).andReturn(true);
  expect(result.getErrors()).andReturn(new JSError[] { error });
 } else {
  expect(result.hasErrors()).andReturn(false);
 }
 expect(result.getResult()).andReturn(res);
 expect(result.toSource()).andReturn(toSource);
 replay(result);
 return result;
}

代码示例来源:origin: com.google.javascript/closure-compiler

@GwtIncompatible("Unnecessary")
private Result restoreAndPerformStage2(String filename) {
 Result result;
 try (BufferedInputStream serializedInputStream =
   new BufferedInputStream(new FileInputStream(filename))) {
  compiler.restoreState(serializedInputStream);
  if (!compiler.hasErrors()) {
    compiler.stage2Passes();
  }
  compiler.performPostCompilationTasks();
 } catch (IOException | ClassNotFoundException e) {
  compiler.report(JSError.make(COULD_NOT_DESERIALIZE_AST, filename));
 } finally {
  // Make sure we generate a report of errors and warnings even if the compiler throws an
  // exception somewhere.
  compiler.generateReport();
 }
 result = compiler.getResult();
 return result;
}

代码示例来源:origin: com.google.javascript/closure-compiler

printConfig(System.err);
if (!hasErrors()) {
 parseForCompilation();
if (!hasErrors()) {
 if (options.getInstrumentForCoverageOnly()) {
 } else {
  stage1Passes();
  if (!hasErrors()) {
   stage2Passes();

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets

private Compiler mockRealJsCompiler(JSError error, Result res, String toSource) {
 Compiler result = createMock(Compiler.class);
 expect(result.compile(EasyMock.<List<JSSourceFile>>anyObject(),
   EasyMock.<List<JSSourceFile>>anyObject(),
   isA(CompilerOptions.class))).andReturn(res);
 if (error != null) {
  expect(result.hasErrors()).andReturn(true);
  expect(result.getErrors()).andReturn(new JSError[] { error });
 } else {
  expect(result.hasErrors()).andReturn(false);
 }
 expect(result.getResult()).andReturn(res);
 expect(result.toSource()).andReturn(toSource);
 replay(result);
 return result;
}

代码示例来源:origin: com.google.javascript/closure-compiler

printConfig(System.err);
if (!hasErrors()) {
 parseForCompilation();
if (!hasErrors()) {
 } else {
  stage1Passes();
  if (!hasErrors()) {
   stage2Passes();

代码示例来源:origin: com.google.javascript/closure-compiler

@GwtIncompatible("Unnecessary")
private Result instrumentForCoverage() {
 Result result;
 try {
  compiler.parseForCompilation();
  if (!compiler.hasErrors()) {
   compiler.instrumentForCoverage();
  }
 } finally {
  compiler.generateReport();
 }
 result = compiler.getResult();
 return result;
}

代码示例来源:origin: com.google.javascript/closure-compiler

checkState(!hasErrors());
checkState(!options.getInstrumentForCoverageOnly());
JSModule weakModule = moduleGraph.getModuleByName(JSModule.WEAK_MODULE_NAME);

代码示例来源:origin: org.scala-js/closure-compiler-java-6

/**
 * Compiles a list of inputs.
 */
public <T1 extends SourceFile, T2 extends SourceFile> Result compile(
  List<T1> externs, List<T2> inputs, CompilerOptions options) {
 // The compile method should only be called once.
 Preconditions.checkState(jsRoot == null);
 try {
  init(externs, inputs, options);
  if (hasErrors()) {
   return getResult();
  }
  return compile();
 } finally {
  Tracer t = newTracer("generateReport");
  errorManager.generateReport();
  stopTracer(t, "generateReport");
 }
}

代码示例来源:origin: org.scala-js/closure-compiler-java-6

/**
 * Compiles a list of modules.
 */
public <T extends SourceFile> Result compileModules(List<T> externs,
  List<JSModule> modules, CompilerOptions options) {
 // The compile method should only be called once.
 Preconditions.checkState(jsRoot == null);
 try {
  initModules(externs, modules, options);
  if (hasErrors()) {
   return getResult();
  }
  return compile();
 } finally {
  Tracer t = newTracer("generateReport");
  errorManager.generateReport();
  stopTracer(t, "generateReport");
 }
}

代码示例来源:origin: com.google.javascript/closure-compiler

public void transpileAndDontCheck() {
 Tracer t = newTracer("runTranspileOnlyPasses");
 try {
  for (PassFactory pf : getPassConfig().getTranspileOnlyPasses()) {
   if (hasErrors()) {
    return;
   }
   pf.create(this).process(externsRoot, jsRoot);
  }
 } finally {
  stopTracer(t, "runTranspileOnlyPasses");
 }
}

代码示例来源:origin: org.scala-js/closure-compiler-java-6

public void check() {
 runCustomPasses(CustomPassExecutionTime.BEFORE_CHECKS);
 // We are currently only interested in check-passes for progress reporting
 // as it is used for IDEs, that's why the maximum progress is set to 1.0.
 phaseOptimizer = new PhaseOptimizer(this, tracker,
   new PhaseOptimizer.ProgressRange(getProgress(), 1.0));
 if (options.devMode == DevMode.EVERY_PASS) {
  phaseOptimizer.setSanityCheck(sanityCheck);
 }
 if (options.getCheckDeterminism()) {
  phaseOptimizer.setPrintAstHashcodes(true);
 }
 phaseOptimizer.consume(getPassConfig().getChecks());
 phaseOptimizer.process(externsRoot, jsRoot);
 if (hasErrors()) {
  return;
 }
 if (options.getTweakProcessing().shouldStrip() ||
   !options.stripTypes.isEmpty() ||
   !options.stripNameSuffixes.isEmpty() ||
   !options.stripTypePrefixes.isEmpty() ||
   !options.stripNamePrefixes.isEmpty()) {
  stripCode(options.stripTypes, options.stripNameSuffixes,
    options.stripTypePrefixes, options.stripNamePrefixes);
 }
 runCustomPasses(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS);
 phaseOptimizer = null;
}

代码示例来源:origin: org.scala-js/closure-compiler-java-6

if (hasErrors()) {
  return null;
if (hasErrors()) {
 return null;
  if (hasErrors()) {
   return null;
if (hasErrors()) {
 return null;

代码示例来源:origin: com.google.javascript/closure-compiler

} else if (compiler.hasErrors()) {

代码示例来源:origin: com.google.javascript/closure-compiler

void check() {
 runCustomPasses(CustomPassExecutionTime.BEFORE_CHECKS);
 // We are currently only interested in check-passes for progress reporting
 // as it is used for IDEs, that's why the maximum progress is set to 1.0.
 phaseOptimizer = createPhaseOptimizer().withProgress(
   new PhaseOptimizer.ProgressRange(getProgress(), 1.0));
 phaseOptimizer.consume(getPassConfig().getChecks());
 phaseOptimizer.process(externsRoot, jsRoot);
 if (hasErrors()) {
  return;
 }
 runCustomPasses(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS);
 phaseOptimizer = null;
}

代码示例来源:origin: org.scala-js/closure-compiler-java-6

if (hasErrors()) {
 return;
 if (hasErrors()) {
  return;

代码示例来源:origin: com.google.javascript/closure-compiler

if (hasErrors()) {
  return null;
if (hasErrors()) {
 return null;
 if (devMode) {
  runValidityCheck();
  if (hasErrors()) {
   return null;
if (hasErrors()) {
 return null;

相关文章

Compiler类方法