1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 41 public class PrimitiveType extends Type { 42 43 57 public static class Code { 58 59 62 private String name; 63 64 73 Code(String name) { 74 this.name = name; 75 } 76 77 82 public String toString() { 83 return name; 84 } 85 } 86 87 88 public static final Code INT = new Code("int"); 90 public static final Code CHAR = new Code("char"); 92 public static final Code BOOLEAN = new Code("boolean"); 94 public static final Code SHORT = new Code("short"); 96 public static final Code LONG = new Code("long"); 98 public static final Code FLOAT = new Code("float"); 100 public static final Code DOUBLE = new Code("double"); 102 public static final Code BYTE = new Code("byte"); 104 108 public static final Code VOID = new Code("void"); 110 114 private PrimitiveType.Code typeCode = INT; 115 116 120 private static final Map CODES; 121 static { 122 CODES = new HashMap (20); 123 Code[] ops = { 124 INT, 125 BYTE, 126 CHAR, 127 BOOLEAN, 128 SHORT, 129 LONG, 130 FLOAT, 131 DOUBLE, 132 VOID, 133 }; 134 for (int i = 0; i < ops.length; i++) { 135 CODES.put(ops[i].toString(), ops[i]); 136 } 137 } 138 139 152 public static PrimitiveType.Code toCode(String token) { 153 return (PrimitiveType.Code) CODES.get(token); 154 } 155 156 160 public static final SimplePropertyDescriptor PRIMITIVE_TYPE_CODE_PROPERTY = 161 new SimplePropertyDescriptor(PrimitiveType.class, "primitiveTypeCode", PrimitiveType.Code.class, MANDATORY); 163 168 private static final List PROPERTY_DESCRIPTORS; 169 170 static { 171 List propertyList = new ArrayList (2); 172 createPropertyList(PrimitiveType.class, propertyList); 173 addProperty(PRIMITIVE_TYPE_CODE_PROPERTY, propertyList); 174 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); 175 } 176 177 188 public static List propertyDescriptors(int apiLevel) { 189 return PROPERTY_DESCRIPTORS; 190 } 191 192 201 PrimitiveType(AST ast) { 202 super(ast); 203 } 204 205 208 final List internalStructuralPropertiesForType(int apiLevel) { 209 return propertyDescriptors(apiLevel); 210 } 211 212 215 final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) { 216 if (property == PRIMITIVE_TYPE_CODE_PROPERTY) { 217 if (get) { 218 return getPrimitiveTypeCode(); 219 } else { 220 setPrimitiveTypeCode((Code) value); 221 return null; 222 } 223 } 224 return super.internalGetSetObjectProperty(property, get, value); 226 } 227 228 231 final int getNodeType0() { 232 return PRIMITIVE_TYPE; 233 } 234 235 238 ASTNode clone0(AST target) { 239 PrimitiveType result = new PrimitiveType(target); 240 result.setSourceRange(this.getStartPosition(), this.getLength()); 241 result.setPrimitiveTypeCode(getPrimitiveTypeCode()); 242 return result; 243 } 244 245 248 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 249 return matcher.match(this, other); 251 } 252 253 256 void accept0(ASTVisitor visitor) { 257 visitor.visit(this); 258 visitor.endVisit(this); 259 } 260 261 267 public PrimitiveType.Code getPrimitiveTypeCode() { 268 return this.typeCode; 269 } 270 271 278 public void setPrimitiveTypeCode(PrimitiveType.Code typeCode) { 279 if (typeCode == null) { 280 throw new IllegalArgumentException (); 281 } 282 preValueChange(PRIMITIVE_TYPE_CODE_PROPERTY); 283 this.typeCode = typeCode; 284 postValueChange(PRIMITIVE_TYPE_CODE_PROPERTY); 285 } 286 287 290 int memSize() { 291 return BASE_NODE_SIZE + 1 * 4; 293 } 294 295 298 int treeSize() { 299 return memSize(); 300 } 301 } 302 | Popular Tags |