• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JSSourceFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: fromFile

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/**
 * Constructs a JSSourceFile from a JavaScript file.
 * @throws IOException if unable to read the file
 */
static JSSourceFile fromFile(File file) throws IOException {
	try (FileInputStream stream = new FileInputStream(file)) {
		try (FileChannel fc = stream.getChannel()) {
			MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
			final Charset charset = Charset.forName("UTF-8");
			return fromCode(charset.decode(bb).toString(), new EncodedFileName(file.getPath()));
		}
	}
}
 
开发者ID:cursem,项目名称:ScriptCompressor,代码行数:14,代码来源:RhinoASTToFlowgraph.java


示例17: compile

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
public static Result compile(String program, int num) {
  JSSourceFile input = JSSourceFile.fromCode(""+num, program);
  Compiler compiler = new Compiler();
  Result result = compiler.compile(extern, input, options);
  return result;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:7,代码来源:CompileEachLineOfProgramOutput.java


示例18: compress

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
@Override
public String compress(String source) {
	
	StringWriter writer = new StringWriter();
	
	//prepare source
	List<JSSourceFile> input = new ArrayList<JSSourceFile>();
	input.add(JSSourceFile.fromCode("source.js", source));
	
	//prepare externs
	List<JSSourceFile> externsList = new ArrayList<JSSourceFile>();
	if(compilationLevel.equals(CompilationLevel.ADVANCED_OPTIMIZATIONS)) {
		//default externs
		if(!customExternsOnly) {
			try {
				externsList = getDefaultExterns();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		//add user defined externs
		if(externs != null) {
			for(JSSourceFile extern : externs) {
				externsList.add(extern);
			}
		}
		//add empty externs
		if(externsList.size() == 0) {
			externsList.add(JSSourceFile.fromCode("externs.js", ""));
		}
	} else {
		//empty externs
		externsList.add(JSSourceFile.fromCode("externs.js", ""));
	}
	
	Compiler.setLoggingLevel(loggingLevel);
	
	Compiler compiler = new Compiler();
	compiler.disableThreads();
	
	compilationLevel.setOptionsForCompilationLevel(compilerOptions);
	warningLevel.setOptionsForWarningLevel(compilerOptions);
	
	Result result = compiler.compile(externsList, input, compilerOptions);
	
	if (result.success) {
		writer.write(compiler.toSource());
	} else {
		writer.write(source);
	}

	return writer.toString();

}
 
开发者ID:ad3n,项目名称:htmlcompressor,代码行数:55,代码来源:ClosureJavaScriptCompressor.java


示例19: fromCode

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/**
 * Constructs a JSSourceFile from a JavaScript snippet.
 */
static JSSourceFile fromCode(String source, EncodedFileName fileName) {
	return JSSourceFile.fromCode(fileName.toString(), source);
}
 
开发者ID:cursem,项目名称:ScriptCompressor,代码行数:7,代码来源:RhinoASTToFlowgraph.java


示例20: fromEmptyCode

import com.google.javascript.jscomp.JSSourceFile; //导入依赖的package包/类
/**
 * Empty JavaScript code snippet; used by the Rhino parser.
 */
static JSSourceFile fromEmptyCode() { // TODO: why is this method needed??
	return fromCode("", new EncodedFileName("dummy.js"));
}
 
开发者ID:cursem,项目名称:ScriptCompressor,代码行数:7,代码来源:RhinoASTToFlowgraph.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ReconcileContext类代码示例发布时间:2022-05-23
下一篇:
Java LengthIndexedLine类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap