com.google.javascript.rhino.StaticSourceFile Java Examples

The following examples show how to use com.google.javascript.rhino.StaticSourceFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractClosureVisitor.java    From jsinterop-generator with Apache License 2.0 5 votes vote down vote up
AbstractClosureVisitor(GenerationContext context) {
  this.context = context;
  externFileNamesSet =
      Streams.concat(
              context.getExternDependencyFiles().stream(), context.getSourceFiles().stream())
          .map(StaticSourceFile::getName)
          .collect(Collectors.toSet());
}
 
Example #2
Source File: GenerationContext.java    From jsinterop-generator with Apache License 2.0 4 votes vote down vote up
public abstract Builder externDependencyFiles(
Collection<? extends StaticSourceFile> externFiles);
 
Example #3
Source File: DeclarationGenerator.java    From clutz with MIT License 4 votes vote down vote up
private void declareModule(
    String name, boolean isDefault, String emitName, StaticSourceFile sourceFile) {
  declareModule(name, isDefault, emitName, /* inParentNamespace= */ false, sourceFile);
}
 
Example #4
Source File: DeclarationGenerator.java    From clutz with MIT License 4 votes vote down vote up
private void declareModule(
    String name,
    boolean isDefault,
    String emitName,
    boolean inParentNamespace,
    StaticSourceFile sourceFile) {
  if (GOOG_BASE_NAMESPACE.equals(name)) {
    // goog:goog cannot be imported.
    return;
  }
  emitGeneratedFromFileComment(sourceFile);
  emitNoSpace("declare module '");
  emitNoSpace("goog:" + name);
  emitNoSpace("' {");
  indent();
  emitBreak();
  // Use the proper name as the alias name, so the TypeScript language service
  // can offer it as an auto-import (auto-imports are offered for the exported
  // name).
  String alias = getUnqualifiedName(name);

  // Make sure we don't emit a variable named after a keyword.
  if (RESERVED_JS_WORDS.contains(alias)) alias += "_";

  // workaround for https://github.com/Microsoft/TypeScript/issues/4325
  emit("import " + alias + " = ");
  emitNoSpace(Constants.INTERNAL_NAMESPACE);
  emitNoSpace(".");
  String emitNamespace = inParentNamespace ? getNamespace(emitName) : emitName;
  emitNoSpace(escapeKeywordsInNamespace(emitNamespace));
  emitNoSpace(";");
  emitBreak();
  if (isDefault) {
    emitNoSpace("export default " + alias);
    if (inParentNamespace) emitNoSpace("." + getUnqualifiedName(name));
    emitNoSpace(";");
  } else {
    emitNoSpace("export = " + alias + ";");
  }
  emitBreak();
  unindent();
  emit("}");
  emitBreak();
}
 
Example #5
Source File: Symbol.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
@Override
public StaticSourceFile getSourceFile() {
  throw new UnsupportedOperationException();
}
 
Example #6
Source File: DeclarationGenerator.java    From clutz with MIT License 3 votes vote down vote up
/**
 * This function should called before every top-level `declare module` or `declare namespace`
 * call. It is used by developers to better understand where symbols are coming from and also by
 * tools (e.g. http://kythe.io for JS <=> TS integration).
 *
 * @param file Original .js file that contained JS symbol for which module/namespace is being
 *     generated.
 */
private void emitGeneratedFromFileComment(StaticSourceFile file) {
  emit("// Generated from");
  String fileName = file == null ? "unknown file" : file.getName();
  emit(stripLineTerminators(fileName));
  emitBreak();
}
 
Example #7
Source File: GenerationContext.java    From jsinterop-generator with Apache License 2.0 votes vote down vote up
public abstract Builder sourceFiles(Collection<? extends StaticSourceFile> externFiles); 
Example #8
Source File: GenerationContext.java    From jsinterop-generator with Apache License 2.0 votes vote down vote up
public abstract ImmutableSet<StaticSourceFile> getSourceFiles(); 
Example #9
Source File: GenerationContext.java    From jsinterop-generator with Apache License 2.0 votes vote down vote up
public abstract ImmutableSet<StaticSourceFile> getExternDependencyFiles();