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


Java SourceFile类代码示例

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


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

示例1: compressJs

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

示例2: run

import com.google.javascript.jscomp.SourceFile; //导入依赖的package包/类
private void run() {
  Options options =
      Options.builder()
          .outputJarFile(output)
          .outputDependencyFile(outputDependencyPath)
          .packagePrefix(packagePrefix)
          .extensionTypePrefix(extensionTypePrefix)
          .debugEnabled(debugEnabled)
          .beanConventionUsed(beanConvention)
          .dependencyMappingFiles(dependencyMappingFilePaths)
          .nameMappingFiles(nameMappingFilePaths)
          .integerEntitiesFiles(integerEntitiesFiles)
          .wildcardTypesFiles(wildcardTypesFiles)
          .dependencies(
              dependencyFilePaths.stream().map(SourceFile::fromFile).collect(toImmutableList()))
          .sources(sourceFilePaths.stream().map(SourceFile::fromFile).collect(toImmutableList()))
          .build();

  new ClosureJsInteropGenerator(options).convert();
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:21,代码来源:Runner.java

示例3: minify

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

import com.google.javascript.jscomp.SourceFile; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private OOPSourceCodeModel compileFiles(List<RawFile> files, List<String> projectFileTypes) {
    OOPSourceCodeModel model = new OOPSourceCodeModel();
    for (RawFile file : files) {
        try {
            Compiler compiler = new Compiler();
            CompilerOptions options = new CompilerOptions();
            options.setIdeMode(true);
            options.setParseJsDocDocumentation(JsDocParsing.INCLUDE_DESCRIPTIONS_WITH_WHITESPACE);
            compiler.initOptions(options);
            Node root = new JsAst(SourceFile.fromCode(file.name(), file.content())).getAstRoot(compiler);
            JavaScriptListener jsListener = new JavaScriptListener(model, file, projectFileTypes);
            NodeTraversal.traverseEs6(compiler, root, jsListener);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return model;
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:20,代码来源:ClarpseJSCompiler.java

示例5: generateDeclarations

import com.google.javascript.jscomp.SourceFile; //导入依赖的package包/类
String generateDeclarations(
    List<SourceFile> sourceFiles, List<SourceFile> externs, Depgraph depgraph)
    throws AssertionError {
  // Compile should always be first here, because it sets internal state.
  compiler.compile(externs, sourceFiles, opts.getCompilerOptions());
  if (opts.partialInput) {
    importRenameMap = ImportRenameMapBuilder.build(compiler.getParsedInputs());
  }
  unknownType = compiler.getTypeRegistry().getNativeType(JSTypeNative.UNKNOWN_TYPE);
  numberType = compiler.getTypeRegistry().getNativeType(JSTypeNative.NUMBER_TYPE);
  iterableType = compiler.getTypeRegistry().getType("Iterable");
  iteratorIterableType = compiler.getTypeRegistry().getType("IteratorIterable");
  // TODO(rado): replace with null and do not emit file when errors.
  String dts = "";
  // If there is an error top scope is null.
  if (compiler.getTopScope() != null) {
    precomputeChildLists();
    collectTypedefs();
    dts = produceDts(depgraph);
  }
  errorManager.doGenerateReport();
  return dts;
}
 
开发者ID:angular,项目名称:clutz,代码行数:24,代码来源:DeclarationGenerator.java

示例6: JSSourceManager

import com.google.javascript.jscomp.SourceFile; //导入依赖的package包/类
public JSSourceManager() {
  nodeMap = new WeakHashMap<Node,JSExp>();
  sourceFiles = new ArrayList<JSSource>();
  sourceSet = new HashSet<String>();
  htmlFiles = new ArrayList<HTMLSource>();
  boolean useExterns = !JAMOpts.noExterns;
  needsCodeUpdate = false;
  needsCallGraphUpdate = true;
  try {
    if (useExterns) {
      // Load the full complement of native functions.
      externList = getDefaultExterns();
    } else {
      // Disable loading of natives for testing/profiling purposes.
      externList = new ArrayList<SourceFile>();
    }
    //SourceFile externFile = SourceFile.fromFile(JAMConfig.EXTERN_FILE);
    //externList.add(externFile);
  } catch (IOException ex) {
    System.err.println("Error loading externs: " + ex.getMessage());
  }
}
 
开发者ID:blackoutjack,项目名称:jamweaver,代码行数:23,代码来源:JSSourceManager.java

示例7: JSSource

import com.google.javascript.jscomp.SourceFile; //导入依赖的package包/类
public JSSource(String p, boolean wrap) {
  path = p;
  this.wrap = wrap;
  if (wrap) {
    // Read the contents, wrap in a function, and create from code.
    JSTransform namer = new JSTransform();
    wrapper = namer.newVariableName("f");
    try {
      String code = FileUtil.getFileContents(path);
      code = "function " + wrapper + "() {\n" + code + "\n}";
      sourceFile = SourceFile.fromCode(path, code);
    } catch (IOException ex) {
      Dbg.err("Unable to wrap event code: " + path);
      sourceFile = SourceFile.fromFile(path);
    }
  } else {
    sourceFile = SourceFile.fromFile(path);
  }
}
 
开发者ID:blackoutjack,项目名称:jamweaver,代码行数:20,代码来源:JSSource.java

示例8: map

import com.google.javascript.jscomp.SourceFile; //导入依赖的package包/类
@Override
public Resource<String> map(Resource<String> resource) {
    try {
        CompilerOptions options = new CompilerOptions();
        config.getCompilationLevel().setOptionsForCompilationLevel(options);
        options.setOutputCharset("UTF-8");
        options.setLanguageIn(config.getLanguage());

        SourceFile input = SourceFile.fromInputStream("dummy.js",
                new ByteArrayInputStream(resource.getContent().getBytes(Charsets.UTF_8)));
        List<SourceFile> externs = config.getExterns();

        Compiler compiler = new Compiler();
        compiler.compile(externs, Lists.newArrayList(input), options);

        if (compiler.hasErrors()) {
            throw new EvaluatorException(compiler.getErrors()[0].description);
        }

        return new Resource<String>(resource.getMimeType(), compiler.toSource(), StringHasher.instance);
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
 
开发者ID:rjnichols,项目名称:visural-web-resources,代码行数:25,代码来源:ClosureMinifyJavascript.java

示例9: invoke

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

示例10: compile

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

示例11: compile

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

示例12: checkSemicolon

import com.google.javascript.jscomp.SourceFile; //导入依赖的package包/类
private void checkSemicolon(NodeTraversal t, Node n) {
  StaticSourceFile staticSourceFile = n.getStaticSourceFile();
  if (staticSourceFile instanceof SourceFile) {
    SourceFile sourceFile = (SourceFile) staticSourceFile;

    String code;
    try {
      code = sourceFile.getCode();
    } catch (IOException e) {
      // We can't read the original source file. Just skip this check.
      return;
    }

    int length = n.getLength();
    if (length == 0) {
      // This check needs node lengths to work correctly. If we're not in IDE mode, we don't have
      // that information, so just skip the check.
      return;
    }
    int position = n.getSourceOffset() + length - 1;
    boolean endsWithSemicolon = code.charAt(position) == ';';
    if (!endsWithSemicolon) {
      t.report(n, MISSING_SEMICOLON);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:27,代码来源:CheckMissingSemicolon.java

示例13: buildSourceMaps

import com.google.javascript.jscomp.SourceFile; //导入依赖的package包/类
private static ImmutableMap<String, SourceMapInput> buildSourceMaps(
    File[] src, String unknownPrefix) {
  ImmutableMap.Builder<String, SourceMapInput> inputSourceMaps = new ImmutableMap.Builder<>();
  if (src != null) {
    for (int i = 0; i < src.length; ++i) {
      File file = src[i];
      if (isNullOrEmpty(file.sourceMap)) {
        continue;
      }
      String path = file.path;
      if (path == null) {
        path = unknownPrefix + i;
      }
      path += ".map";
      SourceFile sf = SourceFile.fromCode(path, file.sourceMap);
      inputSourceMaps.put(path, new SourceMapInput(sf));
    }
  }
  return inputSourceMaps.build();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:21,代码来源:GwtRunner.java

示例14: compile

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

示例15: testDuplicateProvidesErrorThrownIfBadClosurePathSpecified

import com.google.javascript.jscomp.SourceFile; //导入依赖的package包/类
/**
 * Ensures that an error is thrown when the closure_path flag is set incorrectly.
 */
public void testDuplicateProvidesErrorThrownIfBadClosurePathSpecified() throws Exception {
  // Create a stub Closure Library.
  SourceFile fauxClosureDeps =
      SourceFile.fromCode("dep1.js", "goog.addDependency('foo/a.js', ['a'], []);\n");
  SourceFile fauxClosureSrc =
      SourceFile.fromCode("path/to/closure/foo/a.js", "goog.provide('a');\n");
  // Create a source file that depends on the stub Closure Library.
  SourceFile userSrc =
      SourceFile.fromCode("my/package/script.js", "goog.require('a');\n"
          + "goog.provide('my.package.script');\n");

  // doErrorMessagesRun uses closure_path //javascript/closure and therefore
  // fails to recognize and de-dupe the stub Closure Library at
  // //path/to/closure.
  doErrorMessagesRun(ImmutableList.of(fauxClosureDeps),
      ImmutableList.of(fauxClosureSrc, userSrc), true /* fatal */,
      "Namespace \"a\" is already provided in other file dep1.js");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:DepsGeneratorTest.java


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