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

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

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

Compiler.<init>介绍

[英]Creates a Compiler that reports errors and warnings to its logger.
[中]创建向记录器报告错误和警告的编译器。

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected Compiler getCompiler() {
  return new Compiler();
}

代码示例来源:origin: jooby-project/jooby

@Override
public String process(final String filename, final String source, final Config conf,
  final ClassLoader loader) throws Exception {
 final CompilerOptions copts = new CompilerOptions();
 copts.setCodingConvention(new ClosureCodingConvention());
 copts.setOutputCharset(StandardCharsets.UTF_8);
 copts.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING);
 CompilationLevel level = level(get("level"));
 level.setOptionsForCompilationLevel(copts);
 Compiler.setLoggingLevel(Level.SEVERE);
 Compiler compiler = new Compiler();
 compiler.disableThreads();
 compiler.initOptions(copts);
 List<SourceFile> externs = externs(copts);
 Result result = compiler.compile(externs,
   ImmutableList.of(SourceFile.fromCode(filename, source)), copts);
 if (result.success) {
  return compiler.toSource();
 }
 List<AssetProblem> errors = Arrays.stream(result.errors)
   .map(error -> new AssetProblem(error.sourceName, error.lineNumber, error.getCharno(),
     error.description, null))
   .collect(Collectors.toList());
 throw new AssetException(name(), errors);
}

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

protected Compiler compiler() {
 return new Compiler();
}

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

protected Compiler compiler() {
 return new Compiler();
}

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

@Override
protected Compiler createCompiler() {
 return new Compiler(getErrorPrintStream());
}

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

@Override
protected Compiler createCompiler() {
 return new Compiler(getErrorPrintStream());
}

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

static void lint(String filename) throws IOException {
 lint(Paths.get(filename), new Compiler(System.out));
}

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

private Compiler createCompiler(
  List<SourceFile> inputs, List<SourceFile> externs, CompilerOptions compilerOptions) {
 Compiler compiler = new Compiler();
 compiler.disableThreads();
 compiler.compile(externs, inputs, compilerOptions);
 return compiler;
}

代码示例来源:origin: org.pustefixframework/pustefix-core

@Override
public void compress(Reader reader, Writer writer) throws CompressorException {
  com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
  compiler.disableThreads();
  CompilerOptions options = new CompilerOptions();
  CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
  try {
    SourceFile inputFile = SourceFile.fromReader("input.js", reader);
    List<SourceFile> inputFiles = new ArrayList<>();
    inputFiles.add(inputFile);
    List<SourceFile> externFiles = new ArrayList<>();
    compiler.compile(externFiles, inputFiles, options);
    writer.write(compiler.toSource());
  } catch(IOException x) {
    throw new CompressorException("Error while compressing javascript", x);
  }
}

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

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;
}

代码示例来源:origin: alexo/wro4j

private Compiler newCompiler(final CompilerOptions compilerOptions) {
 Compiler.setLoggingLevel(Level.SEVERE);
 final Compiler compiler = new Compiler();
 compilationLevel.setOptionsForCompilationLevel(compilerOptions);
 // make it play nice with GAE
 compiler.disableThreads();
 compiler.initOptions(compilerOptions);
 return compiler;
}

代码示例来源:origin: ro.isdc.wro4j/wro4j-extensions

private Compiler newCompiler(final CompilerOptions compilerOptions) {
 Compiler.setLoggingLevel(Level.SEVERE);
 final Compiler compiler = new Compiler();
 compilationLevel.setOptionsForCompilationLevel(compilerOptions);
 // make it play nice with GAE
 compiler.disableThreads();
 compiler.initOptions(compilerOptions);
 return compiler;
}

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

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;
}

代码示例来源:origin: angular/clutz

TypeScriptGenerator(Options opts) {
 this.opts = opts;
 this.compiler = new Compiler();
 compiler.disableThreads();
 setErrorStream(System.err);
 this.pathUtil = new PathUtil(opts.root, opts.absolutePathPrefix);
 this.nameUtil = new NameUtil(compiler);
}

代码示例来源:origin: org.hibnet/webpipes-googleclosure

private Compiler newCompiler(CompilerOptions compilerOptions, CompilationLevel compilationLevel) {
  Compiler.setLoggingLevel(Level.SEVERE);
  Compiler compiler = new Compiler();
  compilationLevel.setOptionsForCompilationLevel(compilerOptions);
  // make it play nice with GAE
  compiler.disableThreads();
  compiler.initOptions(compilerOptions);
  return compiler;
}

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

/** @return Whether any fixes were applied. */
 private static boolean fix(String filename, ImmutableSet<DiagnosticType> unfixableErrors)
   throws IOException {
  Compiler compiler = new Compiler(System.out);
  FixingErrorManager errorManager = new FixingErrorManager(unfixableErrors);
  compiler.setErrorManager(errorManager);
  errorManager.setCompiler(compiler);

  lint(Paths.get(filename), compiler);

  Collection<SuggestedFix> fixes = errorManager.getSureFixes();
  if (!fixes.isEmpty()) {
   ApplySuggestedFixes.applySuggestedFixesToFiles(fixes);
   return true;
  }
  return false;
 }
}

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

/** Generates the runtime by requesting the "es6_runtime" library from the compiler. */
 private static String getEs6Runtime() {
  CompilerOptions options = getOptions();
  options.setLanguageOut(LanguageMode.ECMASCRIPT3); // change .delete to ['delete']
  options.setForceLibraryInjection(ImmutableList.of("es6_runtime"));
  Compiler compiler = new Compiler();
  // Threads can't be used in small unit tests.
  compiler.disableThreads();
  SourceFile externs = SourceFile.fromCode("externs", "function Symbol() {}");
  SourceFile sourceFile = SourceFile.fromCode("source", "");
  compiler.compile(ImmutableList.of(externs), ImmutableList.of(sourceFile), options);
  return compiler.toSource();
 }
}

代码示例来源:origin: bessemHmidi/AngularBeans

public String compile(String code) {
    Compiler compiler = new Compiler();
    compiler.disableThreads();
    
    SourceFile extern = SourceFile.fromCode("externs.js","function alert(x) {}");
    SourceFile input = SourceFile.fromCode("input.js", code);
    
    compiler.compile(extern, input, options);
    return compiler.toSource();
  }
}

代码示例来源:origin: com.atlassian.maven.plugins/maven-amps-plugin

public static String compile(String code) {
  Compiler compiler = new Compiler();
  CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
  JSSourceFile extern = JSSourceFile.fromCode("externs.js","function alert(x) {}");
  // The dummy input name "input.js" is used here so that any warnings or
  // errors will cite line numbers in terms of input.js.
  JSSourceFile input = JSSourceFile.fromCode("input.js", code);
  // compile() returns a Result, but it is not needed here.
  compiler.compile(extern, input, options);
  // The compiler is responsible for generating the compiled code; it is not
  // accessible via the Result.
  return compiler.toSource();
}

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

protected CompileResult doCompileContent(JsContent content, CompilerOptions options,
  List<SourceFile> externs) throws CompilerException {
 Compiler compiler = new Compiler(getErrorManager()); // We shouldn't reuse compilers
 // disable JS Closure Compiler internal thread
 compiler.disableThreads();
 SourceFile source = SourceFile.fromCode(content.getSource(), content.get());
 Result result = compiler.compile(externs, Lists.newArrayList(source), options);
 if (result.errors.length > 0) {
  throw new CompilerException(result.errors);
 }
 return new CompileResult(compiler, result);
}

相关文章

Compiler类方法