コード例 #1
0
 /** Finds the first matching qualified name node in post-traversal order. */
 protected final Node findQualifiedNameNode(final String name, Node root) {
   final List<Node> matches = Lists.newArrayList();
   NodeUtil.visitPostOrder(
       root,
       new NodeUtil.Visitor() {
         @Override
         public void visit(Node n) {
           if (name.equals(n.getQualifiedName())) {
             matches.add(n);
           }
         }
       },
       Predicates.<Node>alwaysTrue());
   return matches.get(0);
 }
コード例 #2
0
 /** Switches all "this.$.foo" to "this.$['foo']". */
 private void switchDollarSignPropsToBrackets(Node objLit) {
   Preconditions.checkState(objLit.isObjectLit());
   for (Node keyNode : objLit.children()) {
     Node value = keyNode.getFirstChild();
     if (value != null && value.isFunction()) {
       NodeUtil.visitPostOrder(
           value.getLastChild(),
           new NodeUtil.Visitor() {
             @Override
             public void visit(Node n) {
               if (n.isString()
                   && n.getString().equals("$")
                   && n.getParent().isGetProp()
                   && n.getParent().getParent().isGetProp()) {
                 Node dollarChildProp = n.getParent().getParent();
                 dollarChildProp.setType(Token.GETELEM);
                 compiler.reportCodeChange();
               }
             }
           },
           Predicates.<Node>alwaysTrue());
     }
   }
 }