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


Java Result类代码示例

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


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

示例1: execute

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

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public void testRequiresAreCaughtBeforeProcessed() {
  String js = "var foo = {}; var bar = new foo.bar.goo();";
  JSSourceFile input = JSSourceFile.fromCode("foo.js", js);
  Compiler compiler = new Compiler();
  CompilerOptions opts = new CompilerOptions();
  opts.checkRequires = CheckLevel.WARNING;
  opts.closurePass = true;

  Result result = compiler.compile(new JSSourceFile[] {},
      new JSSourceFile[] {input}, opts);
  JSError[] warnings = result.warnings;
  assertNotNull(warnings);
  assertTrue(warnings.length > 0);

  String expectation = "'foo.bar.goo' used but not goog.require'd";

  for (JSError warning : warnings) {
    if (expectation.equals(warning.description)) {
      return;
    }
  }

  fail("Could not find the following warning:" + expectation);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:CheckRequiresForConstructorsTest.java

示例3: minify

import com.google.javascript.jscomp.Result; //导入依赖的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);
}
 
开发者ID:factoryfx,项目名称:factoryfx,代码行数:24,代码来源:JavaScriptFile.java

示例4: execute

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

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
CompiledScript invoke() throws Exception {
  Compiler compiler = new Compiler();

  compiler.setLoggingLevel( Level.OFF );

  SourceFile input = SourceFile.fromFile( srcFile );
  input.setOriginalPath( relSrcFilePath );

  Result res = compiler.compile( EMPTY_EXTERNS_SOURCE_FILE, input, options );
  if ( res.success ) {
    String name = srcFile.getName();

    code = new StringBuilder( compiler.toSource() );
    code.append( "\n//# sourceMappingURL=" ).append( name ).append( ".map" );

    sourcemap = new StringBuilder();
    SourceMap sm = compiler.getSourceMap();
    sm.appendTo( sourcemap, name );

    return this;
  }

  throw new Exception( "Failed script compilation" );
}
 
开发者ID:pentaho,项目名称:pentaho-osgi-bundles,代码行数:25,代码来源:WebjarsURLConnection.java

