Search in sources :

Example 1 with Checkpoint

use of com.google.template.soy.error.ErrorReporter.Checkpoint in project closure-templates by google.

the class MsgHtmlTagNodeTest method parseMsgHtmlTagNode.

private static MsgHtmlTagNode parseMsgHtmlTagNode(String htmlTag, ErrorReporter errorReporter, String... params) {
    Checkpoint cp = errorReporter.checkpoint();
    ParseResult parse = SoyFileSetParserBuilder.forFileContents(Joiner.on('\n').join("{namespace ns}", "", "{template .t stricthtml=\"false\"}", Joiner.on('\n').join(params), "{msg desc=\"...\"}", htmlTag, "{/msg}", "{/template}")).errorReporter(errorReporter).parse();
    if (errorReporter.errorsSince(cp)) {
        return null;
    }
    MsgFallbackGroupNode child = (MsgFallbackGroupNode) parse.fileSet().getChild(0).getChild(0).getChild(0);
    return (MsgHtmlTagNode) ((MsgPlaceholderNode) child.getChild(0).getChild(0)).getChild(0);
}
Also used : Checkpoint(com.google.template.soy.error.ErrorReporter.Checkpoint) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult)

Example 2 with Checkpoint

use of com.google.template.soy.error.ErrorReporter.Checkpoint in project closure-templates by google.

the class RewriteGenderMsgsVisitor method visitMsgNode.

// -----------------------------------------------------------------------------------------------
// Implementations for specific nodes.
@Override
protected void visitMsgNode(MsgNode msg) {
    List<ExprRootNode> genderExprs = msg.getAndRemoveGenderExprs();
    if (genderExprs == null) {
        // not a msg that this pass should rewrite
        return;
    }
    // ------ Do the rewrite. ------
    // Note: We process the genders in reverse order so that the first listed gender will end up
    // being the outermost 'select' level.
    genderExprs = Lists.reverse(genderExprs);
    Checkpoint checkpoint = errorReporter.checkpoint();
    List<String> baseSelectVarNames = MsgSubstUnitBaseVarNameUtils.genNoncollidingBaseNamesForExprs(ExprRootNode.unwrap(genderExprs), FALLBACK_BASE_SELECT_VAR_NAME, errorReporter);
    if (errorReporter.errorsSince(checkpoint)) {
        // To prevent an IndexOutOfBoundsException below.
        return;
    }
    for (int i = 0; i < genderExprs.size(); i++) {
        ExprRootNode genderExpr = genderExprs.get(i);
        String baseSelectVarName = baseSelectVarNames.get(i);
        // and the new algorithm). If so, then there's no need to specify the baseSelectVarName.
        if (MsgSubstUnitBaseVarNameUtils.genNaiveBaseNameForExpr(genderExpr.getRoot(), FALLBACK_BASE_SELECT_VAR_NAME).equals(baseSelectVarName) && MsgSubstUnitBaseVarNameUtils.genShortestBaseNameForExpr(genderExpr.getRoot(), FALLBACK_BASE_SELECT_VAR_NAME).equals(baseSelectVarName)) {
            baseSelectVarName = null;
        }
        splitMsgForGender(msg, genderExpr, baseSelectVarName);
    }
    // ------ Verify from the re-written msg that gender restrictions are followed. ------
    checkExceedsMaxGenders((MsgSelectNode) msg.getChild(0), 1);
}
Also used : Checkpoint(com.google.template.soy.error.ErrorReporter.Checkpoint) Checkpoint(com.google.template.soy.error.ErrorReporter.Checkpoint) ExprRootNode(com.google.template.soy.exprtree.ExprRootNode)

Aggregations

Checkpoint (com.google.template.soy.error.ErrorReporter.Checkpoint)2 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1