private void addCodeToRequireGoogModules(SoyFileNode soyFile) {
    int counter = 1;

    // Get all the unique calls in the file.
    Set<String> calls = new HashSet<>();
    for (CallBasicNode callNode : SoyTreeUtils.getAllNodesOfType(soyFile, CallBasicNode.class)) {
      calls.add(callNode.getCalleeName());
    }

    // Map all the unique namespaces to the templates in those namespaces.
    SetMultimap<String, String> namespaceToTemplates = TreeMultimap.create();
    for (String call : calls) {
      namespaceToTemplates.put(call.substring(0, call.lastIndexOf('.')), call);
    }

    for (String namespace : namespaceToTemplates.keySet()) {
      // Skip the file's own namespace as there is nothing to import/alias.
      if (namespace.equals(soyFile.getNamespace())) {
        continue;
      }

      // Add a require of the module
      String namespaceAlias = "$import" + counter++;
      String importNamespace = getGoogModuleNamespace(namespace);
      jsCodeBuilder.append(
          VariableDeclaration.builder(namespaceAlias)
              .setRhs(GOOG_REQUIRE.call(stringLiteral(importNamespace)))
              .build());
      // Alias all the templates used from the module
      for (String fullyQualifiedName : namespaceToTemplates.get(namespace)) {
        String alias = templateAliases.get(fullyQualifiedName);
        String shortName = fullyQualifiedName.substring(fullyQualifiedName.lastIndexOf('.'));
        jsCodeBuilder.append(
            VariableDeclaration.builder(alias)
                .setRhs(dottedIdNoRequire(namespaceAlias + shortName))
                .build());
      }
    }
  }
private void addCodeToRequireGoogModules ( SoyFileNode soyFile ) { int counter = 1 ; Set < String > calls = new HashSet < > ( ) ; for ( CallBasicNode callNode : SoyTreeUtils . getAllNodesOfType ( soyFile , CallBasicNode . class ) ) { calls . add ( callNode . getCalleeName ( ) ) ; } SetMultimap < String , String > namespaceToTemplates = TreeMultimap . create ( ) ; for ( String call : calls ) { namespaceToTemplates . put ( call . substring ( 0 , call . lastIndexOf ( '.' ) ) , call ) ; } for ( String namespace : namespaceToTemplates . keySet ( ) ) { if ( namespace . equals ( soyFile . getNamespace ( ) ) ) { continue ; } String namespaceAlias = "$import" + counter ++ ; String importNamespace = getGoogModuleNamespace ( namespace ) ; jsCodeBuilder . append ( VariableDeclaration . builder ( namespaceAlias ) . setRhs ( GOOG_REQUIRE . call ( stringLiteral ( importNamespace ) ) ) . build ( ) ) ; for ( String fullyQualifiedName : namespaceToTemplates . get ( namespace ) ) { String alias = templateAliases . get ( fullyQualifiedName ) ; String shortName = fullyQualifiedName . substring ( fullyQualifiedName . lastIndexOf ( '.' ) ) ; jsCodeBuilder . append ( VariableDeclaration . builder ( alias ) . setRhs ( dottedIdNoRequire ( namespaceAlias + shortName ) ) . build ( ) ) ; } } }
Generates the module imports and aliasing. This generates code like the following:

<pre>
var $import1 = goog.require('some.namespace');
var $templateAlias1 = $import1.tmplOne;
var $templateAlias2 = $import1.tmplTwo;
var $import2 = goog.require('other.namespace');
...
</pre>

@param soyFile The node we're visiting.