1 11 package org.eclipse.jdt.internal.compiler.impl; 12 13 public class IntConstant extends Constant { 14 15 int value; 16 17 private static final IntConstant MINUS_FOUR = new IntConstant(-4); 18 private static final IntConstant MINUS_THREE = new IntConstant(-3); 19 private static final IntConstant MINUS_TWO = new IntConstant(-2); 20 private static final IntConstant MINUS_ONE = new IntConstant(-1); 21 private static final IntConstant ZERO = new IntConstant(0); 22 private static final IntConstant ONE = new IntConstant(1); 23 private static final IntConstant TWO = new IntConstant(2); 24 private static final IntConstant THREE = new IntConstant(3); 25 private static final IntConstant FOUR = new IntConstant(4); 26 private static final IntConstant FIVE = new IntConstant(5); 27 private static final IntConstant SIX = new IntConstant(6); 28 private static final IntConstant SEVEN = new IntConstant(7); 29 private static final IntConstant EIGHT= new IntConstant(8); 30 private static final IntConstant NINE = new IntConstant(9); 31 private static final IntConstant TEN = new IntConstant(10); 32 33 public static Constant fromValue(int value) { 34 35 switch (value) { 36 case -4 : return IntConstant.MINUS_FOUR; 37 case -3 : return IntConstant.MINUS_THREE; 38 case -2 : return IntConstant.MINUS_TWO; 39 case -1 : return IntConstant.MINUS_ONE; 40 case 0 : return IntConstant.ZERO; 41 case 1 : return IntConstant.ONE; 42 case 2 : return IntConstant.TWO; 43 case 3 : return IntConstant.THREE; 44 case 4 : return IntConstant.FOUR; 45 case 5 : return IntConstant.FIVE; 46 case 6 : return IntConstant.SIX; 47 case 7 : return IntConstant.SEVEN; 48 case 8 : return IntConstant.EIGHT; 49 case 9 : return IntConstant.NINE; 50 case 10 : return IntConstant.TEN; 51 } 52 return new IntConstant(value); 53 } 54 55 private IntConstant(int value) { 56 this.value = value; 57 } 58 59 public byte byteValue() { 60 return (byte) value; 61 } 62 63 public char charValue() { 64 return (char) value; 65 } 66 67 public double doubleValue() { 68 return value; } 70 71 public float floatValue() { 72 return value; } 74 75 public int intValue() { 76 return value; 77 } 78 79 public long longValue() { 80 return value; } 82 83 public short shortValue() { 84 return (short) value; 85 } 86 87 public String stringValue() { 88 return String.valueOf(this.value); 90 } 91 92 public String toString() { 93 return "(int)" + value; } 95 96 public int typeID() { 97 return T_int; 98 } 99 } 100 | Popular Tags |