/** * Builds the list of SoyMsgParts for the given MsgPluralNode. * * @param msgPluralNode The plural node parsed from the Soy source. * @param msgNode The MsgNode containing 'msgPluralNode'. * @return A SoyMsgPluralPart. */ private static SoyMsgPluralPart buildMsgPartForPlural( MsgPluralNode msgPluralNode, MsgNode msgNode) { // This is the list of the cases. ImmutableList.Builder<SoyMsgPart.Case<SoyMsgPluralCaseSpec>> pluralCases = ImmutableList.builder(); for (CaseOrDefaultNode child : msgPluralNode.getChildren()) { ImmutableList<SoyMsgPart> caseMsgParts = buildMsgPartsForChildren((MsgBlockNode) child, msgNode); SoyMsgPluralCaseSpec caseSpec; if (child instanceof MsgPluralCaseNode) { caseSpec = new SoyMsgPluralCaseSpec(((MsgPluralCaseNode) child).getCaseNumber()); } else if (child instanceof MsgPluralDefaultNode) { caseSpec = new SoyMsgPluralCaseSpec(Type.OTHER); } else { throw new AssertionError("Unidentified node under a plural node."); } pluralCases.add(SoyMsgPart.Case.create(caseSpec, caseMsgParts)); } return new SoyMsgPluralPart( msgNode.getPluralVarName(msgPluralNode), msgPluralNode.getOffset(), pluralCases.build()); }
private SoyMsgPart compactPlural(SoyMsgPluralPart plural) { // Plural variable names tend to be repeated across templates, such as "count". return new SoyMsgPluralPart( intern(plural.getPluralVarName()), plural.getOffset(), compactCases(plural.getCases(), DEFAULT_PLURAL_CASE_SPEC)); }
private SoyMsgPart compactPlural(SoyMsgPluralPart plural) { // Plural variable names tend to be repeated across templates, such as "count". return new SoyMsgPluralPart( intern(plural.getPluralVarName()), plural.getOffset(), compactCases(plural.getCases(), DEFAULT_PLURAL_CASE_SPEC)); }
/** * Builds the list of SoyMsgParts for the given MsgPluralNode. * * @param msgPluralNode The plural node parsed from the Soy source. * @param msgNode The MsgNode containing 'msgPluralNode'. * @return A SoyMsgPluralPart. */ private static SoyMsgPluralPart buildMsgPartForPlural( MsgPluralNode msgPluralNode, MsgNode msgNode) { // This is the list of the cases. ImmutableList.Builder<SoyMsgPart.Case<SoyMsgPluralCaseSpec>> pluralCases = ImmutableList.builder(); for (CaseOrDefaultNode child : msgPluralNode.getChildren()) { ImmutableList<SoyMsgPart> caseMsgParts = buildMsgPartsForChildren(child, msgNode); SoyMsgPluralCaseSpec caseSpec; if (child instanceof MsgPluralCaseNode) { caseSpec = new SoyMsgPluralCaseSpec(((MsgPluralCaseNode) child).getCaseNumber()); } else if (child instanceof MsgPluralDefaultNode) { caseSpec = new SoyMsgPluralCaseSpec(Type.OTHER); } else { throw new AssertionError("Unidentified node under a plural node."); } pluralCases.add(SoyMsgPart.Case.create(caseSpec, caseMsgParts)); } return new SoyMsgPluralPart( msgNode.getPluralVarName(msgPluralNode), msgPluralNode.getOffset(), pluralCases.build()); }
/** * Builds the list of SoyMsgParts for the given MsgPluralNode. * @param msgPluralNode The plural node parsed from the Soy source. * @param msgNode The MsgNode containing 'msgPluralNode'. * @return A SoyMsgPluralPart. */ private static SoyMsgPluralPart buildMsgPartForPlural( MsgPluralNode msgPluralNode, MsgNode msgNode) { // This is the list of the cases. List<Pair<SoyMsgPluralCaseSpec, List<SoyMsgPart>>> pluralCases = Lists.newArrayList(); for (CaseOrDefaultNode child : msgPluralNode.getChildren()) { List<SoyMsgPart> caseMsgParts = buildMsgPartsForChildren(child, msgNode); SoyMsgPluralCaseSpec caseSpec; if (child instanceof MsgPluralCaseNode) { caseSpec = new SoyMsgPluralCaseSpec(((MsgPluralCaseNode) child).getCaseNumber()); } else if (child instanceof MsgPluralDefaultNode) { caseSpec = new SoyMsgPluralCaseSpec("other"); } else { throw new AssertionError("Unidentified node under a plural node."); } pluralCases.add(Pair.of(caseSpec, caseMsgParts)); } return new SoyMsgPluralPart( msgNode.getPluralVarName(msgPluralNode), msgPluralNode.getOffset(), pluralCases); }