示例6: compile

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public void compile(JsonML source) {
  if (report != null) {
    throw new IllegalStateException(COMPILATION_ALREADY_COMPLETED_MSG);
  }

  sourceAst = new JsonMLAst(source);

  CompilerInput input = new CompilerInput(
      sourceAst, "[[jsonmlsource]]", false);

  JSModule module = new JSModule("[[jsonmlmodule]]");
  module.add(input);

  Result result = compiler.compileModules(
      ImmutableList.<SourceFile>of(),
      ImmutableList.of(module),
      options);

  report = generateReport(result);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:SecureCompiler.java

示例7: generateReport

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
Report generateReport(Result result) {
  // a report may be generated only after actual compilation is complete
  if (result == null) {
    return null;
  }

  ArrayList<JsonMLError> errors = Lists.newArrayList();
  for (JSError error : result.errors) {
    errors.add(JsonMLError.make(error, sourceAst));
  }

  ArrayList<JsonMLError> warnings = Lists.newArrayList();
  for (JSError warning : result.warnings) {
    warnings.add(JsonMLError.make(warning, sourceAst));
  }

  return new Report(
      errors.toArray(new JsonMLError[0]),
      warnings.toArray(new JsonMLError[0]));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:SecureCompiler.java

示例8: testRequiresAreCaughtBeforeProcessed

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public void testRequiresAreCaughtBeforeProcessed() {
  String js = "var foo = {}; var bar = new foo.bar.goo();";
  SourceFile input = SourceFile.fromCode("foo.js", js);
  Compiler compiler = new Compiler();
  CompilerOptions opts = new CompilerOptions();
  opts.checkRequires = CheckLevel.WARNING;
  opts.closurePass = true;

  Result result = compiler.compile(ImmutableList.<SourceFile>of(),
      ImmutableList.of(input), opts);
  JSError[] warnings = result.warnings;
  assertNotNull(warnings);
  assertTrue(warnings.length > 0);

  String expectation = "'foo.bar.goo' used but not goog.require'd";

  for (JSError warning : warnings) {
    if (expectation.equals(warning.description)) {
      return;
    }
  }

  fail("Could not find the following warning:" + expectation);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:CheckRequiresForConstructorsTest.java

示例9: compile

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public CompileResult compile(Path path, String code) {
  Compiler compiler = compiler();
  Result result =
      compiler.compile(EXTERNS, SourceFile.fromCode(path.toString(), code), options());
  String source = compiler.toSource();
  StringBuilder sourceMap = new StringBuilder();
  if (result.sourceMap != null) {
    try {
      result.sourceMap.appendTo(sourceMap, path.toString());
    } catch (IOException e) {
      // impossible, and not a big deal even if it did happen.
    }
  }
  boolean transpiled = !result.transpiledFiles.isEmpty();
  if (result.errors.length > 0) {
    throw new TranspilationException(compiler, result.errors, result.warnings);
  }
  return new CompileResult(
      source,
      transpiled,
      transpiled ? sourceMap.toString() : "");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:BaseTranspiler.java

示例10: compile

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public CompileResult compile(Path path, String code) {
  Compiler compiler = compiler();
  Result result =
      compiler.compile(EXTERNS, SourceFile.fromCode(path.toString(), code), options());
  String source = compiler.toSource();
  StringBuilder sourceMap = new StringBuilder();
  if (result.sourceMap != null) {
    try {
      result.sourceMap.appendTo(sourceMap, path.toString());
    } catch (IOException e) {
      // impossible, and not a big deal even if it did happen.
    }
  }
  boolean transformed = transformed(result);
  return new CompileResult(
      source, result.errors, transformed, transformed ? sourceMap.toString() : "");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:18,代码来源:CompilerBasedTransformer.java

示例11: writeSourceMap

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
private void writeSourceMap(Result result, String sourceMap, String output) {
	File file = new File(sourceMap);
	try {
		StringBuffer buffer = new StringBuffer();
		result.sourceMap.appendTo(buffer, output);
		Files.createParentDirs(file);
		Files.write(buffer.toString().getBytes(), file);
	} catch (IOException e) {
		getErrorManager()
				.reportMessage(
						new Status(
								StatusType.ERROR,
								MessageFormat.format(
										resourceBundle
												.getString(IConstants.JSConsole_SourceMapFailed),
										sourceMap), null));
	}
}
 
开发者ID:DigiArea,项目名称:closurefx-builder,代码行数:19,代码来源:JSCCompilerCli.java

示例12: writeSourceMap

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
private void writeSourceMap(Result result, String sourceMap, String output) {
	File file = new File(sourceMap);
	try {
		StringBuffer buffer = new StringBuffer();
		result.sourceMap.appendTo(buffer, output);
		Files.createParentDirs(file);
		Files.write(buffer.toString().getBytes(), file);
	} catch (IOException e) {
		getErrorManager()
				.getConsoleManager()
				.reportMessage(
						new Status(
								StatusType.ERROR,
								MessageFormat.format(
										resourceBundle
												.getString(IConstants.JSConsole_SourceMapFailed),
										sourceMap), null));
	}
}
 
开发者ID:DigiArea,项目名称:closurefx-builder,代码行数:20,代码来源:JSCCompiler.java

示例13: compile

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
/**
 * Copied verbatim from com.google.javascript.jscomp.Compiler, except using getter methods instead
 * of private fields and running cloneParsedInputs() at the appropriate time.
 */
@Override
public <T1 extends SourceFile, T2 extends SourceFile> Result compile(
    List<T1> externs, List<T2> inputs, CompilerOptions options) {
  // The compile method should only be called once.
  checkState(getRoot() == null);

  try {
    init(externs, inputs, options);
    if (!hasErrors()) {
      parseForCompilation();
      cloneParsedInputs();
    }
    if (!hasErrors()) {
      if (options.getInstrumentForCoverageOnly()) {
        // TODO(bradfordcsmith): The option to instrument for coverage only should belong to the
        //     runner, not the compiler.
        instrumentForCoverage();
      } else {
        stage1Passes();
        if (!hasErrors()) {
          stage2Passes();
        }
      }
      performPostCompilationTasks();
    }
  } finally {
    generateReport();
  }
  return getResult();
}
 
开发者ID:angular,项目名称:clutz,代码行数:35,代码来源:InitialParseRetainingCompiler.java

示例14: main

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

示例15: createTypesNode

import com.google.javascript.jscomp.Result; //导入依赖的package包/类
private Node createTypesNode() {
  if (templateTypesNode == null) {
    String typesJs = React.getTypesJs();
    Result previousResult = compiler.getResult();
    templateTypesNode =
      compiler.parse(SourceFile.fromCode(React.TYPES_JS_RESOURCE_PATH, typesJs));
    Result result = compiler.getResult();
    if ((result.success != previousResult.success && previousResult.success) ||
        result.errors.length > previousResult.errors.length ||
        result.warnings.length > previousResult.warnings.length) {
      String message = "Could not parse " + React.TYPES_JS_RESOURCE_PATH + ".";
      if (result.errors.length > 0) {
        message += "\nErrors: " + Joiner.on(",").join(result.errors);
      }
      if (result.warnings.length > 0) {
        message += "\nWarnings: " + Joiner.on(",").join(result.warnings);
      }
      throw new RuntimeException(message);
    }
    // Gather ReactComponent prototype methods.
    NodeTraversal.traverseEs6(
        compiler,
        templateTypesNode,
        new NodeTraversal.AbstractPostOrderCallback() {
          @Override public void visit(NodeTraversal t, Node n, Node parent) {
            if (!n.isAssign() || !n.getFirstChild().isQualifiedName() ||
                !n.getFirstChild().getQualifiedName().startsWith(
                    "ReactComponent.prototype.") ||
                !n.getLastChild().isFunction()) {
                return;
            }
            componentMethodJsDocs.put(
                n.getFirstChild().getLastChild().getString(),
                n.getJSDocInfo());
          }
        });
  }
  return templateTypesNode.cloneTree();
}
 
开发者ID:mihaip,项目名称:react-closure-compiler,代码行数:40,代码来源:ReactCompilerPass.java


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