01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.ejb.plugins.cmp.ejbql;
23:
24: /**
25: * This abstract syntax node represents an exact numeric literal.
26: *
27: * @author <a href="mailto:dain@daingroup.com">Dain Sundstrom</a>
28: * @version $Revision: 57209 $
29: */
30: public final class ASTExactNumericLiteral extends SimpleNode {
31: public long value;
32: public String literal;
33: private static final String LOFFER_L = "l";
34: private static final String UPPER_L = "L";
35: private static final String OX = "0X";
36: private static final String Ox = "0x";
37: private static final String ZERRO = "0";
38:
39: public ASTExactNumericLiteral(int id) {
40: super (id);
41: }
42:
43: public void setValue(String number) {
44: literal = number;
45:
46: // long suffix
47: if (number.endsWith(LOFFER_L) || number.endsWith(UPPER_L)) {
48: // chop off the suffix
49: number = number.substring(0, number.length() - 1);
50: }
51:
52: // hex
53: if (number.startsWith(OX) || number.startsWith(Ox)) {
54: // handle literals from 0x8000000000000000L to 0xffffffffffffffffL:
55: // remove sign bit, parse as positive, then calculate the negative
56: // value with the sign bit
57: if (number.length() == 18) {
58: byte first = Byte.decode(number.substring(0, 3))
59: .byteValue();
60: if (first >= 8) {
61: number = Ox + (first - 8) + number.substring(3);
62: value = Long.decode(number).longValue()
63: - Long.MAX_VALUE - 1;
64: return;
65: }
66: }
67: } else if (number.startsWith(ZERRO)) { // octal
68: // handle literals
69: // from 01000000000000000000000L to 01777777777777777777777L
70: // remove sign bit, parse as positive, then calculate the
71: // negative value with the sign bit
72: if (number.length() == 23) {
73: if (number.charAt(1) == '1') {
74: number = ZERRO + number.substring(2);
75: value = Long.decode(number).longValue()
76: - Long.MAX_VALUE - 1;
77: return;
78: }
79: }
80: }
81: value = Long.decode(number).longValue();
82: }
83:
84: public String toString() {
85: return literal;
86: }
87:
88: /** Accept the visitor. **/
89: public Object jjtAccept(JBossQLParserVisitor visitor, Object data) {
90: return visitor.visit(this, data);
91: }
92: }
|