private DependencyInfo generateDependencyInfo() {
    Preconditions.checkNotNull(compiler, "Expected setCompiler to be called first: %s", this);
    Preconditions.checkNotNull(
        compiler.getErrorManager(), "Expected compiler to call an error manager: %s", this);

    // If the code is a JsAst, then it was originally JS code, and is compatible with the
    // regex-based parsing of JsFileParser.
    if (ast instanceof JsAst && JsFileParser.isSupported()) {
      // Look at the source code.
      // Note: it's OK to use getName() instead of
      // getPathRelativeToClosureBase() here because we're not using
      // this to generate deps files. (We're only using it for
      // symbol dependencies.)
      try {
        DependencyInfo info =
            new JsFileParser(compiler.getErrorManager())
                .setModuleLoader(compiler.getModuleLoader())
                .setIncludeGoogBase(true)
                .parseFile(getName(), getName(), getCode());
        return new LazyParsedDependencyInfo(info, (JsAst) ast, compiler);
      } catch (IOException e) {
        compiler.getErrorManager().report(CheckLevel.ERROR,
            JSError.make(AbstractCompiler.READ_ERROR, getName(), e.getMessage()));
        return SimpleDependencyInfo.EMPTY;
      }
    } else {
      // Otherwise, just look at the AST.

      DepsFinder finder = new DepsFinder(getPath());
      Node root = getAstRoot(compiler);
      if (root == null) {
        return SimpleDependencyInfo.EMPTY;
      }

      finder.visitTree(root);
      JSDocInfo info = root.getJSDocInfo();

      // TODO(nicksantos|user): This caching behavior is a bit
      // odd, and only works if you assume the exact call flow that
      // clients are currently using.  In that flow, they call
      // getProvides(), then remove the goog.provide calls from the
      // AST, and then call getProvides() again.
      //
      // This won't work for any other call flow, or any sort of incremental
      // compilation scheme. The API needs to be fixed so callers aren't
      // doing weird things like this, and then we should get rid of the
      // multiple-scan strategy.
      return SimpleDependencyInfo.builder("", "")
          .setProvides(finder.provides)
          .setRequires(finder.requires)
          .setTypeRequires(finder.typeRequires)
          .setLoadFlags(finder.loadFlags)
          .setHasExternsAnnotation(info != null && info.isExterns())
          .setHasNoCompileAnnotation(info != null && info.isNoCompile())
          .build();
    }
  }
private DependencyInfo generateDependencyInfo ( ) { Preconditions . checkNotNull ( compiler , "Expected setCompiler to be called first: %s" , this ) ; Preconditions . checkNotNull ( compiler . getErrorManager ( ) , "Expected compiler to call an error manager: %s" , this ) ; if ( ast instanceof JsAst && JsFileParser . isSupported ( ) ) { try { DependencyInfo info = new JsFileParser ( compiler . getErrorManager ( ) ) . setModuleLoader ( compiler . getModuleLoader ( ) ) . setIncludeGoogBase ( true ) . parseFile ( getName ( ) , getName ( ) , getCode ( ) ) ; return new LazyParsedDependencyInfo ( info , ( JsAst ) ast , compiler ) ; } catch ( IOException e ) { compiler . getErrorManager ( ) . report ( CheckLevel . ERROR , JSError . make ( AbstractCompiler . READ_ERROR , getName ( ) , e . getMessage ( ) ) ) ; return SimpleDependencyInfo . EMPTY ; } } else { DepsFinder finder = new DepsFinder ( getPath ( ) ) ; Node root = getAstRoot ( compiler ) ; if ( root == null ) { return SimpleDependencyInfo . EMPTY ; } finder . visitTree ( root ) ; JSDocInfo info = root . getJSDocInfo ( ) ; return SimpleDependencyInfo . builder ( "" , "" ) . setProvides ( finder . provides ) . setRequires ( finder . requires ) . setTypeRequires ( finder . typeRequires ) . setLoadFlags ( finder . loadFlags ) . setHasExternsAnnotation ( info != null && info . isExterns ( ) ) . setHasNoCompileAnnotation ( info != null && info . isNoCompile ( ) ) . build ( ) ; } }
Generates the DependencyInfo by scanning and/or parsing the file.
This is called lazily by getDependencyInfo, and does not take into
account any extra requires/provides added by {@link #addRequire}
or {@link #addProvide}.