public final class MsgSubstUnitBaseVarNameUtils extends Object
Important: Do not use outside of Soy code (treat as superpackage-private).
| Modifier and Type | Method and Description |
|---|---|
static String |
genNaiveBaseNameForExpr(ExprNode exprNode,
String fallbackBaseName)
Helper function to generate a base placeholder (or plural/select var) name from an expression,
using the naive algorithm.
|
static List<String> |
genNoncollidingBaseNamesForExprs(List<ExprNode> exprNodes,
String fallbackBaseName,
ErrorReporter errorReporter)
Generates base names for all the expressions in a list, where for each expression, we use the
shortest candidate base name that does not collide with any of the candidate base names
generated from other expressions in the list.
|
static String |
genShortestBaseNameForExpr(ExprNode exprNode,
String fallbackBaseName)
The equivalent of
genNaiveBaseNameForExpr() in our new algorithm for generating base
name. |
public static String genNaiveBaseNameForExpr(ExprNode exprNode, String fallbackBaseName)
If the expression is a data ref or global, then the last key (if any) is used as the base placeholder name. Otherwise, the fallback name is used.
Examples:
$aaaBbb -> AAA_BBB
$aaa_bbb -> AAA_BBB
$aaa.bbb -> BBB
$ij.aaa -> AAA
aaa.BBB -> BBB
$aaa.0 -> fallback
$aaa[0] -> fallback
$aaa[0].bbb -> BBB
length($aaa) -> fallback
$aaa + 1 -> fallback
exprNode - The root node for an expression.fallbackBaseName - The fallback base name.public static String genShortestBaseNameForExpr(ExprNode exprNode, String fallbackBaseName)
genNaiveBaseNameForExpr() in our new algorithm for generating base
name.
Examples:
$aaaBbb -> AAA_BBB
$aaa_bbb -> AAA_BBB
$aaa.bbb -> BBB
$ij.aaa -> AAA
aaa.BBB -> BBB
$aaa.0 -> AAA_0
$aaa[0] -> AAA_0
$aaa[0].bbb -> BBB
length($aaa) -> fallback
$aaa + 1 -> fallback
exprNode - The expr root of the expression to generate the shortest base name for.fallbackBaseName - The fallback base name to use if the given expression doesn't generate
any base names.public static List<String> genNoncollidingBaseNamesForExprs(List<ExprNode> exprNodes, String fallbackBaseName, ErrorReporter errorReporter)
For example, given the expressions $userGender and $target.gender, the generated base names would be USER_GENDER and TARGET_GENDER. (Even though the shortest candidate base names are USER_GENDER and GENDER, the latter one is not used since it collides with the former one.)
Note: We prefer the shorter candidate base names when possible, because the translator usually doesn't care about all the names. E.g. $data.actionTargets[0].personInfo.gender turns into GENDER as opposed to DATA_ACTION_TARGETS_0_PERSON_INFO_GENDER, which is overkill and probably more confusing. Another reason is that refactorings that change higher-level names should not change messages unnecessarily. E.g. a refactoring that changes $data.actionTargets[0].personInfo.gender -> $userData.actionTargets[0].personInfo.gender should not change the placeholder name.
exprNodes - The expr nodes of the expressions to generate noncolliding base names for.fallbackBaseName - The fallback base name.errorReporter - For reporting collision errors.