Class JsMessageVisitor

    • Constructor Detail

      • JsMessageVisitor

        protected JsMessageVisitor​(AbstractCompiler compiler,
                                   boolean needToCheckDuplications,
                                   JsMessage.Style style,
                                   JsMessage.IdGenerator idGenerator)
        Creates JS message visitor.
        Parameters:
        compiler - the compiler instance
        needToCheckDuplications - whether to check duplicated messages in traversed
        style - style that should be used during parsing
        idGenerator - 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 interface CompilerPass
        Parameters:
        externs - Top of external JS tree
        root - 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 iff NodeTraversal.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 interface NodeTraversal.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:
        1. extract all JS messages
        2. replace JS messages with localized versions for some specific language
        3. check that messages have correct syntax and present in localization bundle
        Parameters:
        message - the found message
        definition - the definition of the object and usually contains all additional message information like message node/parent's node
      • checkNode

        protected void checkNode​(@Nullable
                                 Node node,
                                 Token type)
                          throws com.google.javascript.jscomp.JsMessageVisitor.MalformedException
        Checks a node's type.
        Throws:
        com.google.javascript.jscomp.JsMessageVisitor.MalformedException - if the node is null or the wrong type