001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.compiler.impl;
011:
012: public class IntConstant extends Constant {
013:
014: int value;
015:
016: private static final IntConstant MINUS_FOUR = new IntConstant(-4);
017: private static final IntConstant MINUS_THREE = new IntConstant(-3);
018: private static final IntConstant MINUS_TWO = new IntConstant(-2);
019: private static final IntConstant MINUS_ONE = new IntConstant(-1);
020: private static final IntConstant ZERO = new IntConstant(0);
021: private static final IntConstant ONE = new IntConstant(1);
022: private static final IntConstant TWO = new IntConstant(2);
023: private static final IntConstant THREE = new IntConstant(3);
024: private static final IntConstant FOUR = new IntConstant(4);
025: private static final IntConstant FIVE = new IntConstant(5);
026: private static final IntConstant SIX = new IntConstant(6);
027: private static final IntConstant SEVEN = new IntConstant(7);
028: private static final IntConstant EIGHT = new IntConstant(8);
029: private static final IntConstant NINE = new IntConstant(9);
030: private static final IntConstant TEN = new IntConstant(10);
031:
032: public static Constant fromValue(int value) {
033:
034: switch (value) {
035: case -4:
036: return IntConstant.MINUS_FOUR;
037: case -3:
038: return IntConstant.MINUS_THREE;
039: case -2:
040: return IntConstant.MINUS_TWO;
041: case -1:
042: return IntConstant.MINUS_ONE;
043: case 0:
044: return IntConstant.ZERO;
045: case 1:
046: return IntConstant.ONE;
047: case 2:
048: return IntConstant.TWO;
049: case 3:
050: return IntConstant.THREE;
051: case 4:
052: return IntConstant.FOUR;
053: case 5:
054: return IntConstant.FIVE;
055: case 6:
056: return IntConstant.SIX;
057: case 7:
058: return IntConstant.SEVEN;
059: case 8:
060: return IntConstant.EIGHT;
061: case 9:
062: return IntConstant.NINE;
063: case 10:
064: return IntConstant.TEN;
065: }
066: return new IntConstant(value);
067: }
068:
069: private IntConstant(int value) {
070: this .value = value;
071: }
072:
073: public byte byteValue() {
074: return (byte) value;
075: }
076:
077: public char charValue() {
078: return (char) value;
079: }
080:
081: public double doubleValue() {
082: return value; // implicit cast to return type
083: }
084:
085: public float floatValue() {
086: return value; // implicit cast to return type
087: }
088:
089: public int intValue() {
090: return value;
091: }
092:
093: public long longValue() {
094: return value; // implicit cast to return type
095: }
096:
097: public short shortValue() {
098: return (short) value;
099: }
100:
101: public String stringValue() {
102: //spec 15.17.11
103: return String.valueOf(this .value);
104: }
105:
106: public String toString() {
107: return "(int)" + value; //$NON-NLS-1$
108: }
109:
110: public int typeID() {
111: return T_int;
112: }
113: }
|