1 /* 2 * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.tools.javac.code; 27 28 import java.lang.annotation.Retention; 29 import java.lang.annotation.RetentionPolicy; 30 import java.util.Collections; 31 import java.util.EnumSet; 32 import java.util.Map; 33 import java.util.Set; 34 import java.util.concurrent.ConcurrentHashMap; 35 import java.util.stream.Collectors; 36 37 import javax.lang.model.element.Modifier; 38 39 import com.sun.tools.javac.util.Assert; 40 41 /** Access flags and other modifiers for Java classes and members. 42 * 43 * <p><b>This is NOT part of any supported API. 44 * If you write code that depends on this, you do so at your own risk. 45 * This code and its internal interfaces are subject to change or 46 * deletion without notice.</b> 47 */ 48 public class Flags { 49 50 private Flags() {} // uninstantiable 51 52 public static String toString(long flags) { 53 StringBuilder buf = new StringBuilder(); 54 String sep = ""; 55 for (FlagsEnum flag : asFlagSet(flags)) { 56 buf.append(sep); 57 buf.append(flag); 58 sep = " "; 59 } 60 return buf.toString(); 61 } 62 63 public static EnumSet<FlagsEnum> asFlagSet(long flags) { 64 EnumSet<FlagsEnum> flagSet = EnumSet.noneOf(FlagsEnum.class); 65 for (FlagsEnum flag : FlagsEnum.values()) { 66 if ((flags & flag.value()) != 0) { 67 flagSet.add(flag); 68 flags &= ~flag.value(); 69 } 70 } 71 Assert.check(flags == 0); 72 return flagSet; 73 } 74 75 /* Standard Java flags. 76 */ 77 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.VARIABLE}) 78 public static final int PUBLIC = 1; 79 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.VARIABLE}) 80 public static final int PRIVATE = 1<<1; 81 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.VARIABLE}) 82 public static final int PROTECTED = 1<<2; 83 @Use({FlagTarget.BLOCK, FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.VARIABLE}) 84 public static final int STATIC = 1<<3; 85 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.VARIABLE}) 86 public static final int FINAL = 1<<4; 87 @Use({FlagTarget.METHOD}) 88 public static final int SYNCHRONIZED = 1<<5; 89 @Use({FlagTarget.VARIABLE}) 90 public static final int VOLATILE = 1<<6; 91 @Use({FlagTarget.VARIABLE}) 92 public static final int TRANSIENT = 1<<7; 93 @Use({FlagTarget.METHOD}) 94 public static final int NATIVE = 1<<8; 95 @Use({FlagTarget.CLASS}) 96 public static final int INTERFACE = 1<<9; 97 @Use({FlagTarget.CLASS, FlagTarget.METHOD}) 98 public static final int ABSTRACT = 1<<10; 99 @Use({FlagTarget.CLASS, FlagTarget.METHOD}) 100 public static final int STRICTFP = 1<<11; 101 102 /* Flag that marks a symbol synthetic, added in classfile v49.0. */ 103 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.VARIABLE}) 104 public static final int SYNTHETIC = 1<<12; 105 106 /** Flag that marks attribute interfaces, added in classfile v49.0. */ 107 @Use({FlagTarget.CLASS}) 108 public static final int ANNOTATION = 1<<13; 109 110 /** An enumeration type or an enumeration constant, added in 111 * classfile v49.0. */ 112 @Use({FlagTarget.CLASS, FlagTarget.VARIABLE}) 113 public static final int ENUM = 1<<14; 114 115 /** Added in SE8, represents constructs implicitly declared in source. */ 116 @Use({FlagTarget.MODULE, FlagTarget.VARIABLE}) 117 public static final int MANDATED = 1<<15; 118 119 @NotFlag 120 public static final int StandardFlags = 0x0fff; 121 122 // Because the following access flags are overloaded with other 123 // bit positions, we translate them when reading and writing class 124 // files into unique bits positions: ACC_SYNTHETIC <-> SYNTHETIC, 125 // for example. 126 @Use({FlagTarget.CLASS}) 127 @NoToStringValue 128 public static final int ACC_IDENTITY = 1<<5; 129 @Use({FlagTarget.METHOD}) 130 @NoToStringValue 131 public static final int ACC_BRIDGE = 1<<6; 132 @Use({FlagTarget.METHOD}) 133 @NoToStringValue 134 public static final int ACC_VARARGS = 1<<7; 135 @Use({FlagTarget.VARIABLE}) 136 @NoToStringValue 137 public static final int ACC_STRICT = 1<<11; 138 @Use({FlagTarget.CLASS}) 139 @NoToStringValue 140 public static final int ACC_MODULE = 1<<15; 141 142 /* *************************************** 143 * Internal compiler flags (no bits in the lower 16). 144 *****************************************/ 145 146 /** Flag is set if symbol is deprecated. See also DEPRECATED_REMOVAL. 147 */ 148 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE}) 149 public static final int DEPRECATED = 1<<17; 150 151 /** Flag is set for a variable symbol if the variable's definition 152 * has an initializer part. 153 */ 154 @Use({FlagTarget.VARIABLE}) 155 public static final int HASINIT = 1<<18; 156 157 /** Flag is set for a class or interface whose instances have identity 158 * i.e. any concrete class not declared with the modifier `value' 159 * (a) abstract class not declared `value' 160 * (b) older class files with ACC_SUPER bit set 161 */ 162 @Use({FlagTarget.CLASS}) 163 public static final int IDENTITY_TYPE = 1<<18; 164 165 /** Class is an implicitly declared top level class. 166 */ 167 @Use({FlagTarget.CLASS}) 168 public static final int IMPLICIT_CLASS = 1<<19; 169 170 /** Flag is set for compiler-generated anonymous method symbols 171 * that `own' an initializer block. 172 */ 173 @Use({FlagTarget.METHOD}) 174 public static final int BLOCK = 1<<21; 175 176 /** Marks a type as a value class */ 177 @Use({FlagTarget.CLASS}) 178 public static final int VALUE_CLASS = 1<<20; 179 180 /** Flag is set for ClassSymbols that are being compiled from source. 181 */ 182 @Use({FlagTarget.CLASS}) 183 public static final int FROM_SOURCE = 1<<21; 184 185 /** Flag is set for nested classes that do not access instance members 186 * or `this' of an outer class and therefore don't need to be passed 187 * a this$n reference. This value is currently set only for anonymous 188 * classes in superclass constructor calls. 189 * todo: use this value for optimizing away this$n parameters in 190 * other cases. 191 */ 192 @Use({FlagTarget.CLASS, FlagTarget.VARIABLE}) 193 public static final int NOOUTERTHIS = 1<<22; 194 195 /** Flag is set for package symbols if a package has a member or 196 * directory and therefore exists. 197 */ 198 @Use({FlagTarget.CLASS, FlagTarget.PACKAGE}) 199 public static final int EXISTS = 1<<23; 200 201 /** Flag is set for compiler-generated compound classes 202 * representing multiple variable bounds 203 */ 204 @Use({FlagTarget.CLASS}) 205 public static final int COMPOUND = 1<<24; 206 207 /** Flag is set for class symbols if a class file was found for this class. 208 */ 209 @Use({FlagTarget.CLASS}) 210 public static final int CLASS_SEEN = 1<<25; 211 212 /** Flag is set for class symbols if a source file was found for this 213 * class. 214 */ 215 @Use({FlagTarget.CLASS}) 216 public static final int SOURCE_SEEN = 1<<26; 217 218 /* State flags (are reset during compilation). 219 */ 220 221 /** Flag for class symbols is set and later re-set as a lock in 222 * Enter to detect cycles in the superclass/superinterface 223 * relations. Similarly for constructor call cycle detection in 224 * Attr. 225 */ 226 @Use({FlagTarget.CLASS, FlagTarget.METHOD}) 227 public static final int LOCKED = 1<<27; 228 229 /** Flag for class symbols is set and later re-set to indicate that a class 230 * has been entered but has not yet been attributed. 231 */ 232 @Use({FlagTarget.CLASS}) 233 public static final int UNATTRIBUTED = 1<<28; 234 235 /** Flag for synthesized default constructors of anonymous classes. 236 */ 237 @Use({FlagTarget.METHOD}) 238 public static final int ANONCONSTR = 1<<29; 239 240 /** 241 * Flag to indicate the superclasses of this ClassSymbol has been attributed. 242 */ 243 @Use({FlagTarget.CLASS}) 244 public static final int SUPER_OWNER_ATTRIBUTED = 1<<29; 245 246 /** Flag for class symbols to indicate it has been checked and found 247 * acyclic. 248 */ 249 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.TYPE_VAR}) 250 public static final int ACYCLIC = 1<<30; 251 252 /** Flag that marks bridge methods. 253 */ 254 @Use({FlagTarget.METHOD}) 255 public static final long BRIDGE = 1L<<31; 256 257 /** Flag that marks formal parameters. 258 */ 259 @Use({FlagTarget.VARIABLE}) 260 public static final long PARAMETER = 1L<<33; 261 262 /** Flag that marks varargs methods. 263 */ 264 @Use({FlagTarget.METHOD, FlagTarget.VARIABLE}) 265 public static final long VARARGS = 1L<<34; 266 267 /** Flag for annotation type symbols to indicate it has been 268 * checked and found acyclic. 269 */ 270 @Use({FlagTarget.CLASS}) 271 public static final long ACYCLIC_ANN = 1L<<35; 272 273 /** Flag that marks a generated default constructor. 274 */ 275 @Use({FlagTarget.METHOD}) 276 public static final long GENERATEDCONSTR = 1L<<36; 277 278 /** Flag that marks a hypothetical method that need not really be 279 * generated in the binary, but is present in the symbol table to 280 * simplify checking for erasure clashes - also used for 292 poly sig methods. 281 */ 282 @Use({FlagTarget.METHOD}) 283 public static final long HYPOTHETICAL = 1L<<37; 284 285 /** 286 * Flag that marks an internal proprietary class. 287 */ 288 @Use({FlagTarget.CLASS}) 289 public static final long PROPRIETARY = 1L<<38; 290 291 /** 292 * Flag that marks a multi-catch parameter. 293 */ 294 @Use({FlagTarget.VARIABLE}) 295 public static final long UNION = 1L<<39; 296 297 /** 298 * Flags an erroneous TypeSymbol as viable for recovery. 299 * TypeSymbols only. 300 */ 301 @Use({FlagTarget.CLASS, FlagTarget.TYPE_VAR}) 302 public static final long RECOVERABLE = 1L<<40; 303 304 /** 305 * Flag that marks an 'effectively final' local variable. 306 */ 307 @Use({FlagTarget.VARIABLE}) 308 public static final long EFFECTIVELY_FINAL = 1L<<41; 309 310 /** 311 * Flag that marks non-override equivalent methods with the same signature, 312 * or a conflicting match binding (BindingSymbol). 313 */ 314 @Use({FlagTarget.METHOD, FlagTarget.VARIABLE}) 315 public static final long CLASH = 1L<<42; 316 317 /** 318 * Flag that marks either a default method or an interface containing default methods. 319 */ 320 @Use({FlagTarget.CLASS, FlagTarget.METHOD}) 321 public static final long DEFAULT = 1L<<43; // part of ExtendedStandardFlags, cannot be reused 322 323 /** 324 * Flag that marks class as auxiliary, ie a non-public class following 325 * the public class in a source file, that could block implicit compilation. 326 */ 327 @Use({FlagTarget.CLASS}) 328 public static final long AUXILIARY = 1L<<44; 329 330 /** 331 * Flag that marks that a symbol is not available in the current profile 332 */ 333 @Use({FlagTarget.CLASS}) 334 public static final long NOT_IN_PROFILE = 1L<<45; 335 336 /** 337 * Flag that indicates that an override error has been detected by Check. 338 */ 339 @Use({FlagTarget.METHOD}) 340 public static final long BAD_OVERRIDE = 1L<<45; 341 342 /** 343 * Flag that indicates a signature polymorphic method (292). 344 */ 345 @Use({FlagTarget.METHOD}) 346 public static final long SIGNATURE_POLYMORPHIC = 1L<<46; 347 348 /** 349 * Flag that indicates that an inference variable is used in a 'throws' clause. 350 */ 351 @Use({FlagTarget.TYPE_VAR}) 352 public static final long THROWS = 1L<<47; 353 354 /** 355 * Flag to indicate sealed class/interface declaration. 356 */ 357 @Use({FlagTarget.CLASS}) 358 public static final long SEALED = 1L<<48; // part of ExtendedStandardFlags, cannot be reused 359 360 /** 361 * Flag that marks a synthetic method body for a lambda expression 362 */ 363 @Use({FlagTarget.METHOD}) 364 public static final long LAMBDA_METHOD = 1L<<49; 365 366 /** 367 * Flag that marks a synthetic local capture field in a local/anon class 368 */ 369 @Use({FlagTarget.VARIABLE}) 370 public static final long LOCAL_CAPTURE_FIELD = 1L<<49; 371 372 /** 373 * Flag to control recursion in TransTypes 374 */ 375 @Use({FlagTarget.CLASS}) 376 public static final long TYPE_TRANSLATED = 1L<<50; 377 378 /** 379 * Flag to indicate class symbol is for module-info 380 */ 381 @Use({FlagTarget.CLASS}) 382 public static final long MODULE = 1L<<51; 383 384 /** 385 * Flag to indicate the given ModuleSymbol is an automatic module. 386 */ 387 @Use({FlagTarget.MODULE}) 388 public static final long AUTOMATIC_MODULE = 1L<<52; 389 390 /** 391 * Flag to indicate the given PackageSymbol contains any non-.java and non-.class resources. 392 */ 393 @Use({FlagTarget.PACKAGE}) 394 public static final long HAS_RESOURCE = 1L<<52; 395 396 /** 397 * Flag to indicate the given ParamSymbol has a user-friendly name filled. 398 */ 399 @Use({FlagTarget.VARIABLE}) //ParamSymbols only 400 public static final long NAME_FILLED = 1L<<52; 401 402 /** 403 * Flag to indicate the given ModuleSymbol is a system module. 404 */ 405 @Use({FlagTarget.MODULE}) 406 public static final long SYSTEM_MODULE = 1L<<53; 407 408 /** 409 * Flag to indicate the given ClassSymbol is a value based. 410 */ 411 @Use({FlagTarget.CLASS}) 412 public static final long VALUE_BASED = 1L<<53; 413 414 /** 415 * Flag to indicate the given ClassSymbol is a value based. 416 */ 417 @Use({FlagTarget.CLASS}) 418 public static final long MIGRATED_VALUE_CLASS = 1L<<57; //ClassSymbols only 419 420 /** 421 * Flag to indicate the given symbol has a @Deprecated annotation. 422 */ 423 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE}) 424 public static final long DEPRECATED_ANNOTATION = 1L<<54; 425 426 /** 427 * Flag to indicate the given symbol has been deprecated and marked for removal. 428 */ 429 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE}) 430 public static final long DEPRECATED_REMOVAL = 1L<<55; 431 432 /** 433 * Flag to indicate the API element in question is for a preview API. 434 */ 435 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE}) 436 public static final long PREVIEW_API = 1L<<56; //any Symbol kind 437 438 /** 439 * Flag for synthesized default constructors of anonymous classes that have an enclosing expression. 440 */ 441 @Use({FlagTarget.METHOD}) 442 public static final long ANONCONSTR_BASED = 1L<<57; 443 444 /** 445 * Flag that marks finalize block as body-only, should not be copied into catch clauses. 446 * Used to implement try-with-resources. 447 */ 448 @Use({FlagTarget.BLOCK}) 449 public static final long BODY_ONLY_FINALIZE = 1L<<17; 450 451 /** 452 * Flag to indicate the API element in question is for a preview API. 453 */ 454 @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE}) 455 public static final long PREVIEW_REFLECTIVE = 1L<<58; //any Symbol kind 456 457 /** 458 * Flag to indicate the given variable is a match binding variable. 459 */ 460 @Use({FlagTarget.VARIABLE}) 461 public static final long MATCH_BINDING = 1L<<59; 462 463 /** 464 * A flag to indicate a match binding variable whose scope extends after the current statement. 465 */ 466 @Use({FlagTarget.VARIABLE}) 467 public static final long MATCH_BINDING_TO_OUTER = 1L<<60; 468 469 /** 470 * Flag to indicate that a class is a record. The flag is also used to mark fields that are 471 * part of the state vector of a record and to mark the canonical constructor 472 */ 473 @Use({FlagTarget.CLASS, FlagTarget.VARIABLE, FlagTarget.METHOD}) 474 public static final long RECORD = 1L<<61; 475 476 /** 477 * Flag to mark a record constructor as a compact one 478 */ 479 @Use({FlagTarget.METHOD}) 480 public static final long COMPACT_RECORD_CONSTRUCTOR = 1L<<51; 481 482 /** 483 * Flag to mark a record field that was not initialized in the compact constructor 484 */ 485 @Use({FlagTarget.VARIABLE}) 486 public static final long UNINITIALIZED_FIELD= 1L<<51; 487 488 /** Flag is set for compiler-generated record members, it could be applied to 489 * accessors and fields 490 */ 491 @Use({FlagTarget.METHOD, FlagTarget.VARIABLE}) 492 public static final int GENERATED_MEMBER = 1<<24; 493 494 /** 495 * Flag to indicate restricted method declaration. 496 */ 497 @Use({FlagTarget.METHOD}) 498 public static final long RESTRICTED = 1L<<62; 499 500 /** 501 * Flag to indicate parameters that require identity. 502 */ 503 @Use({FlagTarget.VARIABLE}) //ParamSymbols only 504 public static final long REQUIRES_IDENTITY = 1L<<62; 505 506 /** 507 * Flag to indicate type annotations have been queued for field initializers. 508 */ 509 @Use({FlagTarget.VARIABLE}) 510 public static final long FIELD_INIT_TYPE_ANNOTATIONS_QUEUED = 1L<<53; 511 512 /** 513 * Flag to indicate that the class/interface was declared with the non-sealed modifier. 514 */ 515 @Use({FlagTarget.CLASS}) 516 @CustomToStringValue("non-sealed") 517 public static final long NON_SEALED = 1L<<63; // part of ExtendedStandardFlags, cannot be reused 518 519 /** 520 * Flag to indicate that a class has at least one strict field 521 */ 522 @Use({FlagTarget.CLASS}) 523 public static final long HAS_STRICT = 1L<<52; // ClassSymbols, temporary hack 524 525 /** 526 * Flag to indicate that a field is strict 527 */ 528 @Use({FlagTarget.VARIABLE}) 529 public static final long STRICT = 1L<<19; // VarSymbols 530 531 /** 532 * Describe modifier flags as they might appear in source code, i.e., 533 * separated by spaces and in the order suggested by JLS 8.1.1. 534 */ 535 public static String toSource(long flags) { 536 return asModifierSet(flags).stream() 537 .map(Modifier::toString) 538 .collect(Collectors.joining(" ")); 539 } 540 541 /** Modifier masks. 542 */ 543 @NotFlag 544 public static final int 545 AccessFlags = PUBLIC | PROTECTED | PRIVATE, 546 LocalClassFlags = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC | IDENTITY_TYPE, 547 StaticLocalClassFlags = LocalClassFlags | STATIC | INTERFACE, 548 MemberClassFlags = LocalClassFlags | INTERFACE | AccessFlags, 549 MemberStaticClassFlags = MemberClassFlags | STATIC, 550 ClassFlags = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION, 551 InterfaceVarFlags = FINAL | STATIC | PUBLIC, 552 VarFlags = AccessFlags | FINAL | STATIC | 553 VOLATILE | TRANSIENT | ENUM, 554 ConstructorFlags = AccessFlags, 555 InterfaceMethodFlags = ABSTRACT | PUBLIC, 556 MethodFlags = AccessFlags | ABSTRACT | STATIC | NATIVE | 557 SYNCHRONIZED | FINAL | STRICTFP, 558 RecordMethodFlags = AccessFlags | ABSTRACT | STATIC | 559 SYNCHRONIZED | FINAL | STRICTFP; 560 @NotFlag 561 public static final long 562 //NOTE: flags in ExtendedStandardFlags cannot be overlayed across Symbol kinds: 563 ExtendedStandardFlags = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED | VALUE_CLASS, 564 ExtendedMemberClassFlags = (long)MemberClassFlags | SEALED | NON_SEALED | VALUE_CLASS, 565 ExtendedMemberStaticClassFlags = (long) MemberStaticClassFlags | SEALED | NON_SEALED | VALUE_CLASS, 566 ExtendedClassFlags = (long)ClassFlags | SEALED | NON_SEALED | VALUE_CLASS, 567 ExtendedLocalClassFlags = (long) LocalClassFlags | VALUE_CLASS, 568 ExtendedStaticLocalClassFlags = (long) StaticLocalClassFlags | VALUE_CLASS, 569 ValueFieldFlags = (long) VarFlags | STRICT | FINAL, 570 ModifierFlags = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED | VALUE_CLASS, 571 InterfaceMethodMask = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT, 572 AnnotationTypeElementMask = ABSTRACT | PUBLIC, 573 LocalVarFlags = FINAL | PARAMETER, 574 ReceiverParamFlags = PARAMETER; 575 576 public static Set<Modifier> asModifierSet(long flags) { 577 Set<Modifier> modifiers = modifierSets.get(flags); 578 if (modifiers == null) { 579 modifiers = java.util.EnumSet.noneOf(Modifier.class); 580 if (0 != (flags & PUBLIC)) modifiers.add(Modifier.PUBLIC); 581 if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED); 582 if (0 != (flags & PRIVATE)) modifiers.add(Modifier.PRIVATE); 583 if (0 != (flags & ABSTRACT)) modifiers.add(Modifier.ABSTRACT); 584 if (0 != (flags & STATIC)) modifiers.add(Modifier.STATIC); 585 if (0 != (flags & SEALED)) modifiers.add(Modifier.SEALED); 586 if (0 != (flags & NON_SEALED)) 587 modifiers.add(Modifier.NON_SEALED); 588 if (0 != (flags & FINAL)) modifiers.add(Modifier.FINAL); 589 if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT); 590 if (0 != (flags & VOLATILE)) modifiers.add(Modifier.VOLATILE); 591 if (0 != (flags & SYNCHRONIZED)) 592 modifiers.add(Modifier.SYNCHRONIZED); 593 if (0 != (flags & NATIVE)) modifiers.add(Modifier.NATIVE); 594 if (0 != (flags & STRICTFP)) modifiers.add(Modifier.STRICTFP); 595 if (0 != (flags & DEFAULT)) modifiers.add(Modifier.DEFAULT); 596 if (0 != (flags & VALUE_CLASS)) modifiers.add(Modifier.VALUE); 597 modifiers = Collections.unmodifiableSet(modifiers); 598 modifierSets.put(flags, modifiers); 599 } 600 return modifiers; 601 } 602 603 // Cache of modifier sets. 604 private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64); 605 606 public static boolean isStatic(Symbol symbol) { 607 return (symbol.flags() & STATIC) != 0; 608 } 609 610 public static boolean isEnum(Symbol symbol) { 611 return (symbol.flags() & ENUM) != 0; 612 } 613 614 public static boolean isConstant(Symbol.VarSymbol symbol) { 615 return symbol.getConstValue() != null; 616 } 617 618 public enum FlagTarget { 619 /** This flag can appear the JCBlock. 620 */ 621 BLOCK, 622 /** This flag can appear on ClassSymbols. 623 */ 624 CLASS, 625 /** This flag can appear on ModuleSymbols. 626 */ 627 MODULE, 628 /** This flag can appear on PackageSymbols. 629 */ 630 PACKAGE, 631 /** This flag can appear on TypeVarSymbols. 632 */ 633 TYPE_VAR, 634 /** This flag can appear on MethodSymbols. 635 */ 636 METHOD, 637 /** This flag can appear on VarSymbols, includes 638 * including ParamSymbol, and BindingSymbol. 639 */ 640 VARIABLE; 641 } 642 643 @Retention(RetentionPolicy.RUNTIME) 644 public @interface Use { 645 public FlagTarget[] value(); 646 } 647 648 @Retention(RetentionPolicy.RUNTIME) 649 public @interface NotFlag {} 650 651 @Retention(RetentionPolicy.RUNTIME) 652 public @interface CustomToStringValue { 653 public String value(); 654 } 655 656 @Retention(RetentionPolicy.RUNTIME) 657 public @interface NoToStringValue { 658 } 659 }