1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.jexl3.parser;
18
19 public final class ASTNumberLiteral extends JexlNode implements JexlNode.Constant<Number> {
20
21 /**
22 */
23 private static final long serialVersionUID = 1L;
24
25 /** The number parser. */
26 private final NumberParser nlp;
27
28 ASTNumberLiteral(final int id) {
29 super(id);
30 nlp = new NumberParser();
31 }
32
33 @Override
34 public Number getLiteral() {
35 return nlp.getLiteralValue();
36 }
37
38 public Class<? extends Number> getLiteralClass() {
39 return nlp.getLiteralClass();
40 }
41
42 @Override
43 protected boolean isConstant(final boolean literal) {
44 return true;
45 }
46
47 public boolean isInteger() {
48 return nlp.isInteger();
49 }
50
51 @Override
52 public Object jjtAccept(final ParserVisitor visitor, final Object data) {
53 return visitor.visit(this, data);
54 }
55
56 /**
57 * Sets this node as a natural literal.
58 * Originally from OGNL.
59 *
60 * @param s the natural as string
61 */
62 void setNatural(final String s) {
63 nlp.assignNatural(s);
64 }
65
66 /**
67 * Sets this node as a real literal.
68 * Originally from OGNL.
69 *
70 * @param s the real as string
71 */
72 void setReal(final String s) {
73 nlp.assignReal(s);
74 }
75
76 @Override
77 public String toString() {
78 return nlp.toString();
79 }
80 }