@GwtIncompatible(value="JsMessage") final class ReplaceMessages extends JsMessageVisitor
JsMessageVisitor.MalformedException
Modifier and Type | Field and Description |
---|---|
private MessageBundle |
bundle |
(package private) static DiagnosticType |
BUNDLE_DOES_NOT_HAVE_THE_MESSAGE |
private boolean |
strictReplacement |
BAD_FALLBACK_SYNTAX, compiler, FALLBACK_ARG_ERROR, HIDDEN_DESC_PREFIX, MESSAGE_DUPLICATE_KEY, MESSAGE_HAS_NO_DESCRIPTION, MESSAGE_HAS_NO_TEXT, MESSAGE_HAS_NO_VALUE, MESSAGE_NODE_IS_ORPHANED, MESSAGE_NOT_INITIALIZED_USING_NEW_SYNTAX, MESSAGE_TREE_MALFORMED, MSG_PREFIX
Constructor and Description |
---|
ReplaceMessages(AbstractCompiler compiler,
MessageBundle bundle,
boolean checkDuplicatedMessages,
JsMessage.Style style,
boolean strictReplacement) |
Modifier and Type | Method and Description |
---|---|
private static void |
checkStringExprNode(Node node)
Checks that a node is a valid string expression (either a string literal
or a concatenation of string literals).
|
private static Node |
constructAddOrStringNode(java.util.Iterator<java.lang.CharSequence> partsIterator,
Node argListNode)
Creates a parse tree corresponding to the remaining message parts in
an iteration.
|
private static Node |
constructStringExprNode(java.util.Iterator<java.lang.CharSequence> parts,
Node objLitNode,
Node refNode)
Creates a parse tree corresponding to the remaining message parts in an
iteration.
|
private Node |
getNewValueNode(JsMessage message,
Node origValueNode)
Constructs a node representing a message's value, or, if possible, just
modifies
origValueNode so that it accurately represents the
message's value. |
protected void |
processJsMessage(JsMessage message,
JsMessageDefinition definition)
Processes found JS message.
|
(package private) void |
processMessageFallback(Node callNode,
JsMessage message1,
JsMessage message2)
Processes the goog.getMsgWithFallback primitive.
|
private Node |
replaceCallNode(JsMessage message,
Node callNode)
Replaces a CALL node with an inlined message value.
|
private void |
updateFunctionNode(JsMessage message,
Node functionNode)
Updates the descendants of a FUNCTION node to represent a message's value.
|
checkNode, isLowerCamelCaseWithNumericSuffixes, isMessageName, process, toLowerCamelCaseWithNumericSuffixes, visit
shouldTraverse
private final MessageBundle bundle
private final boolean strictReplacement
static final DiagnosticType BUNDLE_DOES_NOT_HAVE_THE_MESSAGE
ReplaceMessages(AbstractCompiler compiler, MessageBundle bundle, boolean checkDuplicatedMessages, JsMessage.Style style, boolean strictReplacement)
void processMessageFallback(Node callNode, JsMessage message1, JsMessage message2)
JsMessageVisitor
processMessageFallback
in class JsMessageVisitor
protected void processJsMessage(JsMessage message, JsMessageDefinition definition)
JsMessageVisitor
processJsMessage
in class JsMessageVisitor
message
- the found messagedefinition
- the definition of the object and usually contains all
additional message information like message node/parent's nodeprivate Node getNewValueNode(JsMessage message, Node origValueNode) throws JsMessageVisitor.MalformedException
origValueNode
so that it accurately represents the
message's value.message
- a messageorigValueNode
- the message's original value nodeorigValueNode
MalformedException
- if the passed node's subtree structure is
not as expectedJsMessageVisitor.MalformedException
private void updateFunctionNode(JsMessage message, Node functionNode) throws JsMessageVisitor.MalformedException
The tree looks something like:
function |-- name |-- lp | |-- name| -- name -- block | --return | --add |-- string foo -- name
message
- a messagefunctionNode
- the message's original FUNCTION value nodeMalformedException
- if the passed node's subtree structure is
not as expectedJsMessageVisitor.MalformedException
private static Node constructAddOrStringNode(java.util.Iterator<java.lang.CharSequence> partsIterator, Node argListNode) throws JsMessageVisitor.MalformedException
partsIterator
- an iterator over message partsargListNode
- an LP node whose children are valid placeholder namesMalformedException
- if partsIterator
contains a
placeholder reference that does not correspond to a valid argument in
the arg listJsMessageVisitor.MalformedException
private Node replaceCallNode(JsMessage message, Node callNode) throws JsMessageVisitor.MalformedException
The call tree looks something like:
call |-- getprop | |-- name 'goog' | +-- string 'getMsg' | |-- string 'Hi {$userName}! Welcome to {$product}.' +-- objlit |-- string 'userName' |-- name 'someUserName' |-- string 'product' +-- call +-- name 'getProductName'For that example, we'd return:
add |-- string 'Hi ' +-- add |-- name someUserName +-- add |-- string '! Welcome to ' +-- add |-- call | +-- name 'getProductName' +-- string '.'
message
- a messagecallNode
- the message's original CALL value nodeMalformedException
- if the passed node's subtree structure is
not as expectedJsMessageVisitor.MalformedException
private static Node constructStringExprNode(java.util.Iterator<java.lang.CharSequence> parts, Node objLitNode, Node refNode) throws JsMessageVisitor.MalformedException
parts
- an iterator over message partsobjLitNode
- an OBJLIT node mapping placeholder names to valuesMalformedException
- if parts
contains a placeholder
reference that does not correspond to a valid placeholder nameJsMessageVisitor.MalformedException
private static void checkStringExprNode(@Nullable Node node)
java.lang.IllegalArgumentException
- if the node is null or the wrong type