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


Java CompilerOptions.setPreferSingleQuotes方法代码示例

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


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

示例1: 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

示例2: generateCode

import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
public String generateCode(AbstractCompiler compiler, Node node) {
  // TODO(mknichel): Fix all the formatting problems with this code.
  // How does this play with goog.scope?
  if (node.isNormalBlock()) {
    // Avoid printing the {}'s
    node.setToken(Token.SCRIPT);
  }
  CompilerOptions compilerOptions = new CompilerOptions();
  compilerOptions.setPreferSingleQuotes(true);
  compilerOptions.setUseOriginalNamesInOutput(true);
  // We're refactoring existing code, so no need to escape values inside strings.
  compilerOptions.setTrustedStrings(true);
  return new CodePrinter.Builder(node)
      .setCompilerOptions(compilerOptions)
      .setTypeRegistry(compiler.getTypeRegistry())
      .setPrettyPrint(true)
      .setLineBreak(true)
      .setOutputTypes(true)
      .build();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:21,代码来源:SuggestedFix.java

示例3: getOptions

import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
@Override
protected CompilerOptions getOptions() {
  CompilerOptions options = super.getOptions();
  options.setPrettyPrint(true);
  options.setPreserveTypeAnnotations(true);
  options.setPreferSingleQuotes(true);
  options.setEmitUseStrict(false);
  return options;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:CheckRequiresAndProvidesSortedTest.java

示例4: parse

import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的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: outputSource

import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
/**
 * Outputs the source equivalent of the abstract syntax tree, optionally generating a sourcemap.
 *
 * @param node The JavaScript abstract syntax tree.
 * @param outputFormat The source output format options.
 * @param inputFileName The source file name to associate with the input node, used for sourcemap
 *     generation.
 * @param inputSourceMap The content of the input sourcemap.
 * @param sourceMapOutputFileName The name of the output sourcemap.
 * @return The equivalent JavaScript source.
 */
private static String outputSource(
    Node node,
    ImmutableSet<OutputFormat> outputFormat,
    String inputFileName,
    String inputSourceMap,
    String sourceMapOutputFileName) {
  CompilerOptions options = new CompilerOptions();
  options.setPrettyPrint(outputFormat.contains(OutputFormat.PRETTY));
  options.setPreferSingleQuotes(outputFormat.contains(OutputFormat.SINGLE_QUOTE_STRINGS));
  // The Closure Compiler treats the 'use strict' directive as a property of a node. CodeBuilder
  // doesn't consider directives during its code generation. Instead, it inserts the 'use strict'
  // directive if it is in a strict language mode.
  Set<String> directives = node.getDirectives();
  if ((directives != null) && directives.contains("use strict")) {
    options.setLanguage(CompilerOptions.LanguageMode.ECMASCRIPT_2015);
    options.setEmitUseStrict(true);
  }
  options.skipAllCompilerPasses();

  if (inputSourceMap != null) {
    SourceFile sourceMapSourceFile = SourceFile.fromCode("input.sourcemap", inputSourceMap);
    ImmutableMap<String, SourceMapInput> inputSourceMaps =
        ImmutableMap.of(inputFileName, new SourceMapInput(sourceMapSourceFile));
    options.setInputSourceMaps(inputSourceMaps);
    options.setApplyInputSourceMaps(true);
    // Simply setting the path to any non-null value will trigger source map generation.
    // Since sourceMapOutputPath is handled by AbstractCommandLineRunner and not the Compiler
    // itself, we manually output the final sourcemap below.
    options.setSourceMapOutputPath("/dev/null");
  }

  Compiler compiler = new Compiler();
  compiler.disableThreads();
  compiler.initOptions(options);
  compiler.initBasedOnOptions();
  Compiler.CodeBuilder cb = new Compiler.CodeBuilder();
  compiler.toSource(cb, 0, node);

  if (inputFileName != null && inputSourceMap != null && sourceMapOutputFileName != null) {
    try {
      FileOutputStream fileOut = new FileOutputStream(sourceMapOutputFileName);
      OutputStreamWriter out = new OutputStreamWriter(fileOut, UTF_8);
      compiler.getSourceMap().appendTo(out, "renamed.js");
      out.close();
    } catch (Exception e) {
      System.err.println(e + "Error writing output sourcemap.");
    }
  }

  return cb.toString();
}
 
开发者ID:PolymerLabs,项目名称:PolymerRenamer,代码行数:63,代码来源:JsRenamer.java

示例6: createCompilerOptions

import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
private CompilerOptions createCompilerOptions() {
  CompilerOptions options = new CompilerOptions();

  this.compilationLevel.setOptionsForCompilationLevel(options);
  if (this.debugOptions) {
    this.compilationLevel.setDebugOptionsForCompilationLevel(options);
  }

  options.setEnvironment(this.environment);

  options.setPrettyPrint(this.prettyPrint);
  options.setPrintInputDelimiter(this.printInputDelimiter);
  options.setPreferSingleQuotes(this.preferSingleQuotes);
  options.setGenerateExports(this.generateExports);

  options.setLanguageIn(this.languageIn);
  options.setLanguageOut(this.languageOut);
  options.setOutputCharset(this.outputEncoding);

  this.warningLevel.setOptionsForWarningLevel(options);
  options.setManageClosureDependencies(manageDependencies);
  convertEntryPointParameters(options);
  options.setTrustedStrings(true);
  options.setAngularPass(angularPass);

  if (replaceProperties) {
    convertPropertiesMap(options);
  }

  convertDefineParameters(options);

  for (Warning warning : warnings) {
    CheckLevel level = warning.getLevel();
    String groupName = warning.getGroup();
    DiagnosticGroup group = new DiagnosticGroups().forName(groupName);
    if (group == null) {
      throw new BuildException(
          "Unrecognized 'warning' option value (" + groupName + ")");
    }
    options.setWarningLevel(group, level);
  }

  if (!Strings.isNullOrEmpty(sourceMapFormat)) {
    options.setSourceMapFormat(Format.valueOf(sourceMapFormat));
  }

  if (!Strings.isNullOrEmpty(sourceMapLocationMapping)) {
    String[] tokens = sourceMapLocationMapping.split("\\|", -1);
    LocationMapping lm = new LocationMapping(tokens[0], tokens[1]);
    options.setSourceMapLocationMappings(Arrays.asList(lm));
  }

  options.setApplyInputSourceMaps(applyInputSourceMaps);

  if (sourceMapOutputFile != null) {
    File parentFile = sourceMapOutputFile.getParentFile();
    if (parentFile.mkdirs()) {
      log("Created missing parent directory " + parentFile, Project.MSG_DEBUG);
    }
    options.setSourceMapOutputPath(parentFile.getAbsolutePath());
  }
  return options;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:64,代码来源:CompileTask.java


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