private SoyMsgPart compactSelect(SoyMsgSelectPart select) { // TODO: Turn into a non-select message if there's only one unique case. // Select variable names tend to be repeated across many templates, like "gender". return new SoyMsgSelectPart( intern(select.getSelectVarName()), compactCases(select.getCases(), DEFAULT_SELECT_CASE_SPEC)); }
/** Brings a message back to life from only its ID and parts. */ @SuppressWarnings("unchecked") // The constructor guarantees the type of ImmutableList. private SoyMsg resurrectMsg(long id, ImmutableList<SoyMsgPart> parts) { return SoyMsg.builder() .setId(id) .setLocaleString(localeString) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .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)); }
/** * Appends the text representation of a plural part to a StringBuilder. * @param stringBuilder The StringBuilder to append to. * @param soyMsgPluralPart The SoyMsgPluralPart to add. * @param doUseBracedPhs Whether to use braced placeholders. */ private static void appendPluralToStringBuilder( StringBuilder stringBuilder, SoyMsgPluralPart soyMsgPluralPart, boolean doUseBracedPhs) { stringBuilder.append(IcuSyntaxUtils.getPluralOpenString( soyMsgPluralPart.getPluralVarName(), soyMsgPluralPart.getOffset())); for (Pair<SoyMsgPluralCaseSpec, List<SoyMsgPart>> pluralCase : soyMsgPluralPart.getCases()) { SoyMsgPluralCaseSpec pluralCaseSpec = pluralCase.first; stringBuilder.append(IcuSyntaxUtils.getPluralCaseOpenString( pluralCaseSpec.getType() == SoyMsgPluralCaseSpec.Type.OTHER ? null : pluralCaseSpec.getExplicitValue())); appendMsgPartsToTcStringBuilder(stringBuilder, pluralCase.second, doUseBracedPhs); stringBuilder.append(IcuSyntaxUtils.getPluralCaseCloseString()); } stringBuilder.append(IcuSyntaxUtils.getPluralCloseString()); }
/** * Appends the text representation of a select part to a StringBuilder. * @param stringBuilder The StringBuilder to append to. * @param soyMsgSelectPart The SoyMsgSelectPart to add. * @param doUseBracedPhs Whether to use braced placeholders. */ private static void appendSelectToStringBuilder( StringBuilder stringBuilder, SoyMsgSelectPart soyMsgSelectPart, boolean doUseBracedPhs) { stringBuilder.append(IcuSyntaxUtils.getSelectOpenString(soyMsgSelectPart.getSelectVarName())); for (Pair<String, List<SoyMsgPart>> oneSelectCase : soyMsgSelectPart.getCases()) { stringBuilder.append(IcuSyntaxUtils.getSelectCaseOpenString(oneSelectCase.first)); appendMsgPartsToTcStringBuilder(stringBuilder, oneSelectCase.second, doUseBracedPhs); stringBuilder.append(IcuSyntaxUtils.getSelectCaseCloseString()); } stringBuilder.append(IcuSyntaxUtils.getSelectCloseString()); }
private SoyMsgPart compactPlaceholder(SoyMsgPlaceholderPart part) { return new SoyMsgPlaceholderPart( intern(part.getPlaceholderName()), /* placeholderExample=*/ null); }
/** * Gets the opening (left) string for a plural case statement. * * @param pluralCaseSpec The plural case spec object. * @return the ICU syntax string for the plural case opening string. */ private static String getPluralCaseOpenString(SoyMsgPluralCaseSpec pluralCaseSpec) { String icuCaseName = (pluralCaseSpec.getType() == SoyMsgPluralCaseSpec.Type.EXPLICIT) ? "=" + pluralCaseSpec.getExplicitValue() : pluralCaseSpec.getType().name().toLowerCase(); return icuCaseName + "{"; }
/** * Compacts a single message part. * * <p>If the part is a plural/select part, it might be expanded into multiple parts. */ private SoyMsgPart compactPart(SoyMsgPart part) { if (part instanceof SoyMsgPluralPart) { part = compactPlural((SoyMsgPluralPart) part); } else if (part instanceof SoyMsgSelectPart) { part = compactSelect((SoyMsgSelectPart) part); } else if (part instanceof SoyMsgPlaceholderPart) { part = compactPlaceholder((SoyMsgPlaceholderPart) part); } // Now intern the message part. return intern(part); }
@Override public final String toString() { return getRawText(); }
public SoyMsg build() { SoyMsg msg = new AutoValue_SoyMsg( localeString, id, altId, meaning, desc, isHidden, contentType, isPlrselMsg, parts); if (sourceLocation != null) { msg.addSourceLocation(sourceLocation); } return msg; } }
/** * Returns a possibly canonicalized version of the input. This causes a permanent reference to the * input. */ private <T> T intern(T input) { return interner.intern(input); } }
/** Returns a new builder for {@link SoyMsg}. */ public static Builder builder() { return new Builder(); }
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 compactSelect(SoyMsgSelectPart select) { // TODO: Turn into a non-select message if there's only one unique case. // Select variable names tend to be repeated across many templates, like "gender". return new SoyMsgSelectPart( intern(select.getSelectVarName()), compactCases(select.getCases(), DEFAULT_SELECT_CASE_SPEC)); }
/** Brings a message back to life from only its ID and parts. */ @SuppressWarnings("unchecked") // The constructor guarantees the type of ImmutableList. private SoyMsg resurrectMsg(long id, ImmutableList<SoyMsgPart> parts) { return SoyMsg.builder() .setId(id) .setLocaleString(localeString) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build(); }
private SoyMsgPart compactPlaceholder(SoyMsgPlaceholderPart part) { return new SoyMsgPlaceholderPart( intern(part.getPlaceholderName()), /* placeholderExample=*/ null); }
/** * Gets the opening (left) string for a plural case statement. * * @param pluralCaseSpec The plural case spec object. * @return the ICU syntax string for the plural case opening string. */ private static String getPluralCaseOpenString(SoyMsgPluralCaseSpec pluralCaseSpec) { String icuCaseName = (pluralCaseSpec.getType() == SoyMsgPluralCaseSpec.Type.EXPLICIT) ? "=" + pluralCaseSpec.getExplicitValue() : pluralCaseSpec.getType().name().toLowerCase(); return icuCaseName + "{"; }
@Override public final String toString() { return getRawText(); }
/** * Returns a possibly canonicalized version of the input. This causes a permanent reference to the * input. */ private <T> T intern(T input) { return interner.intern(input); } }
/** Returns a new builder for {@link SoyMsg}. */ public static Builder builder() { return new Builder(); }