本文整理汇总了Java中com.google.javascript.jscomp.CompilationLevel类的典型用法代码示例。如果您正苦于以下问题:Java CompilationLevel类的具体用法?Java CompilationLevel怎么用?Java CompilationLevel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompilationLevel类属于com.google.javascript.jscomp包,在下文中一共展示了CompilationLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compressJs
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的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);
}
示例2: GccMinifier
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的package包/类
public GccMinifier(MinifyBuilder builder, IFile srcFile, IFile destFile,
OutputStream out, IEclipsePreferences prefs)
throws IOException, CoreException {
super(builder);
this.srcFile = srcFile;
this.out = out;
this.outCharset = destFile.exists() ? destFile.getCharset() : "ascii";
console = builder.minifierConsole();
String optLevel = prefs.get(PrefsAccess.preferenceKey(
srcFile, MinifyBuilder.GCC_OPTIMIZATION),
MinifyBuilder.GCC_OPT_WHITESPACE_ONLY);
switch (optLevel) {
case MinifyBuilder.GCC_OPT_ADVANCED:
compilationLevel = CompilationLevel.ADVANCED_OPTIMIZATIONS;
break;
case MinifyBuilder.GCC_OPT_SIMPLE:
compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
break;
default:
compilationLevel = CompilationLevel.WHITESPACE_ONLY;
}
}
示例3: minify
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的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);
}
示例4: initCompilationResources
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的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;
}
示例5: CompileTask
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的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();
}
示例6: compile
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的package包/类
/**
* Attempts to compile the given input files and returns the created script.
* Any problems are logged to the provided logger. As a fallback strategy,
* if the closure compiler fails, a simple concatenated script is returned,
* to ensure that at least some of the functionality provided by the scripts
* will be present.
*
* @param inputFiles
* the input files must already be sorted, i.e. be in a valid
* order w.r.t. dependencies.
*/
public String compile(List<JavaScriptFile> inputFiles,
List<JavaScriptFile> externFiles, ILogger logger) {
if (DISABLE_COMPILATION) {
return "/* compilation disabled */";
}
logger.info("Compilation mode: " + compilationMode);
switch (compilationMode) {
case OFF:
return concatScripts(inputFiles);
case SIMPLE:
return closureCompile(CompilationLevel.SIMPLE_OPTIMIZATIONS,
inputFiles, externFiles, logger);
case ADVANCED:
return closureCompile(CompilationLevel.ADVANCED_OPTIMIZATIONS,
inputFiles, externFiles, logger);
}
throw new AssertionError("Unknown compilation mode: " + compilationMode);
}
示例7: CompileTask
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的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<>();
}
示例8: compile
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的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();
}
示例9: CompileTask
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的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.entryPointParams = Lists.newLinkedList();
this.externFileLists = Lists.newLinkedList();
this.sourceFileLists = Lists.newLinkedList();
this.sourcePaths = Lists.newLinkedList();
this.warnings = Lists.newLinkedList();
}
示例10: testAdvancedJsFailbackToOriginal
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的package包/类
@Test
public void testAdvancedJsFailbackToOriginal() throws Exception {
googleClosureOutputProcessor.setCompilationLevel(CompilationLevel.ADVANCED_OPTIMIZATIONS.name());
final String js = "function myFunction()\n" +
"{\n" +
"var x=\"\",i;\n" +
"for (i=0;i<5;i++)\n" +
" {\n" +
" x=x + \"The number is \" + i + \"<br>\";\n" +
" }\n" +
"document.getElementById(\"demo\").innerHTML=x;\n" +
"}";
final StringReader reader = new StringReader(js);
final StringWriter writer = new StringWriter();
googleClosureOutputProcessor.process(reader, writer);
final String compiled = writer.getBuffer().toString();
assertEquals(js, compiled);
}
示例11: compile
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的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();
}
示例12: CompileTask
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的package包/类
public CompileTask() {
this.warningLevel = WarningLevel.DEFAULT;
this.debugOptions = false;
this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
this.customExternsOnly = false;
this.externFileLists = Lists.newLinkedList();
this.sourceFileLists = Lists.newLinkedList();
}
示例13: setCompilationLevel
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的package包/类
/**
* Set the compilation level.
* @param value The optimization level by string name.
* (whitespace, simple, advanced).
*/
public void setCompilationLevel(String value) {
if ("simple".equalsIgnoreCase(value)) {
this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
} else if ("advanced".equalsIgnoreCase(value)) {
this.compilationLevel = CompilationLevel.ADVANCED_OPTIMIZATIONS;
} else if ("whitespace".equalsIgnoreCase(value)) {
this.compilationLevel = CompilationLevel.WHITESPACE_ONLY;
} else {
throw new BuildException(
"Unrecognized 'compilation' option value (" + value + ")");
}
}
示例14: testEnumToArgv
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的package包/类
@Test
public static void testEnumToArgv() throws Exception {
JsOptions opts = new JsOptions();
opts.compilationLevel = CompilationLevel.ADVANCED_OPTIMIZATIONS;
assertEquals(
ImmutableList.of("--compilation_level", "ADVANCED_OPTIMIZATIONS"),
sanityCheckArgv(opts));
}
示例15: testCompilationLevel
import com.google.javascript.jscomp.CompilationLevel; //导入依赖的package包/类
@Test
public static void testCompilationLevel() throws Exception {
JsOptions opts = new JsOptions();
opts.compilationLevel = sampleValueFor(
"compilationLevel", CompilationLevel.class);
sanityCheckArgv(opts);
}