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


Java Compiler.disableThreads方法代码示例

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


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

示例1: createCompiler

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
private Compiler createCompiler() {
    try {
        Compiler closureCompiler  = new Compiler(new PrintStream(new DiscardOutputStream(), false, "UTF-8"));
        closureCompiler.disableThreads();
        Compiler.setLoggingLevel(Level.INFO);
        return closureCompiler;
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:factoryfx,项目名称:factoryfx,代码行数:11,代码来源:ContentAssist.java

示例2: compile

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

示例3: main

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  Compiler compiler = new Compiler(System.err);
  compiler.disableThreads(); // Makes errors easier to track down.

  List<SourceFile> inputs = ImmutableList.of(
      SourceFile.fromInputStream("stdin", System.in, StandardCharsets.UTF_8)
  );

  CompilerOptions options = new CompilerOptions();
  Result result = compiler.compile(
      Collections.<SourceFile>emptyList(), inputs, options);
  dump(compiler.getRoot(), 0, System.out);
  System.out.append("\n");
}
 
开发者ID:mihaip,项目名称:react-closure-compiler,代码行数:15,代码来源:AstDump.java

示例4: testPropType

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
private void testPropType(String reactPropType, String typeExpression) {
  Compiler compiler = new Compiler();
  CompilerOptions options = new CompilerOptions();
  // So that source dumps still have JSDoc
  options.preserveTypeAnnotations = true;
  compiler.initOptions(options);
  // Avoid extra "use strict" boilerplate in output.
  options.setEmitUseStrict(false);
  compiler.disableThreads(); // Makes errors easier to track down.
  Node reactPropTypeNode = compiler.parse(
      SourceFile.fromCode("/src/test.js", reactPropType))
      .getFirstChild().getFirstChild();
  assertArrayEquals(new JSError[]{}, compiler.getErrors());

  Node typeNode = PropTypesExtractor.convertPropType(reactPropTypeNode)
      .typeNode;

  // Easiest way to stringify the type node is to print it out as JSDoc.
  JSDocInfoBuilder jsDocInfoBuilder = new JSDocInfoBuilder(true);
  jsDocInfoBuilder.recordType(new JSTypeExpression(
      typeNode, "/src/test.js"));
  Node tempNode = IR.var(IR.name("temp"));
  tempNode.setJSDocInfo(jsDocInfoBuilder.build());
  String tempCode = compiler.toSource(tempNode);

  assertEquals("/** @type {" + typeExpression + "} */ var temp", tempCode);
}
 
开发者ID:mihaip,项目名称:react-closure-compiler,代码行数:28,代码来源:PropTypesExtractorTest.java

示例5: process

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
@Override
public String process(File[] srcFiles) throws ProcessException {
    CompilerOptions compilerOptions = new CompilerOptions();
    compilerOptions.setCodingConvention(new ClosureCodingConvention());
    compilerOptions.setOutputCharset("UTF-8");
    compilerOptions.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING);
    compilerOptions.setLanguage(CompilerOptions.LanguageMode.ECMASCRIPT5);
    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(compilerOptions);

    Compiler compiler = new Compiler();
    compiler.disableThreads();
    compiler.initOptions(compilerOptions);

    ArrayList<SourceFile> inputFiles = new ArrayList<SourceFile>();

    for (File srcFile : srcFiles) {
        SourceFile inputFile = SourceFile.fromFile(srcFile);
        inputFiles.add(inputFile);
    }

    Result result = compiler.compile(new ArrayList<SourceFile>(), inputFiles, compilerOptions);

    if (!result.success) {
        throw new ProcessException("Failure when processing javascript files!");
    }

    return compiler.toSource();
}
 
开发者ID:instant-solutions,项目名称:gradle-website-optimizer,代码行数:29,代码来源:JsProcessor.java

