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

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

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

Compiler.runInCompilerThread介绍

[英]The primary purpose of this method is to run the provided code with a larger than standard stack.
[中]此方法的主要目的是使用比标准堆栈更大的堆栈运行提供的代码。

代码示例

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

private Result compile() {
 return runInCompilerThread(new Callable<Result>() {
  @Override
  public Result call() throws Exception {
   compileInternal();
   return getResult();
  }
 });
}

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

void orderInputsWithLargeStack() {
 runInCompilerThread(new Callable<Void>() {
  @Override
  public Void call() throws Exception {
   Tracer tracer = newTracer("orderInputsWithLargeStack");
   try {
    orderInputs();
   } finally {
    stopTracer(tracer, "orderInputsWithLargeStack");
   }
   return null;
  }
 });
}

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

/**
 * Converts the parse tree for each input back to JS code.
 */
public String[] toSourceArray() {
 return runInCompilerThread(new Callable<String[]>() {
  @Override
  public String[] call() throws Exception {
   Tracer tracer = newTracer("toSourceArray");
   try {
    int numInputs = inputs.size();
    String[] sources = new String[numInputs];
    CodeBuilder cb = new CodeBuilder();
    for (int i = 0; i < numInputs; i++) {
     Node scriptNode = inputs.get(i).getAstRoot(Compiler.this);
     cb.reset();
     toSource(cb, i, scriptNode);
     sources[i] = cb.toString();
    }
    return sources;
   } finally {
    stopTracer(tracer, "toSourceArray");
   }
  }
 });
}

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

/**
 * Converts the main parse tree back to JS code.
 */
@Override
public String toSource() {
 return runInCompilerThread(new Callable<String>() {
  @Override
  public String call() throws Exception {
   Tracer tracer = newTracer("toSource");
   try {
    CodeBuilder cb = new CodeBuilder();
    if (jsRoot != null) {
     int i = 0;
     for (Node scriptNode = jsRoot.getFirstChild();
        scriptNode != null;
        scriptNode = scriptNode.getNext()) {
      toSource(cb, i++, scriptNode);
     }
    }
    return cb.toString();
   } finally {
    stopTracer(tracer, "toSource");
   }
  }
 });
}

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

/**
 * Converts the parse tree for each input in a module back to JS code.
 */
public String[] toSourceArray(final JSModule module) {
 return runInCompilerThread(new Callable<String[]>() {
  @Override
  public String[] call() throws Exception {
   List<CompilerInput> inputs = module.getInputs();
   int numInputs = inputs.size();
   if (numInputs == 0) {
    return new String[0];
   }
   String[] sources = new String[numInputs];
   CodeBuilder cb = new CodeBuilder();
   for (int i = 0; i < numInputs; i++) {
    Node scriptNode = inputs.get(i).getAstRoot(Compiler.this);
    if (scriptNode == null) {
     throw new IllegalArgumentException(
       "Bad module input: " + inputs.get(i).getName());
    }
    cb.reset();
    toSource(cb, i, scriptNode);
    sources[i] = cb.toString();
   }
   return sources;
  }
 });
}

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

