use of com.google.template.soy.soytree.TemplateBasicNode in project closure-templates by google.
the class ContextualAutoescaper method findTemplates.
/**
* Fills in the {@link Inferences} template name to node map.
*
* @param files Modified in place.
*/
private static ImmutableListMultimap<String, TemplateNode> findTemplates(Iterable<? extends SoyFileNode> files) {
ImmutableListMultimap.Builder<String, TemplateNode> builder = ImmutableListMultimap.builder();
for (SoyFileNode file : files) {
for (TemplateNode template : file.getChildren()) {
String templateName;
if (template instanceof TemplateBasicNode) {
templateName = template.getTemplateName();
} else {
templateName = ((TemplateDelegateNode) template).getDelTemplateName();
}
builder.put(templateName, template);
}
}
return builder.build();
}
use of com.google.template.soy.soytree.TemplateBasicNode in project closure-templates by google.
the class AliasUtils method createTemplateAliases.
/**
* Creates a mapping for assigning and looking up the variable alias for templates both within a
* file and referenced from external files. For local files, the alias is just the local
* template's name. For external templates, the alias is an identifier that is unique for that
* template.
*
* <p>For V1 templates, no alias is generated and the template should be called by the fully
* qualified name.
*
* @param fileNode The {@link SoyFileNode} to create an alias mapping for.
* @return A {@link TemplateAliases} to look up aliases with.
*/
static TemplateAliases createTemplateAliases(SoyFileNode fileNode) {
Map<String, String> aliasMap = new HashMap<>();
Set<String> localTemplates = new HashSet<>();
int counter = 0;
// Go through templates first and just alias them to their local name.
for (TemplateBasicNode templateBasicNode : SoyTreeUtils.getAllNodesOfType(fileNode, TemplateBasicNode.class)) {
String partialName = templateBasicNode.getPartialTemplateName();
String fullyQualifiedName = templateBasicNode.getTemplateName();
localTemplates.add(fullyQualifiedName);
Preconditions.checkState(partialName != null, "Aliasing not supported for V1 templates");
// Need to start the alias with something that cannot be a part of a reserved
// JavaScript identifier like 'function' or 'catch'.
String alias = "$" + partialName.substring(1);
aliasMap.put(fullyQualifiedName, alias);
}
// Go through all call sites looking for foreign template calls and create an alias for them.
for (CallBasicNode callBasicNode : SoyTreeUtils.getAllNodesOfType(fileNode, CallBasicNode.class)) {
String fullyQualifiedName = callBasicNode.getCalleeName();
// to a local template.
if (localTemplates.contains(fullyQualifiedName) || aliasMap.containsKey(fullyQualifiedName)) {
continue;
}
String alias = TEMPLATE_ALIAS_PREFIX + (++counter);
aliasMap.put(fullyQualifiedName, alias);
}
return new Aliases(aliasMap);
}
use of com.google.template.soy.soytree.TemplateBasicNode in project closure-templates by google.
the class FindTransitiveDepTemplatesVisitor method visitCallBasicNode.
@Override
protected void visitCallBasicNode(CallBasicNode node) {
// Don't forget to visit content within CallParamContentNodes.
visitChildren(node);
TemplateBasicNode callee = templateRegistry.getBasicTemplate(node.getCalleeName());
// If the callee is null (i.e. not within the Soy file set), then this is an external call.
if (callee == null) {
return;
}
// Visit the callee template.
processCalleeHelper(callee);
}
use of com.google.template.soy.soytree.TemplateBasicNode in project closure-templates by google.
the class FindIndirectParamsVisitor method visitCallBasicNode.
@Override
protected void visitCallBasicNode(CallBasicNode node) {
// Don't forget to visit content within CallParamContentNodes.
visitChildren(node);
// We only want to recurse on calls that pass all data.
if (!node.isPassingAllData()) {
return;
}
TemplateBasicNode callee = templateRegistry.getBasicTemplate(node.getCalleeName());
// Soy file set.
if (callee == null) {
mayHaveIndirectParamsInExternalCalls = true;
return;
}
// Visit the callee template.
visitCalleeHelper(node, callee);
}
Aggregations