| 1 | /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | * |
| 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 | |
| 7 | package org.mozilla.javascript.ast; |
| 8 | |
| 9 | import org.mozilla.javascript.Token; |
| 10 | |
| 11 | /** |
| 12 | * AST node representing an E4X {@code foo.(bar)} query expression. |
| 13 | * The node type (operator) is {@link Token#DOTQUERY}. |
| 14 | * Its {@code getLeft} node is the target ("foo" in the example), |
| 15 | * and the {@code getRight} node is the filter expression node.<p> |
| 16 | * |
| 17 | * This class exists separately from {@link InfixExpression} largely because it |
| 18 | * has different printing needs. The position of the left paren is just after |
| 19 | * the dot (operator) position, and the right paren is the final position in the |
| 20 | * bounds of the node. If the right paren is missing, the node ends at the end |
| 21 | * of the filter expression. |
| 22 | */ |
| 23 | public class XmlDotQuery extends InfixExpression { |
| 24 | |
| 25 | private int rp = -1; |
| 26 | |
| 27 | { |
| 28 | type = Token.DOTQUERY; |
| 29 | } |
| 30 | |
| 31 | public XmlDotQuery() { |
| 32 | } |
| 33 | |
| 34 | public XmlDotQuery(int pos) { |
| 35 | super(pos); |
| 36 | } |
| 37 | |
| 38 | public XmlDotQuery(int pos, int len) { |
| 39 | super(pos, len); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Returns right-paren position, -1 if missing.<p> |
| 44 | * |
| 45 | * Note that the left-paren is automatically the character |
| 46 | * immediately after the "." in the operator - no whitespace is |
| 47 | * permitted between the dot and lp by the scanner. |
| 48 | */ |
| 49 | public int getRp() { |
| 50 | return rp; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Sets right-paren position |
| 55 | */ |
| 56 | public void setRp(int rp) { |
| 57 | this.rp = rp; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String toSource(int depth) { |
| 62 | StringBuilder sb = new StringBuilder(); |
| 63 | sb.append(makeIndent(depth)); |
| 64 | sb.append(getLeft().toSource(0)); |
| 65 | sb.append(".("); |
| 66 | sb.append(getRight().toSource(0)); |
| 67 | sb.append(")"); |
| 68 | return sb.toString(); |
| 69 | } |
| 70 | } |