1 11 package org.eclipse.jdt.core.dom; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 44 public final class Modifier extends ASTNode implements IExtendedModifier { 45 46 50 public static class ModifierKeyword { 51 52 53 public static final ModifierKeyword ABSTRACT_KEYWORD = new ModifierKeyword("abstract", ABSTRACT); 55 56 public static final ModifierKeyword FINAL_KEYWORD = new ModifierKeyword("final", FINAL); 58 62 private static final Map KEYWORDS; 63 64 65 public static final ModifierKeyword NATIVE_KEYWORD = new ModifierKeyword("native", NATIVE); 67 68 public static final ModifierKeyword PRIVATE_KEYWORD = new ModifierKeyword("private", PRIVATE); 70 71 public static final ModifierKeyword PROTECTED_KEYWORD = new ModifierKeyword("protected", PROTECTED); 73 74 public static final ModifierKeyword PUBLIC_KEYWORD = new ModifierKeyword("public", PUBLIC); 76 77 public static final ModifierKeyword STATIC_KEYWORD = new ModifierKeyword("static", STATIC); 79 80 public static final ModifierKeyword STRICTFP_KEYWORD = new ModifierKeyword("strictfp", STRICTFP); 82 83 public static final ModifierKeyword SYNCHRONIZED_KEYWORD = new ModifierKeyword("synchronized", SYNCHRONIZED); 85 86 public static final ModifierKeyword TRANSIENT_KEYWORD = new ModifierKeyword("transient", TRANSIENT); 88 89 public static final ModifierKeyword VOLATILE_KEYWORD = new ModifierKeyword("volatile", VOLATILE); static { 91 KEYWORDS = new HashMap (20); 92 ModifierKeyword[] ops = { 93 PUBLIC_KEYWORD, 94 PROTECTED_KEYWORD, 95 PRIVATE_KEYWORD, 96 STATIC_KEYWORD, 97 ABSTRACT_KEYWORD, 98 FINAL_KEYWORD, 99 NATIVE_KEYWORD, 100 SYNCHRONIZED_KEYWORD, 101 TRANSIENT_KEYWORD, 102 VOLATILE_KEYWORD, 103 STRICTFP_KEYWORD 104 }; 105 for (int i = 0; i < ops.length; i++) { 106 KEYWORDS.put(ops[i].toString(), ops[i]); 107 } 108 } 109 110 123 public static ModifierKeyword fromFlagValue(int flagValue) { 124 for (Iterator it = KEYWORDS.values().iterator(); it.hasNext(); ) { 125 ModifierKeyword k = (ModifierKeyword) it.next(); 126 if (k.toFlagValue() == flagValue) { 127 return k; 128 } 129 } 130 return null; 131 } 132 133 146 public static ModifierKeyword toKeyword(String keyword) { 147 return (ModifierKeyword) KEYWORDS.get(keyword); 148 } 149 150 153 private int flagValue; 154 155 158 private String keyword; 159 160 170 private ModifierKeyword(String keyword, int flagValue) { 171 this.keyword = keyword; 172 this.flagValue = flagValue; 173 } 174 175 182 public int toFlagValue() { 183 return this.flagValue; 184 } 185 186 192 public String toString() { 193 return this.keyword; 194 } 195 } 196 197 202 public static final int ABSTRACT = 0x0400; 203 204 209 public static final int FINAL = 0x0010; 210 211 215 public static final SimplePropertyDescriptor KEYWORD_PROPERTY = 216 new SimplePropertyDescriptor(Modifier.class, "keyword", Modifier.ModifierKeyword.class, MANDATORY); 218 223 public static final int NATIVE = 0x0100; 224 225 229 public static final int NONE = 0x0000; 230 231 236 public static final int PRIVATE = 0x0002; 237 238 243 private static final List PROPERTY_DESCRIPTORS; 244 245 250 public static final int PROTECTED = 0x0004; 251 252 257 public static final int PUBLIC = 0x0001; 258 259 264 public static final int STATIC = 0x0008; 265 266 271 public static final int STRICTFP = 0x0800; 272 273 278 public static final int SYNCHRONIZED = 0x0020; 279 280 285 public static final int TRANSIENT = 0x0080; 286 287 292 public static final int VOLATILE = 0x0040; 293 294 static { 295 List properyList = new ArrayList (2); 296 createPropertyList(Modifier.class, properyList); 297 addProperty(KEYWORD_PROPERTY, properyList); 298 PROPERTY_DESCRIPTORS = reapPropertyList(properyList); 299 } 300 301 310 public static boolean isAbstract(int flags) { 311 return (flags & ABSTRACT) != 0; 312 } 313 314 323 public static boolean isFinal(int flags) { 324 return (flags & FINAL) != 0; 325 } 326 327 336 public static boolean isNative(int flags) { 337 return (flags & NATIVE) != 0; 338 } 339 340 349 public static boolean isPrivate(int flags) { 350 return (flags & PRIVATE) != 0; 351 } 352 353 362 public static boolean isProtected(int flags) { 363 return (flags & PROTECTED) != 0; 364 } 365 366 375 public static boolean isPublic(int flags) { 376 return (flags & PUBLIC) != 0; 377 } 378 379 388 public static boolean isStatic(int flags) { 389 return (flags & STATIC) != 0; 390 } 391 392 401 public static boolean isStrictfp(int flags) { 402 return (flags & STRICTFP) != 0; 403 } 404 405 414 public static boolean isSynchronized(int flags) { 415 return (flags & SYNCHRONIZED) != 0; 416 } 417 418 427 public static boolean isTransient(int flags) { 428 return (flags & TRANSIENT) != 0; 429 } 430 431 440 public static boolean isVolatile(int flags) { 441 return (flags & VOLATILE) != 0; 442 } 443 444 455 public static List propertyDescriptors(int apiLevel) { 456 return PROPERTY_DESCRIPTORS; 457 } 458 459 463 private ModifierKeyword modifierKeyword = ModifierKeyword.PUBLIC_KEYWORD; 464 465 475 Modifier(AST ast) { 476 super(ast); 477 unsupportedIn2(); 478 } 479 480 484 void accept0(ASTVisitor visitor) { 485 visitor.visit(this); 486 visitor.endVisit(this); 487 } 488 489 493 ASTNode clone0(AST target) { 494 Modifier result = new Modifier(target); 495 result.setSourceRange(this.getStartPosition(), this.getLength()); 496 result.setKeyword(getKeyword()); 497 return result; 498 } 499 500 506 public ModifierKeyword getKeyword() { 507 return this.modifierKeyword; 508 } 509 510 514 final int getNodeType0() { 515 return MODIFIER; 516 } 517 518 521 final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) { 522 if (property == KEYWORD_PROPERTY) { 523 if (get) { 524 return getKeyword(); 525 } else { 526 setKeyword((ModifierKeyword) value); 527 return null; 528 } 529 } 530 return super.internalGetSetObjectProperty(property, get, value); 532 } 533 534 537 final List internalStructuralPropertiesForType(int apiLevel) { 538 return propertyDescriptors(apiLevel); 539 } 540 541 547 public boolean isAbstract() { 548 return this.modifierKeyword == ModifierKeyword.ABSTRACT_KEYWORD; 549 } 550 551 554 public boolean isAnnotation() { 555 return false; 556 } 557 558 564 public boolean isFinal() { 565 return this.modifierKeyword == ModifierKeyword.FINAL_KEYWORD; 566 } 567 568 571 public boolean isModifier() { 572 return true; 573 } 574 575 581 public boolean isNative() { 582 return this.modifierKeyword == ModifierKeyword.NATIVE_KEYWORD; 583 } 584 585 591 public boolean isPrivate() { 592 return this.modifierKeyword == ModifierKeyword.PRIVATE_KEYWORD; 593 } 594 595 601 public boolean isProtected() { 602 return this.modifierKeyword == ModifierKeyword.PROTECTED_KEYWORD; 603 } 604 605 611 public boolean isPublic() { 612 return this.modifierKeyword == ModifierKeyword.PUBLIC_KEYWORD; 613 } 614 615 621 public boolean isStatic() { 622 return this.modifierKeyword == ModifierKeyword.STATIC_KEYWORD; 623 } 624 625 631 public boolean isStrictfp() { 632 return this.modifierKeyword == ModifierKeyword.STRICTFP_KEYWORD; 633 } 634 635 641 public boolean isSynchronized() { 642 return this.modifierKeyword == ModifierKeyword.SYNCHRONIZED_KEYWORD; 643 } 644 645 651 public boolean isTransient() { 652 return this.modifierKeyword == ModifierKeyword.TRANSIENT_KEYWORD; 653 } 654 655 661 public boolean isVolatile() { 662 return this.modifierKeyword == ModifierKeyword.VOLATILE_KEYWORD; 663 } 664 665 669 int memSize() { 670 return BASE_NODE_SIZE + 1 * 4; 672 } 673 674 681 public void setKeyword(ModifierKeyword modifierKeyord) { 682 if (modifierKeyord == null) { 683 throw new IllegalArgumentException (); 684 } 685 preValueChange(KEYWORD_PROPERTY); 686 this.modifierKeyword = modifierKeyord; 687 postValueChange(KEYWORD_PROPERTY); 688 } 689 690 694 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 695 return matcher.match(this, other); 697 } 698 699 703 int treeSize() { 704 return memSize(); 705 } 706 } 707 | Popular Tags |