示例6: process

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
@Override
public void process(final Reader reader, final Writer writer) throws IOException {
    logger.debug("google closure processing...");
    final String originalJsSourceCode = IOUtils.toString(reader);
    try {
        Compiler.setLoggingLevel(Level.SEVERE);
        final Compiler compiler = new Compiler();
        final CompilerOptions compilerOptions = newCompilerOptions();
        compilationLevel.setOptionsForCompilationLevel(compilerOptions);
        //make it play nice with GAE
        compiler.disableThreads();
        compiler.initOptions(compilerOptions);

        final SourceFile input = SourceFile.fromInputStream("dummy.js", new ByteArrayInputStream(originalJsSourceCode.getBytes(soyViewConf.globalEncoding())));
        final Result result = compiler.compile(Lists.<SourceFile>newArrayList(), Lists.newArrayList(input), compilerOptions);

        logWarningsAndErrors(result);

        boolean origFallback = false;
        if (result.success) {
            final String minifiedJsSourceCode = compiler.toSource();
            if (StringUtils.isEmpty(minifiedJsSourceCode)) {
                origFallback = true;
            } else {
                writer.write(minifiedJsSourceCode);
            }
        } else {
            origFallback = true;
        }
        if (origFallback) {
            writer.write(originalJsSourceCode);
        }
    } finally {
        reader.close();
        writer.close();
    }
}
 
开发者ID:matiwinnetou,项目名称:play-soy-view,代码行数:38,代码来源:GoogleClosureOutputProcessor.java

示例7: createCompiler

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
private static Compiler createCompiler(
    List<SourceFile> inputs, List<SourceFile> externs, CompilerOptions compilerOptions) {
  Compiler compiler = new Compiler(new BlackHoleErrorManager());
  compiler.disableThreads();
  compiler.compile(externs, inputs, compilerOptions);
  return compiler;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:8,代码来源:RefactoringDriver.java

示例8: setUp

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
@Before
public void setUp() {
  errorManager = new FixingErrorManager();
  compiler = new Compiler(errorManager);
  compiler.disableThreads();
  errorManager.setCompiler(compiler);

  options = RefactoringDriver.getCompilerOptions();
  options.setWarningLevel(DiagnosticGroups.ANALYZER_CHECKS, WARNING);
  options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, ERROR);
  options.setWarningLevel(DiagnosticGroups.DEBUGGER_STATEMENT_PRESENT, ERROR);
  options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, WARNING);
  options.setWarningLevel(DiagnosticGroups.STRICT_MISSING_REQUIRE, ERROR);
  options.setWarningLevel(DiagnosticGroups.EXTRA_REQUIRE, ERROR);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:16,代码来源:ErrorToFixMapperTest.java

示例9: getCompiler

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
private static Compiler getCompiler(String externs, String jsInput) {
  Compiler compiler = new Compiler(new BlackHoleErrorManager());
  compiler.disableThreads();
  CompilerOptions options = RefactoringDriver.getCompilerOptions();
  compiler.compile(
      ImmutableList.of(SourceFile.fromCode("externs", externs)),
      ImmutableList.of(SourceFile.fromCode("test", jsInput)),
      options);
  return compiler;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:11,代码来源:MatchersTest.java

示例10: process

import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
@Override
public String process(final String filename, final String source, final Config conf)
    throws Exception {
  final CompilerOptions copts = new CompilerOptions();
  copts.setCodingConvention(new ClosureCodingConvention());
  copts.setOutputCharset("UTF-8");
  copts.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING);
  CompilationLevel level = level(get("level"));
  level.setOptionsForCompilationLevel(copts);

  Compiler.setLoggingLevel(Level.SEVERE);
  Compiler compiler = new Compiler();
  compiler.disableThreads();
  compiler.initOptions(copts);

  List<SourceFile> externs = externs(copts);
  Result result = compiler.compile(externs,
      ImmutableList.of(SourceFile.fromCode(filename, source)), copts);
  if (result.success) {
    return compiler.toSource();
  }
  List<AssetProblem> errors = Arrays.stream(result.errors)
      .map(error -> new AssetProblem(error.sourceName, error.lineNumber, error.getCharno(),
          error.description, null))
      .collect(Collectors.toList());
  throw new AssetException(name(), errors);
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:28,代码来源:ClosureCompiler.java

示例11: compress

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

示例12: outputSource

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


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