Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/NumberLiteral.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 a Number literal. Node type is {@link Token#NUMBER}.<p>
13 */
14 public class NumberLiteral extends AstNode {
15
16 private String value;
17 private double number;
18
19 {
20 type = Token.NUMBER;
21 }
22
23 public NumberLiteral() {
24 }
25
26 public NumberLiteral(int pos) {
27 super(pos);
28 }
29
30 public NumberLiteral(int pos, int len) {
31 super(pos, len);
32 }
33
34 /**
35 * Constructor. Sets the length to the length of the {@code value} string.
36 */
37 public NumberLiteral(int pos, String value) {
38 super(pos);
39 setValue(value);
40 setLength(value.length());
41 }
42
43 /**
44 * Constructor. Sets the length to the length of the {@code value} string.
45 */
46 public NumberLiteral(int pos, String value, double number) {
47 this(pos, value);
48 setDouble(number);
49 }
50
51 public NumberLiteral(double number) {
52 setDouble(number);
53 setValue(Double.toString(number));
54 }
55
56 /**
57 * Returns the node's string value (the original source token)
58 */
59 public String getValue() {
60 return value;
61 }
62
63 /**
64 * Sets the node's value
65 * @throws IllegalArgumentException} if value is {@code null}
66 */
67 public void setValue(String value) {
68 assertNotNull(value);
69 this.value = value;
70 }
71
72 /**
73 * Gets the {@code double} value.
74 */
75 public double getNumber() {
76 return number;
77 }
78
79 /**
80 * Sets the node's {@code double} value.
81 */
82 public void setNumber(double value) {
83 number = value;
84 }
85
86 @Override
87 public String toSource(int depth) {
88 return makeIndent(depth) + (value == null ? "<null>" : value);
89 }
90
91 /**
92 * Visits this node. There are no children to visit.
93 */
94 @Override
95 public void visit(NodeVisitor v) {
96 v.visit(this);
97 }
98 }