Search in sources :

Example 1 with ValidatedLoggableElement

use of com.google.template.soy.logging.ValidatedLoggingConfig.ValidatedLoggableElement in project closure-templates by google.

the class VeLogValidationPass method validateNodeAgainstConfig.

/**
 * Type checks both expressions and assigns the {@link VeLogNode#getLoggingId()} field.
 */
private void validateNodeAgainstConfig(VeLogNode node) {
    ValidatedLoggableElement config = loggingConfig.getElement(node.getName().identifier());
    if (config == null) {
        reporter.report(node.getName().location(), NO_CONFIG_FOR_ELEMENT, SoyErrors.getDidYouMeanMessage(loggingConfig.allKnownIdentifiers(), node.getName().identifier()));
    } else {
        node.setLoggingId(config.getId());
        if (node.getConfigExpression() != null) {
            SoyType type = node.getConfigExpression().getType();
            Optional<String> protoName = config.getProtoName();
            if (!protoName.isPresent()) {
                reporter.report(node.getConfigExpression().getSourceLocation(), UNEXPECTED_CONFIG, node.getName().identifier());
            } else if (type.getKind() != Kind.ERROR && (type.getKind() != Kind.PROTO || !((SoyProtoType) type).getDescriptor().getFullName().equals(protoName.get()))) {
                reporter.report(node.getConfigExpression().getSourceLocation(), WRONG_TYPE, protoName.get(), type);
            }
        }
        if (node.getLogonlyExpression() != null) {
            SoyType type = node.getLogonlyExpression().getType();
            if (type.getKind() != Kind.BOOL) {
                reporter.report(node.getLogonlyExpression().getSourceLocation(), WRONG_TYPE, BoolType.getInstance(), type);
            }
        }
    }
}
Also used : SoyType(com.google.template.soy.types.SoyType) ValidatedLoggableElement(com.google.template.soy.logging.ValidatedLoggingConfig.ValidatedLoggableElement)

Aggregations

ValidatedLoggableElement (com.google.template.soy.logging.ValidatedLoggingConfig.ValidatedLoggableElement)1 SoyType (com.google.template.soy.types.SoyType)1