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


Java CompilerOptions类代码示例

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


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

示例1: compressJs

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
private void compressJs(String sourceName, InputStream in, OutputStream out) throws IOException
{
    CompilerOptions options = new CompilerOptions();
    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

    SourceFile input = SourceFile.fromInputStream(sourceName, in, Charset.forName("UTF-8"));

    com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
    compiler.compile(Collections.EMPTY_LIST, Collections.singletonList(input), options);

    if (compiler.hasErrors())
    {
        throw new EvaluatorException(compiler.getErrors()[0].description);
    }

    String compressed = compiler.toSource();
    IOUtils.copy(new StringReader(compressed), out);
}
 
开发者ID:touwolf,项目名称:kasije,代码行数:19,代码来源:ResourcesManagerImpl.java

示例2: execute

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public void execute() {
  if (this.outputFile == null) {
    throw new BuildException("outputFile attribute must be set");
  }

  Compiler.setLoggingLevel(Level.OFF);

  CompilerOptions options = createCompilerOptions();
  Compiler compiler = createCompiler(options);

  JSSourceFile[] externs = findExternFiles();
  JSSourceFile[] sources = findSourceFiles();

  log("Compiling " + sources.length + " file(s) with " +
      externs.length + " extern(s)");

  Result result = compiler.compile(externs, sources, options);
  if (result.success) {
    writeResult(compiler.toSource());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:CompileTask.java

示例3: minify

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public byte[] minify(byte[] jsFileContent, String path) {
    List<SourceFile> externs = Collections.emptyList();
    List<SourceFile> inputs = Arrays.asList(SourceFile.fromCode(path, new String(jsFileContent, StandardCharsets.UTF_8)));

    CompilerOptions options = new CompilerOptions();
    options.setAngularPass(true);
    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);


    com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
    Result result = compiler.compile(externs, inputs, options);

    if (result.success) {
        return compiler.toSource().getBytes(StandardCharsets.UTF_8);
    }

    JSError[] errors = result.errors;
    StringBuilder errorText = new StringBuilder();
    for (JSError error: errors){
        errorText.append(error.toString());
    }
    throw new IllegalArgumentException("Unable to minify, input source\n"+ errorText);
}
 
开发者ID:factoryfx,项目名称:factoryfx,代码行数:24,代码来源:JavaScriptFile.java

示例4: compileFiles

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private OOPSourceCodeModel compileFiles(List<RawFile> files, List<String> projectFileTypes) {
    OOPSourceCodeModel model = new OOPSourceCodeModel();
    for (RawFile file : files) {
        try {
            Compiler compiler = new Compiler();
            CompilerOptions options = new CompilerOptions();
            options.setIdeMode(true);
            options.setParseJsDocDocumentation(JsDocParsing.INCLUDE_DESCRIPTIONS_WITH_WHITESPACE);
            compiler.initOptions(options);
            Node root = new JsAst(SourceFile.fromCode(file.name(), file.content())).getAstRoot(compiler);
            JavaScriptListener jsListener = new JavaScriptListener(model, file, projectFileTypes);
            NodeTraversal.traverseEs6(compiler, root, jsListener);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return model;
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:20,代码来源:ClarpseJSCompiler.java

示例5: create

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
/**
 * Creates a symbolic executor which will instrument the given file and then,
 * when run, symbolically execute starting by calling entryFunction with the
 * given inputs.
 *
 * @param filename a JavaScript file which will be instrumented and then
 *        symbolically executed
 * @param loader a FileLoader to help load files
 * @param newInputGenerator the object that will generate new inputs from old
 *        ones
 * @param maxNumInputs symbolic execution will stop after this many inputs are
 *        generated. This isn't a strict maximum, though, because new inputs
 *        are generated in batches, and we stop after the first <em>batch</em>
 *        puts us at or past this limit.
 * @param entryFunction the function at which symbolic execution will start
 * @param inputs the initial inputs to use when calling entryFunction
 */
public static SymbolicExecutor create(String filename, FileLoader loader,
    NewInputGenerator newInputGenerator, int maxNumInputs,
    String entryFunction, String... inputs) {
  CompilerOptions options = new CompilerOptions();
  // Enable instrumentation
  options.symbolicExecutionInstrumentation = true;
  options.prettyPrint=true;
  // Compile the program; this is where the instrumentation happens.
  Compiler compiler = new Compiler();
  compiler.compile(new ArrayList<JSSourceFile>(),
      Lists.newArrayList(JSSourceFile.fromFile(loader.getPath(filename))),
      options);
  // Add the call to symbolicExecution.execute
  String code = String.format("%s;symbolicExecution.execute(this,%s,inputs)",
    compiler.toSource(), entryFunction);
  return create(code, loader, newInputGenerator, inputs, maxNumInputs);
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:35,代码来源:SymbolicExecutor.java

示例6: execute

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public void execute() {
  if (this.outputFile == null) {
    throw new BuildException("outputFile attribute must be set");
  }

  Compiler.setLoggingLevel(Level.OFF);

  CompilerOptions options = createCompilerOptions();
  Compiler compiler = createCompiler(options);

  JSSourceFile[] externs = findExternFiles();
  JSSourceFile[] sources = findSourceFiles();

  log("Compiling " + sources.length + " file(s) with " +
      externs.length + " extern(s)");

  Result result = compiler.compile(externs, sources, options);
  if (result.success) {
    writeResult(compiler.toSource());
  } else {
    throw new BuildException("Compilation failed.");
  }
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:24,代码来源:CompileTask.java

示例7: getCompilerOptions

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public CompilerOptions getCompilerOptions() {
  final CompilerOptions options = new CompilerOptions();
  options.setClosurePass(true);

  options.setCheckGlobalNamesLevel(CheckLevel.ERROR);
  // Report duplicate definitions, e.g. for accidentally duplicated externs.
  options.setWarningLevel(DiagnosticGroups.DUPLICATE_VARS, CheckLevel.ERROR);

  options.setLanguage(CompilerOptions.LanguageMode.ECMASCRIPT_2015);
  options.setLanguageOut(CompilerOptions.LanguageMode.NO_TRANSPILE);

  // Do not transpile module declarations
  options.setWrapGoogModulesForWhitespaceOnly(false);
  // Stop escaping the characters "=&<>"
  options.setTrustedStrings(true);
  options.setPreferSingleQuotes(true);

  // Compiler passes must be disabled to disable down-transpilation to ES5.
  options.skipAllCompilerPasses();
  // turns off optimizations.
  options.setChecksOnly(true);
  options.setPreserveDetailedSourceInfo(true);
  options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);

  return options;
}
 
开发者ID:angular,项目名称:clutz,代码行数:27,代码来源:Options.java

示例8: initCompilerOptions

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
protected CompilerOptions initCompilerOptions() {
    CompilerOptions opts = new CompilerOptions();
    opts.setSummaryDetailLevel(1);
    opts.prettyPrint = true;

    // MIT-LL's integrated demo script requires this setting since
    // it uses trailing commas in object literals.
    opts.setLanguageIn(LanguageMode.ECMASCRIPT5);
    opts.setGenerateExports(false);
    opts.setPreferLineBreakAtEndOfFile(false);
    opts.setTrustedStrings(true);

    /*
    DependencyOptions dopts = new DependencyOptions();
    dopts.setDependencyPruning(true);
    dopts.setMoocherDropping(true);
    opts.setDependencyOptions(dopts);
    */

    return opts;
}
 
开发者ID:blackoutjack,项目名称:jamweaver,代码行数:22,代码来源:JSSourceManager.java

示例9: map

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
@Override
public Resource<String> map(Resource<String> resource) {
    try {
        CompilerOptions options = new CompilerOptions();
        config.getCompilationLevel().setOptionsForCompilationLevel(options);
        options.setOutputCharset("UTF-8");
        options.setLanguageIn(config.getLanguage());

        SourceFile input = SourceFile.fromInputStream("dummy.js",
                new ByteArrayInputStream(resource.getContent().getBytes(Charsets.UTF_8)));
        List<SourceFile> externs = config.getExterns();

        Compiler compiler = new Compiler();
        compiler.compile(externs, Lists.newArrayList(input), options);

        if (compiler.hasErrors()) {
            throw new EvaluatorException(compiler.getErrors()[0].description);
        }

        return new Resource<String>(resource.getMimeType(), compiler.toSource(), StringHasher.instance);
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
 
开发者ID:rjnichols,项目名称:visural-web-resources,代码行数:25,代码来源:ClosureMinifyJavascript.java

示例10: initCompilationResources

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
private CompilerOptions initCompilationResources() {
  CompilerOptions options = new CompilerOptions();
  CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel( options );

  options.setSourceMapOutputPath( "." );

  WarningLevel.QUIET.setOptionsForWarningLevel( options );
  options.setWarningLevel( DiagnosticGroups.LINT_CHECKS, CheckLevel.OFF );

  options.setLanguageIn( CompilerOptions.LanguageMode.ECMASCRIPT5 );

  // make sure these are clear
  this.lastPrefix = null;
  this.lastLocationMapping = null;

  return options;
}
 
开发者ID:pentaho,项目名称:pentaho-osgi-bundles,代码行数:18,代码来源:WebjarsURLConnection.java

示例11: CompileTask

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public CompileTask() {
  this.languageIn = CompilerOptions.LanguageMode.ECMASCRIPT3;
  this.warningLevel = WarningLevel.DEFAULT;
  this.debugOptions = false;
  this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
  this.customExternsOnly = false;
  this.manageDependencies = false;
  this.prettyPrint = false;
  this.printInputDelimiter = false;
  this.generateExports = false;
  this.replaceProperties = false;
  this.forceRecompile = false;
  this.replacePropertiesPrefix = "closure.define.";
  this.defineParams = Lists.newLinkedList();
  this.externFileLists = Lists.newLinkedList();
  this.sourceFileLists = Lists.newLinkedList();
  this.sourcePaths = Lists.newLinkedList();
  this.warnings = Lists.newLinkedList();
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:CompileTask.java

示例12: convertPropertiesMap

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
/**
 * Converts project properties beginning with the replacement prefix
 * into Compiler {@code @define} replacements.
 *
 * @param options
 */
private void convertPropertiesMap(CompilerOptions options) {
  @SuppressWarnings("unchecked")
  Map<String, Object> props = getProject().getProperties();
  for (Map.Entry<String, Object> entry : props.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();

    if (key.startsWith(replacePropertiesPrefix)) {
      key = key.substring(replacePropertiesPrefix.length());

      if (!setDefine(options, key, value)) {
        log("Unexpected property value for key=" + key + "; value=" + value);
      }
    }
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:CompileTask.java

示例13: getSecureCompilerOptions

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
/**
 * Returns compiler options which are safe for compilation of a cajoled
 * module. The set of options is similar to the one which is used by
 * CompilationLevel in simple mode. The main difference is that variable
 * renaming and closurePass options are turned off.
 */
private CompilerOptions getSecureCompilerOptions() {
  CompilerOptions options = new CompilerOptions();

  options.variableRenaming = VariableRenamingPolicy.OFF;
  options.setInlineVariables(Reach.LOCAL_ONLY);
  options.inlineLocalFunctions = true;
  options.checkGlobalThisLevel = CheckLevel.OFF;
  options.coalesceVariableNames = true;
  options.deadAssignmentElimination = true;
  options.collapseVariableDeclarations = true;
  options.convertToDottedProperties = true;
  options.labelRenaming = true;
  options.removeDeadCode = true;
  options.optimizeArgumentsArray = true;
  options.removeUnusedVars = false;
  options.removeUnusedLocalVars = true;

  return options;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:SecureCompiler.java

示例14: setOptions

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
protected void setOptions(CompilerOptions options) {
  options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT);
  // TODO(sdh): It would be nice to allow people to output code in
  // strict mode.  But currently we swallow all the input language
  // strictness checks, and there are various tests that are never
  // compiled and so are broken when we output 'use strict'.  We
  // could consider adding some sort of logging/warning/error in
  // cases where the input was not strict, though there could still
  // be semantic differences even if syntax is strict.  Possibly
  // the first step would be to allow the option of outputting strict
  // and then change the default and see what breaks.  b/33005948
  options.setLanguageOut(LanguageMode.ECMASCRIPT5);
  options.setQuoteKeywordProperties(true);
  options.setSkipNonTranspilationPasses(true);
  options.setVariableRenaming(VariableRenamingPolicy.OFF);
  options.setPropertyRenaming(PropertyRenamingPolicy.OFF);
  options.setWrapGoogModulesForWhitespaceOnly(false);
  options.setPrettyPrint(true);
  options.setSourceMapOutputPath("/dev/null");
  options.setSourceMapIncludeSourcesContent(true);
  options.setWarningLevel(ES5_WARNINGS, CheckLevel.OFF);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:BaseTranspiler.java

示例15: CompileTask

import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public CompileTask() {
  this.languageIn = CompilerOptions.LanguageMode.ECMASCRIPT_2015;
  this.languageOut = CompilerOptions.LanguageMode.ECMASCRIPT3;
  this.warningLevel = WarningLevel.DEFAULT;
  this.debugOptions = false;
  this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
  this.environment = CompilerOptions.Environment.BROWSER;
  this.manageDependencies = false;
  this.prettyPrint = false;
  this.printInputDelimiter = false;
  this.preferSingleQuotes = false;
  this.generateExports = false;
  this.replaceProperties = false;
  this.forceRecompile = false;
  this.angularPass = false;
  this.replacePropertiesPrefix = "closure.define.";
  this.defineParams = new ArrayList<>();
  this.entryPointParams = new ArrayList<>();
  this.externFileLists = new ArrayList<>();
  this.sourceFileLists = new ArrayList<>();
  this.sourcePaths = new ArrayList<>();
  this.warnings = new ArrayList<>();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:24,代码来源:CompileTask.java


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