KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > ejbql > ASTExactNumericLiteral


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * 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: 37459 $
29  */

30 public final class ASTExactNumericLiteral extends SimpleNode {
31    public long value;
32    public String JavaDoc literal;
33    private static final String JavaDoc LOFFER_L = "l";
34    private static final String JavaDoc UPPER_L = "L";
35    private static final String JavaDoc OX = "0X";
36    private static final String JavaDoc Ox = "0x";
37    private static final String JavaDoc ZERRO = "0";
38
39    public ASTExactNumericLiteral(int id) {
40       super(id);
41    }
42
43    public void setValue(String JavaDoc 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)).byteValue();
59             if(first >= 8) {
60                number = Ox + (first - 8) + number.substring(3);
61                value = Long.decode(number).longValue() - Long.MAX_VALUE - 1;
62                return;
63             }
64          }
65       } else if(number.startsWith(ZERRO)) { // octal
66
// handle literals
67
// from 01000000000000000000000L to 01777777777777777777777L
68
// remove sign bit, parse as positive, then calculate the
69
// negative value with the sign bit
70
if(number.length() == 23) {
71             if(number.charAt(1) == '1') {
72                number = ZERRO + number.substring(2);
73                value = Long.decode(number).longValue() - Long.MAX_VALUE - 1;
74                return;
75             }
76          }
77       }
78       value = Long.decode(number).longValue();
79    }
80
81    public String JavaDoc toString() {
82       return literal;
83    }
84    
85    /** Accept the visitor. **/
86    public Object JavaDoc jjtAccept(JBossQLParserVisitor visitor, Object JavaDoc data) {
87       return visitor.visit(this, data);
88    }
89 }
90
Popular Tags