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


Java SourceFile.fromCode方法代码示例

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


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

示例1: compile

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
private String compile(HtmlLibrary library, ClosureOptimizationLevel opt, InputStream js) throws IOException {
	CompilationLevel compilationLevel = opt.toCompilationLevel();
	if (null == compilationLevel) {
		// return original input
		return IOUtils.toString(js);
	}
	SourceFile input = SourceFile.fromInputStream(getLibraryName(library), js);
	// TODO externs not supported, should avoid ADVANCED compilation
	SourceFile extern = SourceFile.fromCode("TODO", StringUtils.EMPTY);
	CompilerOptions options = new CompilerOptions();
	compilationLevel.setOptionsForCompilationLevel(options);
	// ES5 assumption to allow getters/setters
	options.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT5);
	Compiler compiler = new Compiler();
	compiler.compile(extern, input, options);
	return compiler.toSource();
}
 
开发者ID:steeleforge,项目名称:aemin,代码行数:18,代码来源:HtmlLibraryManagerDelegateImpl.java

示例2: buildSourceMaps

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
private static ImmutableMap<String, SourceMapInput> buildSourceMaps(
    File[] src, String unknownPrefix) {
  ImmutableMap.Builder<String, SourceMapInput> inputSourceMaps = new ImmutableMap.Builder<>();
  if (src != null) {
    for (int i = 0; i < src.length; ++i) {
      File file = src[i];
      if (isNullOrEmpty(file.sourceMap)) {
        continue;
      }
      String path = file.path;
      if (path == null) {
        path = unknownPrefix + i;
      }
      path += ".map";
      SourceFile sf = SourceFile.fromCode(path, file.sourceMap);
      inputSourceMaps.put(path, new SourceMapInput(sf));
    }
  }
  return inputSourceMaps.build();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:21,代码来源:GwtRunner.java

示例3: testJsDocInfoPosition

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
public void testJsDocInfoPosition() throws IOException {
  SourceFile sourceFile = SourceFile.fromCode("comment-position-test.js",
      "   \n" +
      "  /**\n" +
      "   * A comment\n" +
      "   */\n" +
      "  function f(x) {}");
  Node script = parseFull(sourceFile.getCode());
  checkState(script.isScript());
  Node fn = script.getFirstChild();
  checkState(fn.isFunction());
  JSDocInfo jsdoc = fn.getJSDocInfo();

  assertThat(jsdoc.getOriginalCommentPosition()).isEqualTo(6);
  assertThat(sourceFile.getLineOfOffset(jsdoc.getOriginalCommentPosition())).isEqualTo(2);
  assertThat(sourceFile.getColumnOfOffset(jsdoc.getOriginalCommentPosition())).isEqualTo(2);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:18,代码来源:JsDocInfoParserTest.java

示例4: testDuplicateProvidesErrorThrownIfBadClosurePathSpecified

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
/**
 * Ensures that an error is thrown when the closure_path flag is set incorrectly.
 */
public void testDuplicateProvidesErrorThrownIfBadClosurePathSpecified() throws Exception {
  // Create a stub Closure Library.
  SourceFile fauxClosureDeps =
      SourceFile.fromCode("dep1.js", "goog.addDependency('foo/a.js', ['a'], []);\n");
  SourceFile fauxClosureSrc =
      SourceFile.fromCode("path/to/closure/foo/a.js", "goog.provide('a');\n");
  // Create a source file that depends on the stub Closure Library.
  SourceFile userSrc =
      SourceFile.fromCode("my/package/script.js", "goog.require('a');\n"
          + "goog.provide('my.package.script');\n");

  // doErrorMessagesRun uses closure_path //javascript/closure and therefore
  // fails to recognize and de-dupe the stub Closure Library at
  // //path/to/closure.
  doErrorMessagesRun(ImmutableList.of(fauxClosureDeps),
      ImmutableList.of(fauxClosureSrc, userSrc), true /* fatal */,
      "Namespace \"a\" is already provided in other file dep1.js");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:DepsGeneratorTest.java

示例5: compile

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
/**
	 * @param code
	 *            JavaScript source code to compile.
	 * @return The compiled version of the code.
	 */
	public static String compile(String code) {
		
//		System.out.println("------------------------");
//		System.out.println(code);
//		System.out.println("------------------------");
		
		Compiler compiler = new Compiler();

		CompilerOptions options = new CompilerOptions();
		// Advanced mode is used here, but additional options could be set, too.
		CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

		// To get the complete set of externs, the logic in
		// CompilerRunner.getDefaultExterns() should be used here.
		SourceFile extern = SourceFile.fromCode("externs.js", "");

		// The dummy input name "input.js" is used here so that any warnings or
		// errors will cite line numbers in terms of input.js.
		SourceFile input = SourceFile.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();
	}
 
开发者ID:rfxlab,项目名称:analytics-with-rfx,代码行数:34,代码来源:JsOptimizerUtil.java

示例6: compile

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
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();
}
 
开发者ID:bessemHmidi,项目名称:AngularBeans,代码行数:11,代码来源:ClosureCompiler.java

示例7: JSSource

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
public JSSource(String n, String code, boolean w) {
  name = n;
  relativePath = name;
  this.wrap = wrap;
  if (wrap) {
    // Read the contents, wrap in a function, and create from code.
    JSTransform namer = new JSTransform();
    wrapper = namer.newVariableName("f");
    code = "function " + wrapper + "() {\n" + code + "\n}";
  }
  sourceFile = SourceFile.fromCode(getPath(), code);
}
 
开发者ID:blackoutjack,项目名称:jamweaver,代码行数:13,代码来源:JSSource.java

示例8: doCompile

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
private void doCompile() {
  SourceFile externFile = SourceFile.fromCode("externs", externs.getValue());
  SourceFile srcFile = SourceFile.fromCode("input0", input0.getValue());
  Compiler compiler = new Compiler();
  try {
    Result result = compiler.compile(externFile, srcFile, options);
    updateUi(compiler, result);
  } catch (Exception e) {
    updateUiException(e);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:12,代码来源:DebuggerGwtMain.java

示例9: parse

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
/** Internal implementation to produce the {@link FileInfo} object. */
private static FileInfo parse(String code, String filename, @Nullable Reporter reporter) {
  ErrorReporter errorReporter = new DelegatingReporter(reporter);
  Compiler compiler = new Compiler();
  compiler.init(
      ImmutableList.<SourceFile>of(), ImmutableList.<SourceFile>of(), new CompilerOptions());

  Config config =
      ParserRunner.createConfig(
          // TODO(sdh): ES8 STRICT, with a non-strict fallback - then give warnings.
          Config.LanguageMode.ECMASCRIPT8,
          Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE,
          Config.RunMode.KEEP_GOING,
          /* extraAnnotationNames */ ImmutableSet.<String>of(),
          /* parseInlineSourceMaps */ true,
          Config.StrictMode.SLOPPY);

  SourceFile source = SourceFile.fromCode(filename, code);
  FileInfo info = new FileInfo(errorReporter);
  ParserRunner.ParseResult parsed = ParserRunner.parse(source, code, config, errorReporter);
  parsed.ast.setInputId(new InputId(filename));
  String version = parsed.features.version();
  if (!version.equals("es3")) {
    info.loadFlags.add(JsArray.of("lang", version));
  }

  for (Comment comment : parsed.comments) {
    if (comment.type == Comment.Type.JSDOC) {
      parseComment(comment, info);
    }
  }
  NodeTraversal.traverseEs6(compiler, parsed.ast, new Traverser(info));
  return info;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:35,代码来源:JsfileParser.java

示例10: testMergeStrategyHelper

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
private String testMergeStrategyHelper(DepsGenerator.InclusionStrategy mergeStrategy)
    throws Exception {
  SourceFile dep1 =
      SourceFile.fromCode(
          "dep1.js",
          LINE_JOINER.join(
              "goog.addDependency('../../a.js', ['a'], []);",
              "goog.addDependency('../../src1.js', ['b'], []);",
              "goog.addDependency('../../d.js', ['d'], []);\n"));
  SourceFile src1 = SourceFile.fromCode("/base/" + "/src1.js", "goog.provide('b');\n");
  SourceFile src2 =
      SourceFile.fromCode(
          "/base/" + "/src2.js", LINE_JOINER.join("goog.provide('c');", "goog.require('d');"));
  DepsGenerator depsGenerator =
      new DepsGenerator(
          ImmutableList.of(dep1),
          ImmutableList.of(src1, src2),
          mergeStrategy,
          PathUtil.makeAbsolute("/base/javascript/closure"),
          errorManager,
          new ModuleLoader(
              null,
              ImmutableList.of("/base/"),
              ImmutableList.<DependencyInfo>of(),
              ModuleLoader.PathResolver.ABSOLUTE,
              ModuleLoader.ResolutionMode.BROWSER));

  String output = depsGenerator.computeDependencyCalls();

  assertWithMessage("There should be output files").that(output).isNotEmpty();
  assertNoWarnings();

  return output;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:35,代码来源:DepsGeneratorTest.java

示例11: testDuplicateProvides

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
public void testDuplicateProvides() throws Exception {
  SourceFile dep1 = SourceFile.fromCode("dep1.js",
      "goog.addDependency('a.js', ['a'], []);\n");
  SourceFile src1 = SourceFile.fromCode("src1.js",
      "goog.provide('a');\n");

  doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.of(src1), true /* fatal */,
      "Namespace \"a\" is already provided in other file dep1.js");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:DepsGeneratorTest.java

示例12: testDuplicateProvidesIgnoredIfInClosureDirectory

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
/** Ensures that DepsGenerator deduplicates dependencies from custom Closure Library branches. */
public void testDuplicateProvidesIgnoredIfInClosureDirectory() throws Exception {
  // Create a stub Closure Library.
  SourceFile fauxClosureDeps =
      SourceFile.fromCode("dep1.js", "goog.addDependency('foo/a.js', ['a'], []);\n");
  SourceFile fauxClosureSrc =
      SourceFile.fromCode("path/to/closure/foo/a.js", "goog.provide('a');\n");
  // Create a source file that depends on the stub Closure Library.
  SourceFile userSrc =
      SourceFile.fromCode("my/package/script.js", "goog.require('a');\n"
          + "goog.provide('my.package.script');\n");
  DepsGenerator worker =
      new DepsGenerator(
          ImmutableList.of(fauxClosureDeps),
          ImmutableList.of(fauxClosureSrc, userSrc),
          DepsGenerator.InclusionStrategy.ALWAYS,
          PathUtil.makeAbsolute("./path/to/closure"),
          errorManager,
          new ModuleLoader(
              null,
              ImmutableList.of("."),
              ImmutableList.<DependencyInfo>of(),
              ModuleLoader.PathResolver.ABSOLUTE,
              ModuleLoader.ResolutionMode.BROWSER));

  String output = worker.computeDependencyCalls();

  assertWithMessage("Output should have been created.").that(output).isNotEmpty();
  assertNoWarnings();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:31,代码来源:DepsGeneratorTest.java

示例13: testDuplicateProvidesSameFile

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
public void testDuplicateProvidesSameFile() throws Exception {
  SourceFile dep1 = SourceFile.fromCode("dep1.js",
      "goog.addDependency('a.js', ['a'], []);\n");
  SourceFile src1 =
      SourceFile.fromCode(
          "src1.js", LINE_JOINER.join("goog.provide('b');", "goog.provide('b');\n"));

  doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.of(src1), false /* fatal */,
      "Multiple calls to goog.provide(\"b\")");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:11,代码来源:DepsGeneratorTest.java

示例14: testDuplicateRequire

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
public void testDuplicateRequire() throws Exception {
  SourceFile dep1 = SourceFile.fromCode("dep1.js",
      "goog.addDependency('a.js', ['a'], []);\n");
  SourceFile src1 =
      SourceFile.fromCode(
          "src1.js", LINE_JOINER.join("goog.require('a');", "goog.require('a');", ""));

  doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.of(src1), false /* fatal */,
      "Namespace \"a\" is required multiple times");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:11,代码来源:DepsGeneratorTest.java

示例15: testSameFileProvideRequire

import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
public void testSameFileProvideRequire() throws Exception {
  SourceFile dep1 = SourceFile.fromCode("dep1.js",
      "goog.addDependency('a.js', ['a'], []);\n");
  SourceFile src1 =
      SourceFile.fromCode(
          "src1.js", LINE_JOINER.join("goog.provide('b');", "goog.require('b');", ""));

  doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.of(src1), false /* fatal */,
      "Namespace \"b\" is both required and provided in the same file.");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:11,代码来源:DepsGeneratorTest.java


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