Search in sources :

Example 1 with FindCalleesNotInFileVisitor

use of com.google.template.soy.shared.internal.FindCalleesNotInFileVisitor in project closure-templates by google.

the class GenJsCodeVisitor method addCodeToRequireSoyNamespaces.

/**
 * Helper for visitSoyFileNode(SoyFileNode) to add code to require Soy namespaces.
 *
 * @param soyFile The node we're visiting.
 */
private void addCodeToRequireSoyNamespaces(SoyFileNode soyFile) {
    String prevCalleeNamespace = null;
    Set<String> calleeNamespaces = new TreeSet<>();
    for (CallBasicNode node : new FindCalleesNotInFileVisitor().exec(soyFile)) {
        String calleeNotInFile = node.getCalleeName();
        int lastDotIndex = calleeNotInFile.lastIndexOf('.');
        calleeNamespaces.add(calleeNotInFile.substring(0, lastDotIndex));
    }
    for (String calleeNamespace : calleeNamespaces) {
        if (calleeNamespace.length() > 0 && !calleeNamespace.equals(prevCalleeNamespace)) {
            jsCodeBuilder.addGoogRequire(GoogRequire.create(calleeNamespace));
            prevCalleeNamespace = calleeNamespace;
        }
    }
}
Also used : FindCalleesNotInFileVisitor(com.google.template.soy.shared.internal.FindCalleesNotInFileVisitor) TreeSet(java.util.TreeSet) CallBasicNode(com.google.template.soy.soytree.CallBasicNode)

Aggregations

FindCalleesNotInFileVisitor (com.google.template.soy.shared.internal.FindCalleesNotInFileVisitor)1 CallBasicNode (com.google.template.soy.soytree.CallBasicNode)1 TreeSet (java.util.TreeSet)1