Package com.google.javascript.jscomp
Class JsMessageVisitor
- java.lang.Object
-
- com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback
-
- com.google.javascript.jscomp.JsMessageVisitor
-
- All Implemented Interfaces:
CompilerPass
,NodeTraversal.Callback
@GwtIncompatible("JsMessage, java.util.regex") public abstract class JsMessageVisitor extends NodeTraversal.AbstractPostOrderCallback implements CompilerPass
Traverses across parsed tree and finds I18N messages. Then it passes it toprocessJsMessage(JsMessage, JsMessageDefinition)
.
-
-
Field Summary
Fields Modifier and Type Field Description static DiagnosticType
BAD_FALLBACK_SYNTAX
static DiagnosticType
FALLBACK_ARG_ERROR
static DiagnosticType
MESSAGE_NOT_INITIALIZED_USING_NEW_SYNTAX
static DiagnosticType
MESSAGE_TREE_MALFORMED
-
Constructor Summary
Constructors Modifier Constructor Description protected
JsMessageVisitor(AbstractCompiler compiler, JsMessage.Style style, JsMessage.IdGenerator idGenerator)
Creates JS message visitor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
checkNode(Node node, Token type)
Checks a node's type.void
process(Node externs, Node root)
Process the JS with root node root.protected abstract void
processJsMessage(JsMessage message, JsMessageDefinition definition)
Processes found JS message.void
visit(NodeTraversal traversal, Node node, Node unused)
Visits a node in postorder (after its children).-
Methods inherited from class com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback
shouldTraverse
-
-
-
-
Field Detail
-
MESSAGE_TREE_MALFORMED
public static final DiagnosticType MESSAGE_TREE_MALFORMED
-
MESSAGE_NOT_INITIALIZED_USING_NEW_SYNTAX
public static final DiagnosticType MESSAGE_NOT_INITIALIZED_USING_NEW_SYNTAX
-
BAD_FALLBACK_SYNTAX
public static final DiagnosticType BAD_FALLBACK_SYNTAX
-
FALLBACK_ARG_ERROR
public static final DiagnosticType FALLBACK_ARG_ERROR
-
-
Constructor Detail
-
JsMessageVisitor
protected JsMessageVisitor(AbstractCompiler compiler, JsMessage.Style style, JsMessage.IdGenerator idGenerator)
Creates JS message visitor.- Parameters:
compiler
- the compiler instancestyle
- style that should be used during parsingidGenerator
- generator that used for creating unique ID for the message
-
-
Method Detail
-
process
public void process(Node externs, Node root)
Description copied from interface:CompilerPass
Process the JS with root node root. Can modify the contents of each Node tree- Specified by:
process
in interfaceCompilerPass
- Parameters:
externs
- Top of external JS treeroot
- Top of JS tree
-
visit
public void visit(NodeTraversal traversal, Node node, Node unused)
Description copied from interface:NodeTraversal.Callback
Visits a node in postorder (after its children). A node is visited in postorder iffNodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
returned true for its parent. In particular, the root node is never visited in postorder.Siblings are always visited left-to-right.
Implementations can have side-effects (e.g. modify the parse tree). Removing the current node is legal, but removing or reordering nodes above the current node may cause nodes to be visited twice or not at all.
- Specified by:
visit
in interfaceNodeTraversal.Callback
- Parameters:
traversal
- The current traversal.node
- The current node.unused
- The parent of the current node.
-
processJsMessage
protected abstract void processJsMessage(JsMessage message, JsMessageDefinition definition)
Processes found JS message. Several examples of "standard" processing routines are:- extract all JS messages
- replace JS messages with localized versions for some specific language
- check that messages have correct syntax and present in localization bundle
- Parameters:
message
- the found messagedefinition
- the definition of the object and usually contains all additional message information like message node/parent's node
-
-