Search in sources :

Example 1 with SoyFileKind

use of com.google.template.soy.base.internal.SoyFileKind in project closure-templates by google.

the class StrictDepsVisitor method visitCallBasicNode.

// -----------------------------------------------------------------------------------------------
// Implementations for specific nodes.
// TODO(gboyer): Consider some deltemplate checking, but it's hard to make a coherent case for
// deltemplates since it's legitimate to have zero implementations, or to have the implementation
// in a different part of the dependency graph (if it's late-bound).
@Override
protected void visitCallBasicNode(CallBasicNode node) {
    TemplateNode callee = templateRegistry.getBasicTemplate(node.getCalleeName());
    if (callee == null) {
        String extraErrorMessage = SoyErrors.getDidYouMeanMessage(templateRegistry.getBasicTemplatesMap().keySet(), node.getCalleeName());
        errorReporter.report(node.getSourceLocation(), CALL_TO_UNDEFINED_TEMPLATE, node.getCalleeName(), extraErrorMessage);
    } else {
        SoyFileKind callerKind = node.getNearestAncestor(SoyFileNode.class).getSoyFileKind();
        SoyFileKind calleeKind = callee.getParent().getSoyFileKind();
        String callerFilePath = node.getSourceLocation().getFilePath();
        String calleeFilePath = callee.getSourceLocation().getFilePath();
        if (calleeKind == SoyFileKind.INDIRECT_DEP && callerKind == SoyFileKind.SRC) {
            errorReporter.report(node.getSourceLocation(), CALL_TO_INDIRECT_DEPENDENCY, calleeFilePath);
        }
        // should fail due to unknown template, but it doesn't hurt to add this.
        if (calleeKind == SoyFileKind.SRC && callerKind != SoyFileKind.SRC) {
            errorReporter.report(node.getSourceLocation(), CALL_FROM_DEP_TO_SRC, callee.getTemplateNameForUserMsgs(), calleeFilePath, callerFilePath);
        }
    }
    // Don't forget to visit content within CallParamContentNodes.
    visitChildren(node);
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) SoyFileKind(com.google.template.soy.base.internal.SoyFileKind) SoyFileNode(com.google.template.soy.soytree.SoyFileNode)

Aggregations

SoyFileKind (com.google.template.soy.base.internal.SoyFileKind)1 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)1 TemplateNode (com.google.template.soy.soytree.TemplateNode)1