final int inputSeqNum,
          final Node root) {
runInCompilerThread(new Callable<Void>() {
 @Override
 public Void call() throws Exception {

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

/**
 * Converts the parse tree for a module back to JS code.
 */
public String toSource(final JSModule module) {
 return runInCompilerThread(new Callable<String>() {
  @Override
  public String call() throws Exception {
   List<CompilerInput> inputs = module.getInputs();
   int numInputs = inputs.size();
   if (numInputs == 0) {
    return "";
   }
   CodeBuilder cb = new CodeBuilder();
   for (int i = 0; i < numInputs; i++) {
    Node scriptNode = inputs.get(i).getAstRoot(Compiler.this);
    if (scriptNode == null) {
     throw new IllegalArgumentException(
       "Bad module: " + module.getName());
    }
    toSource(cb, i, scriptNode);
   }
   return cb.toString();
  }
 });
}

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

/**
 * Performs all the bookkeeping required at the end of a compilation.
 *
 * <p>This method must be called if the compilation makes it as far as doing checks.
 * <p> DON'T call it if the compiler threw an exception.
 * <p> DO call it even when {@code hasErrors()} returns true.
 */
public void performPostCompilationTasks() {
 runInCompilerThread(
   () -> {
    performPostCompilationTasksInternal();
    return null;
   });
}

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

/**
 * Parses input files in preparation for compilation.
 *
 * <p>Either {@code init()} or {@code initModules()} must be called first to set up the input
 * files to be read.
 * <p>TODO(bradfordcsmith): Rename this to parse()
 */
public void parseForCompilation() {
 runInCompilerThread(
   () -> {
    parseForCompilationInternal();
    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

void orderInputsWithLargeStack() {
 runInCompilerThread(
   () -> {
    Tracer tracer = newTracer("orderInputsWithLargeStack");
    try {
     orderInputs();
    } finally {
     stopTracer(tracer, "orderInputsWithLargeStack");
    }
    return null;
   });
}

代码示例来源: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

@GwtIncompatible("ObjectOutputStream")
public void saveState(OutputStream outputStream) throws IOException {
 // Do not close the outputstream, caller is responsible for closing it.
 final ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
 runInCompilerThread(
   () -> {
    Tracer tracer = newTracer("serializeCompilerState");
    objectOutputStream.writeObject(new CompilerState(Compiler.this));
    if (typeRegistry != null) {
     typeRegistry.saveContents(objectOutputStream);
    }
    stopTracer(tracer, "serializeCompilerState");
    return null;
   });
}

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

/**
 * Converts the parse tree for a module back to JS code.
 */
public String toSource(final JSModule module) {
 return runInCompilerThread(
   () -> {
    List<CompilerInput> inputs = module.getInputs();
    int numInputs = inputs.size();
    if (numInputs == 0) {
     return "";
    }
    CodeBuilder cb = new CodeBuilder();
    for (int i = 0; i < numInputs; i++) {
     Node scriptNode = inputs.get(i).getAstRoot(Compiler.this);
     if (scriptNode == null) {
      throw new IllegalArgumentException("Bad module: " + module.getName());
     }
     toSource(cb, i, scriptNode);
    }
    return cb.toString();
   });
}

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

/**
 * Converts the parse tree for each input in a module back to JS code.
 */
public String[] toSourceArray(final JSModule module) {
 return runInCompilerThread(
   () -> {
    List<CompilerInput> inputs = module.getInputs();
    int numInputs = inputs.size();
    if (numInputs == 0) {
     return new String[0];
    }
    String[] sources = new String[numInputs];
    CodeBuilder cb = new CodeBuilder();
    for (int i = 0; i < numInputs; i++) {
     Node scriptNode = inputs.get(i).getAstRoot(Compiler.this);
     if (scriptNode == null) {
      throw new IllegalArgumentException("Bad module input: " + inputs.get(i).getName());
     }
     cb.reset();
     toSource(cb, i, scriptNode);
     sources[i] = cb.toString();
    }
    return sources;
   });
}

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

runInCompilerThread(
  () -> {
   if (options.shouldOptimize()) {

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

ImmutableList.copyOf(inputs),
  options);
compiler.runInCompilerThread(
  () -> {
   compiler.parseInputs();

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

final int inputSeqNum,
          final Node root) {
runInCompilerThread(
  () -> {
   if (options.printInputDelimiter) {

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

/**
 * Converts the parse tree for each input back to JS code.
 */
public String[] toSourceArray() {
 return runInCompilerThread(
   () -> {
    Tracer tracer = newTracer("toSourceArray");
    try {
     int numInputs = moduleGraph.getInputCount();
     String[] sources = new String[numInputs];
     CodeBuilder cb = new CodeBuilder();
     int i = 0;
     for (CompilerInput input : moduleGraph.getAllInputs()) {
      Node scriptNode = input.getAstRoot(Compiler.this);
      cb.reset();
      toSource(cb, i, scriptNode);
      sources[i] = cb.toString();
      i++;
     }
     return sources;
    } finally {
     stopTracer(tracer, "toSourceArray");
    }
   });
}

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

return runInCompilerThread(
  () -> {
   Tracer tracer = newTracer("toSource");

相关文章

Compiler类方法