Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/PropertyGet.java

raw symbols SCIP
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 for the '.' operator. Node type is {@link Token#GETPROP}.
13 */
14 public class PropertyGet extends InfixExpression {
15
16 {
17 type = Token.GETPROP;
18 }
19
20 public PropertyGet() {
21 }
22
23 public PropertyGet(int pos) {
24 super(pos);
25 }
26
27 public PropertyGet(int pos, int len) {
28 super(pos, len);
29 }
30
31 public PropertyGet(int pos, int len, AstNode target, Name property) {
32 super(pos, len, target, property);
33 }
34
35 /**
36 * Constructor. Updates bounds to include left ({@code target}) and
37 * right ({@code property}) nodes.
38 */
39 public PropertyGet(AstNode target, Name property) {
40 super(target, property);
41 }
42
43 public PropertyGet(AstNode target, Name property, int dotPosition) {
44 super(Token.GETPROP, target, property, dotPosition);
45 }
46
47 /**
48 * Returns the object on which the property is being fetched.
49 * Should never be {@code null}.
50 */
51 public AstNode getTarget() {
52 return getLeft();
53 }
54
55 /**
56 * Sets target object, and sets its parent to this node.
57 * @param target expression evaluating to the object upon which
58 * to do the property lookup
59 * @throws IllegalArgumentException} if {@code target} is {@code null}
60 */
61 public void setTarget(AstNode target) {
62 setLeft(target);
63 }
64
65 /**
66 * Returns the property being accessed.
67 */
68 public Name getProperty() {
69 return (Name)getRight();
70 }
71
72 /**
73 * Sets the property being accessed, and sets its parent to this node.
74 * @throws IllegalArgumentException} if {@code property} is {@code null}
75 */
76 public void setProperty(Name property) {
77 setRight(property);
78 }
79
80 @Override
81 public String toSource(int depth) {
82 StringBuilder sb = new StringBuilder();
83 sb.append(makeIndent(depth));
84 sb.append(getLeft().toSource(0));
85 sb.append(".");
86 sb.append(getRight().toSource(0));
87 return sb.toString();
88 }
89
90 /**
91 * Visits this node, the target expression, and the property name.
92 */
93 @Override
94 public void visit(NodeVisitor v) {
95 if (v.visit(this)) {
96 getTarget().visit(v);
97 getProperty().visit(v);
98 }
99 }
100 }