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


Java JSSourceFile类代码示例

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


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

示例1: execute

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的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

示例2: getDefaultExterns

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/**
 * Gets the default externs set.
 *
 * Adapted from {@link CommandLineRunner}.
 */
private List<JSSourceFile> getDefaultExterns() {
  try {
    InputStream input = Compiler.class.getResourceAsStream(
        "/externs.zip");
    ZipInputStream zip = new ZipInputStream(input);
    List<JSSourceFile> externs = Lists.newLinkedList();

    for (ZipEntry entry; (entry = zip.getNextEntry()) != null; ) {
      LimitInputStream entryStream =
          new LimitInputStream(zip, entry.getSize());
      externs.add(
          JSSourceFile.fromInputStream(entry.getName(), entryStream));
    }

    return externs;
  } catch (IOException e) {
    throw new BuildException(e);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:CompileTask.java

示例3: create

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的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

示例4: execute

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的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

示例5: findExternFiles

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
private JSSourceFile[] findExternFiles() {
  List<JSSourceFile> files = Lists.newLinkedList();
  if (!this.customExternsOnly) {
    files.addAll(getDefaultExterns());
  }

  for (FileList list : this.externFileLists) {
    files.addAll(findJavaScriptFiles(list));
  }

  return files.toArray(new JSSourceFile[files.size()]);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:CompileTask.java

示例6: findSourceFiles

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
private JSSourceFile[] findSourceFiles() {
  List<JSSourceFile> files = Lists.newLinkedList();

  for (FileList list : this.sourceFileLists) {
    files.addAll(findJavaScriptFiles(list));
  }

  return files.toArray(new JSSourceFile[files.size()]);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:CompileTask.java

示例7: findJavaScriptFiles

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/**
 * Translates an Ant file list into the file format that the compiler
 * expects.
 */
private List<JSSourceFile> findJavaScriptFiles(FileList fileList) {
  List<JSSourceFile> files = Lists.newLinkedList();
  File baseDir = fileList.getDir(getProject());

  for (String included : fileList.getFiles(getProject())) {
    files.add(JSSourceFile.fromFile(new File(baseDir, included)));
  }

  return files;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:CompileTask.java

示例8: getDefaultExterns

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
private List<JSSourceFile> getDefaultExterns() throws IOException {
	InputStream input = ClosureJavaScriptCompressor.class.getResourceAsStream("/externs.zip");
	ZipInputStream zip = new ZipInputStream(input);
	List<JSSourceFile> externs = Lists.newLinkedList();
	for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null;) {
		LimitInputStream entryStream = new LimitInputStream(zip, entry.getSize());
		externs.add(JSSourceFile.fromInputStream(entry.getName(), entryStream));
	}
	return externs;
}
 
开发者ID:ad3n,项目名称:htmlcompressor,代码行数:11,代码来源:ClosureJavaScriptCompressor.java

示例9: findJavaScriptFiles

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/**
 * Translates an Ant file list into the file format that the compiler
 * expects.
 */
private List<JSSourceFile> findJavaScriptFiles(FileList fileList) {
  List<JSSourceFile> files = Lists.newLinkedList();
  File baseDir = fileList.getDir(getProject());

  for (String included : fileList.getFiles(getProject())) {
    files.add(JSSourceFile.fromFile(new File(baseDir, included),
        Charset.forName(encoding)));
  }

  return files;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:16,代码来源:CompileTask.java

示例10: getDefaultExterns

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/**
 * Gets the default externs set.
 *
 * Adapted from {@link CommandLineRunner}.
 */
private List<JSSourceFile> getDefaultExterns() {
  try {
    return CommandLineRunner.getDefaultExterns();
  } catch (IOException e) {
    throw new BuildException(e);
  }
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:13,代码来源:CompileTask.java

示例11: closureCompile

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/**
 * Compiles the scripts from the given files into a single script using the
 * Google closure compiler. Any problems encountered are logged as warnings
 * or errors (depending on severity).
 * <p>
 * For better understanding what is going on in this method, please read
 * "Closure: The Definitve Guide" by M. Bolin. Especially chapters 12 and 14
 * explain how to use the compiler programmatically.
 */
private String closureCompile(CompilationLevel level,
		List<JavaScriptFile> inputFiles, List<JavaScriptFile> externFiles,
		ILogger logger) {

	CollectingErrorManager collectingErrorManager = new CollectingErrorManager(
			inputFiles, externFiles);
	Compiler compiler = new Compiler(collectingErrorManager);
	Compiler.setLoggingLevel(Level.OFF);

	List<JSSourceFile> defaultExterns = new ArrayList<JSSourceFile>();
	try {
		defaultExterns = CommandLineRunner.getDefaultExterns();
	} catch (IOException e) {
		logger.error(
				"Could not load closure's default externs! Probably this will prevent compilation.",
				e);
	}

	Result result = compiler.compile(
			createJSSourceFiles(externFiles, defaultExterns),
			createJSSourceFiles(inputFiles, new ArrayList<JSSourceFile>()),
			determineOptions(level));

	if (!collectingErrorManager.messages.isEmpty()) {
		logger.warn(new ListStructuredLogMessage(
				"JavaScript compilation produced "
						+ collectingErrorManager.messages.size()
						+ " errors and warnings",
				collectingErrorManager.messages, JavaScriptManager.LOG_TAG));
	}

	if (!result.success) {
		logger.error("Compilation of JavaScript code failed! Falling back to concatenated script.");
		return concatScripts(inputFiles);
	}

	return StringUtils.normalizeLineBreaks(compiler.toSource());
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:48,代码来源:ConQATJavaScriptCompiler.java

示例12: createJSSourceFiles

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/** Creates an array of {@link JSSourceFile}s from {@link JavaScriptFile}s. */
private JSSourceFile[] createJSSourceFiles(List<JavaScriptFile> files,
		List<JSSourceFile> baseList) {
	for (int i = 0; i < files.size(); ++i) {
		baseList.add(JSSourceFile.fromCode(files.get(i).getName(), files
				.get(i).getContent()));
	}
	return CollectionUtils.toArray(baseList, JSSourceFile.class);
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:10,代码来源:ConQATJavaScriptCompiler.java

示例13: processInput

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void processInput(ITextResource input) throws ConQATException {

	NodeUtils.addToDisplayList(input, KEY);

	uniformPathToElementMap = ResourceTraversalUtils
			.createUniformPathToElementMap(input, ITextElement.class);

	group = NodeUtils.getFindingReport(input)
			.getOrCreateCategory("Google Closure")
			.getOrCreateFindingGroup("Closure Findings");

	FindingErrorManager errorManager = new FindingErrorManager();
	Compiler compiler = new Compiler(errorManager);
	Compiler.setLoggingLevel(Level.OFF);
	compiler.compile(new JSSourceFile[0], CollectionUtils.toArray(
			determineInputFiles(input), JSSourceFile.class),
			determineOptions());

	if (errorManager.hadErrors()) {
		throw new ConQATException("Closure compile error: '"
				+ errorManager.error.description + "' at "
				+ errorManager.error.sourceName + ":"
				+ errorManager.error.lineNumber);
	}
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:28,代码来源:ClosureAnalyzer.java

示例14: determineInputFiles

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/** Determines the input files. */
private List<JSSourceFile> determineInputFiles(ITextResource input)
		throws ConQATException {
	List<JSSourceFile> inputFiles = new ArrayList<JSSourceFile>();
	for (ITextElement element : ResourceTraversalUtils
			.listTextElements(input)) {
		inputFiles.add(JSSourceFile.fromCode(element.getUniformPath(),
				element.getTextContent()));
	}
	return inputFiles;
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:12,代码来源:ClosureAnalyzer.java

示例15: parseJavaScriptFiles

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/**
 * Runs the Rhino parser on the given JavaScript snippets.
 * @return Rhino AST node (last child of the root)
 */
private Node parseJavaScriptFiles(List<String> sourceFiles) throws IOException {
	Compiler compiler = new Compiler();
	JSSourceFile[] fs = new JSSourceFile[sourceFiles.size()];
	for (int i = 0; i < fs.length; i++) {
		final File file;
		final String sourceFileName = sourceFiles.get(i);
		if ("-".equals(sourceFileName)) { // Read from stdin
			try {
				file = File.createTempFile("TAJS_<stdin>", ".js");
				try (FileOutputStream out = new FileOutputStream(file)) {
					byte[] buffer = new byte[1024];
					int len;
					while ((len = System.in.read(buffer)) != -1) {
						out.write(buffer, 0, len);
					}
				}
			} catch (Exception e) {
				throw new AnalysisException("Unable to parse stdin");
			}
		} else {
			file = new File(sourceFileName);
		}
		fs[i] = fromFile(file);
	}
	compiler.compile(fromEmptyCode(), fs, compilerOptions);
	if (compiler.getErrorCount() > 0)
		throw new AnalysisException("Parse error in file: " + sourceFiles);
	return getParentOfFirstInterestingNode(compiler);
}
 
开发者ID:cursem,项目名称:ScriptCompressor,代码行数:34,代码来源:RhinoASTToFlowgraph.java


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