Class JsMessageVisitor

    • Field Detail

      • MESSAGE_TREE_MALFORMED

        public static final DiagnosticType MESSAGE_TREE_MALFORMED
      • MESSAGE_NOT_INITIALIZED_CORRECTLY

        public static final DiagnosticType MESSAGE_NOT_INITIALIZED_CORRECTLY
      • 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.IdGenerator idGenerator)
        Creates JS message visitor.
        Parameters:
        compiler - the compiler instance
        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.
      • getExternalMessageId

        public static @Nullable java.lang.String getExternalMessageId​(java.lang.String messageKey)
        Extracts an external message ID from the message key, if it contains one.
        Parameters:
        messageKey - the message key (usually the variable or property name)
        Returns:
        the external ID if it is found, otherwise `null`
      • extractObjectLiteralMap

        public static JsMessageVisitor.ObjectLiteralMap extractObjectLiteralMap​(@Nullable Node objLit)
                                                                         throws com.google.javascript.jscomp.JsMessageVisitor.MalformedException
        Returns an object to represent an object literal Node from the AST.

        The object literal's members must all be `STRING_KEY` nodes.

        No duplicate string keys are allowed.

        A `null` argument is treated as if it were an empty object literal.

        Throws:
        com.google.javascript.jscomp.JsMessageVisitor.MalformedException - If the Node does not meet the above requirements.
      • 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
      • isScopedAliasesPrefix

        public static boolean isScopedAliasesPrefix​(java.lang.String name)
      • removeScopedAliasesPrefix

        public static java.lang.String removeScopedAliasesPrefix​(java.lang.String name)