1 package polyglot.types.reflect; 2 3 import java.io.*; 4 5 11 class Constant 12 { 13 int tag; 14 Object value; 15 16 23 static final byte CLASS = 7; 24 25 31 static final byte FIELD_REF = 9; 32 33 39 static final byte METHOD_REF = 10; 40 41 45 static final byte STRING = 8; 46 47 50 static final byte INTEGER = 3; 51 52 55 static final byte FLOAT = 4; 56 57 60 static final byte LONG = 5; 61 62 65 static final byte DOUBLE = 6; 66 67 72 static final byte INTERFACE_METHOD_REF = 11; 73 74 79 static final byte NAME_AND_TYPE = 12; 80 81 87 static final byte UTF8 = 1; 88 89 95 Constant(final int tag, final Object value) 96 { 97 this.tag = tag; 98 this.value = value; 99 } 100 101 107 final int tag() 108 { 109 return tag; 110 } 111 112 118 final Object value() 119 { 120 return value; 121 } 122 123 129 public int hashCode() 130 { 131 switch (tag) { 132 case CLASS: 133 case STRING: 134 case INTEGER: 135 case FLOAT: 136 case LONG: 137 case DOUBLE: 138 case UTF8: 139 return tag ^ value.hashCode(); 140 case FIELD_REF: 141 case METHOD_REF: 142 case INTERFACE_METHOD_REF: 143 case NAME_AND_TYPE: 144 return tag ^ ((int[]) value)[0] ^ ((int[]) value)[1]; 145 } 146 147 return tag; 148 } 149 150 158 public boolean equals(Object other) 159 { 160 if (! (other instanceof Constant)) { 161 return false; 162 } 163 164 Constant c = (Constant) other; 165 166 if (tag != c.tag) { 167 return false; 168 } 169 170 switch (tag) { 171 case CLASS: 172 case STRING: 173 case INTEGER: 174 case FLOAT: 175 case LONG: 176 case DOUBLE: 177 case UTF8: 178 return value.equals(c.value); 179 case FIELD_REF: 180 case METHOD_REF: 181 case INTERFACE_METHOD_REF: 182 case NAME_AND_TYPE: 183 return ((int[]) value)[0] == ((int[]) c.value)[0] && 184 ((int[]) value)[1] == ((int[]) c.value)[1]; 185 } 186 187 return false; 188 } 189 } 190 | Popular Tags |