1 /*
  2  * Copyright (c) 1999, 2026, 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_SUPER    = 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.CLASS})
136     @NoToStringValue
137     public static final int ACC_MODULE   = 1<<15;
138 
139     /* ***************************************
140      * Internal compiler flags (no bits in the lower 16).
141      *****************************************/
142 
143     /** Flag is set if symbol is deprecated.  See also DEPRECATED_REMOVAL.
144      */
145     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
146     public static final int DEPRECATED   = 1<<17;
147 
148     /** Flag is set for a variable symbol if the variable's definition
149      *  has an initializer part.
150      */
151     @Use({FlagTarget.VARIABLE})
152     public static final int HASINIT          = 1<<18;
153 
154     /** Class is an implicitly declared top level class.
155      */
156     @Use({FlagTarget.CLASS})
157     public static final int IMPLICIT_CLASS    = 1<<19;
158 
159     /** Variable with implicit/inferred type.
160      */
161     @Use(FlagTarget.VARIABLE)
162     public static final int VAR_VARIABLE     = 1<<19;
163 
164     /** Flag is set for compiler-generated anonymous method symbols
165      *  that `own' an initializer block.
166      */
167     @Use({FlagTarget.METHOD})
168     public static final int BLOCK            = 1<<20;
169 
170     /** A parameter of a lambda function.
171      */
172     @Use(FlagTarget.VARIABLE)
173     public static final int LAMBDA_PARAMETER     = 1<<20;
174 
175     /** Flag is set for ClassSymbols that are being compiled from source.
176      */
177     @Use({FlagTarget.CLASS})
178     public static final int FROM_SOURCE      = 1<<21;
179 
180     /** Flag is set for nested classes that do not access instance members
181      *  or `this' of an outer class and therefore don't need to be passed
182      *  a this$n reference.  This value is currently set only for anonymous
183      *  classes in superclass constructor calls.
184      *  todo: use this value for optimizing away this$n parameters in
185      *  other cases.
186      */
187     @Use({FlagTarget.CLASS, FlagTarget.VARIABLE})
188     public static final int NOOUTERTHIS  = 1<<22;
189 
190     /** Flag is set for package symbols if a package has a member or
191      *  directory and therefore exists.
192      */
193     @Use({FlagTarget.CLASS, FlagTarget.PACKAGE})
194     public static final int EXISTS           = 1<<23;
195 
196     /** Flag is set for compiler-generated compound classes
197      *  representing multiple variable bounds
198      */
199     @Use({FlagTarget.CLASS})
200     public static final int COMPOUND     = 1<<24;
201 
202     /** Flag is set for class symbols if a class file was found for this class.
203      */
204     @Use({FlagTarget.CLASS})
205     public static final int CLASS_SEEN   = 1<<25;
206 
207     /** Flag is set for class symbols if a source file was found for this
208      *  class.
209      */
210     @Use({FlagTarget.CLASS})
211     public static final int SOURCE_SEEN  = 1<<26;
212 
213     /* State flags (are reset during compilation).
214      */
215 
216     /** Flag for class symbols is set and later re-set as a lock in
217      *  Enter to detect cycles in the superclass/superinterface
218      *  relations.  Similarly for constructor call cycle detection in
219      *  Attr.
220      */
221     @Use({FlagTarget.CLASS, FlagTarget.METHOD})
222     public static final int LOCKED           = 1<<27;
223 
224     /** Flag for class symbols is set and later re-set to indicate that a class
225      *  has been entered but has not yet been attributed.
226      */
227     @Use({FlagTarget.CLASS})
228     public static final int UNATTRIBUTED = 1<<28;
229 
230     /** Flag for synthesized default constructors of anonymous classes.
231      */
232     @Use({FlagTarget.METHOD})
233     public static final int ANONCONSTR   = 1<<29;
234 
235     /**
236      * Flag to indicate the superclasses of this ClassSymbol has been attributed.
237      */
238     @Use({FlagTarget.CLASS})
239     public static final int SUPER_OWNER_ATTRIBUTED = 1<<29;
240 
241     /** Flag for class symbols to indicate it has been checked and found
242      *  acyclic.
243      */
244     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.TYPE_VAR})
245     public static final int ACYCLIC          = 1<<30;
246 
247     /** Flag that marks bridge methods.
248      */
249     @Use({FlagTarget.METHOD})
250     public static final long BRIDGE          = 1L<<31;
251 
252     /** Flag that marks formal parameters.
253      */
254     @Use({FlagTarget.VARIABLE})
255     public static final long PARAMETER   = 1L<<33;
256 
257     /** Flag that marks varargs methods.
258      */
259     @Use({FlagTarget.METHOD, FlagTarget.VARIABLE})
260     public static final long VARARGS   = 1L<<34;
261 
262     /** Flag for annotation type symbols to indicate it has been
263      *  checked and found acyclic.
264      */
265     @Use({FlagTarget.CLASS})
266     public static final long ACYCLIC_ANN      = 1L<<35;
267 
268     /** Flag that marks a generated default constructor.
269      */
270     @Use({FlagTarget.METHOD})
271     public static final long GENERATEDCONSTR   = 1L<<36;
272 
273     /** Flag that marks a hypothetical method that need not really be
274      *  generated in the binary, but is present in the symbol table to
275      *  simplify checking for erasure clashes - also used for 292 poly sig methods.
276      */
277     @Use({FlagTarget.METHOD})
278     public static final long HYPOTHETICAL   = 1L<<37;
279 
280     /**
281      * Flag that marks an internal proprietary class.
282      */
283     @Use({FlagTarget.CLASS})
284     public static final long PROPRIETARY = 1L<<38;
285 
286     /**
287      * Flag that marks a multi-catch parameter.
288      */
289     @Use({FlagTarget.VARIABLE})
290     public static final long UNION = 1L<<39;
291 
292     /**
293      * Flags an erroneous TypeSymbol as viable for recovery.
294      * TypeSymbols only.
295      */
296     @Use({FlagTarget.CLASS, FlagTarget.TYPE_VAR})
297     public static final long RECOVERABLE = 1L<<40;
298 
299     /**
300      * Flag that marks an 'effectively final' local variable.
301      */
302     @Use({FlagTarget.VARIABLE})
303     public static final long EFFECTIVELY_FINAL = 1L<<41;
304 
305     /**
306      * Flag that marks non-override equivalent methods with the same signature,
307      * or a conflicting match binding (BindingSymbol).
308      */
309     @Use({FlagTarget.METHOD, FlagTarget.VARIABLE})
310     public static final long CLASH = 1L<<42;
311 
312     /**
313      * Flag that marks either a default method or an interface containing default methods.
314      */
315     @Use({FlagTarget.CLASS, FlagTarget.METHOD})
316     public static final long DEFAULT = 1L<<43; // part of ExtendedStandardFlags, cannot be reused
317 
318     /**
319      * Flag that marks class as auxiliary, ie a non-public class following
320      * the public class in a source file, that could block implicit compilation.
321      */
322     @Use({FlagTarget.CLASS})
323     public static final long AUXILIARY = 1L<<44;
324 
325     /**
326      * Flag that marks that a symbol is not available in the current profile
327      */
328     @Use({FlagTarget.CLASS})
329     public static final long NOT_IN_PROFILE = 1L<<45;
330 
331     /**
332      * Flag that indicates that an override error has been detected by Check.
333      */
334     @Use({FlagTarget.METHOD})
335     public static final long BAD_OVERRIDE = 1L<<45;
336 
337     /**
338      * Flag that indicates a signature polymorphic method (292).
339      */
340     @Use({FlagTarget.METHOD})
341     public static final long SIGNATURE_POLYMORPHIC = 1L<<46;
342 
343     /**
344      * Flag that indicates that an inference variable is used in a 'throws' clause.
345      */
346     @Use({FlagTarget.TYPE_VAR})
347     public static final long THROWS = 1L<<47;
348 
349     /**
350      * Flag to indicate sealed class/interface declaration.
351      */
352     @Use({FlagTarget.CLASS})
353     public static final long SEALED = 1L<<48; // part of ExtendedStandardFlags, cannot be reused
354 
355     /**
356      * Flag that marks a synthetic method body for a lambda expression
357      */
358     @Use({FlagTarget.METHOD})
359     public static final long LAMBDA_METHOD = 1L<<49;
360 
361     /**
362      * Flag that marks a synthetic local capture field in a local/anon class
363      */
364     @Use({FlagTarget.VARIABLE})
365     public static final long LOCAL_CAPTURE_FIELD = 1L<<49;
366 
367     /**
368      * Flag to control recursion in TransTypes
369      */
370     @Use({FlagTarget.CLASS})
371     public static final long TYPE_TRANSLATED = 1L<<50;
372 
373     /**
374      * Flag to indicate class symbol is for module-info
375      */
376     @Use({FlagTarget.CLASS})
377     public static final long MODULE = 1L<<51;
378 
379     /**
380      * Flag to indicate the given ModuleSymbol is an automatic module.
381      */
382     @Use({FlagTarget.MODULE})
383     public static final long AUTOMATIC_MODULE = 1L<<52;
384 
385     /**
386      * Flag to indicate the given PackageSymbol contains any non-.java and non-.class resources.
387      */
388     @Use({FlagTarget.PACKAGE})
389     public static final long HAS_RESOURCE = 1L<<52;
390 
391     /**
392      * Flag to indicate the given ParamSymbol has a user-friendly name filled.
393      */
394     @Use({FlagTarget.VARIABLE}) //ParamSymbols only
395     public static final long NAME_FILLED = 1L<<52;
396 
397     /**
398      * Flag to indicate the given ModuleSymbol is a system module.
399      */
400     @Use({FlagTarget.MODULE})
401     public static final long SYSTEM_MODULE = 1L<<53;
402 
403     /**
404      * Flag to indicate the given ClassSymbol is a value based.
405      */
406     @Use({FlagTarget.CLASS})
407     public static final long VALUE_BASED = 1L<<53;
408 
409     /**
410      * Flag to indicate the given symbol has a @Deprecated annotation.
411      */
412     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
413     public static final long DEPRECATED_ANNOTATION = 1L<<54;
414 
415     /**
416      * Flag to indicate the given symbol has been deprecated and marked for removal.
417      */
418     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
419     public static final long DEPRECATED_REMOVAL = 1L<<55;
420 
421     /**
422      * Flag to indicate the API element in question is for a preview API.
423      */
424     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
425     public static final long PREVIEW_API = 1L<<56; //any Symbol kind
426 
427     /**
428      * Flag for synthesized default constructors of anonymous classes that have an enclosing expression.
429      */
430     @Use({FlagTarget.METHOD})
431     public static final long ANONCONSTR_BASED = 1L<<57;
432 
433     /**
434      * Flag that marks finalize block as body-only, should not be copied into catch clauses.
435      * Used to implement try-with-resources.
436      */
437     @Use({FlagTarget.BLOCK})
438     public static final long BODY_ONLY_FINALIZE = 1L<<17;
439 
440     /**
441      * Flag to indicate the API element in question is for a preview API.
442      */
443     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
444     public static final long PREVIEW_REFLECTIVE = 1L<<58; //any Symbol kind
445 
446     /**
447      * Flag to indicate the given variable is a match binding variable.
448      */
449     @Use({FlagTarget.VARIABLE})
450     public static final long MATCH_BINDING = 1L<<59;
451 
452     /**
453      * A flag to indicate a match binding variable whose scope extends after the current statement.
454      */
455     @Use({FlagTarget.VARIABLE})
456     public static final long MATCH_BINDING_TO_OUTER = 1L<<60;
457 
458     /**
459      * Flag to indicate that a class is a record. The flag is also used to mark fields that are
460      * part of the state vector of a record and to mark the canonical constructor
461      */
462     @Use({FlagTarget.CLASS, FlagTarget.VARIABLE, FlagTarget.METHOD})
463     public static final long RECORD = 1L<<61;
464 
465     /**
466      * Flag to mark a record constructor as a compact one
467      */
468     @Use({FlagTarget.METHOD})
469     public static final long COMPACT_RECORD_CONSTRUCTOR = 1L<<51;
470 
471     /**
472      * Flag to mark a record field that was not initialized in the compact constructor
473      */
474     @Use({FlagTarget.VARIABLE})
475     public static final long UNINITIALIZED_FIELD= 1L<<51;
476 
477     /** Flag is set for compiler-generated record members, it could be applied to
478      *  accessors and fields
479      */
480     @Use({FlagTarget.METHOD, FlagTarget.VARIABLE})
481     public static final int GENERATED_MEMBER = 1<<24;
482 
483     /**
484      * Flag to indicate restricted method declaration.
485      */
486     @Use({FlagTarget.METHOD})
487     public static final long RESTRICTED = 1L<<62;
488 
489     /**
490      * Flag to indicate parameters that require identity.
491      */
492     @Use({FlagTarget.VARIABLE}) //ParamSymbols only
493     public static final long REQUIRES_IDENTITY = 1L<<62;
494 
495     /**
496      * Flag to indicate type annotations have been queued for field initializers.
497      */
498     @Use({FlagTarget.VARIABLE})
499     public static final long FIELD_INIT_TYPE_ANNOTATIONS_QUEUED = 1L<<53;
500 
501     /**
502      * Flag to indicate that the class/interface was declared with the non-sealed modifier.
503      */
504     @Use({FlagTarget.CLASS})
505     @CustomToStringValue("non-sealed")
506     public static final long NON_SEALED = 1L<<63;  // part of ExtendedStandardFlags, cannot be reused
507 
508     /**
509      * Describe modifier flags as they might appear in source code, i.e.,
510      * separated by spaces and in the order suggested by JLS 8.1.1.
511      */
512     public static String toSource(long flags) {
513         return asModifierSet(flags).stream()
514           .map(Modifier::toString)
515           .collect(Collectors.joining(" "));
516     }
517 
518     /** Modifier masks.
519      */
520     @NotFlag
521     public static final int
522         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
523         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC,
524         StaticLocalFlags                  = LocalClassFlags | STATIC | INTERFACE,
525         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
526         MemberStaticClassFlags            = MemberClassFlags | STATIC,
527         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
528         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
529         VarFlags                          = AccessFlags | FINAL | STATIC |
530                                             VOLATILE | TRANSIENT | ENUM,
531         ConstructorFlags                  = AccessFlags,
532         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
533         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
534                                             SYNCHRONIZED | FINAL | STRICTFP,
535         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
536                                             SYNCHRONIZED | FINAL | STRICTFP;
537     @NotFlag
538     public static final long
539         //NOTE: flags in ExtendedStandardFlags cannot be overlayed across Symbol kinds:
540         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED,
541         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED,
542         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED,
543         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED,
544         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED,
545         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
546         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
547         LocalVarFlags                     = FINAL | PARAMETER,
548         ReceiverParamFlags                = PARAMETER;
549 
550     public static Set<Modifier> asModifierSet(long flags) {
551         Set<Modifier> modifiers = modifierSets.get(flags);
552         if (modifiers == null) {
553             modifiers = java.util.EnumSet.noneOf(Modifier.class);
554             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
555             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
556             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
557             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
558             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
559             if (0 != (flags & SEALED))    modifiers.add(Modifier.SEALED);
560             if (0 != (flags & NON_SEALED))
561                                           modifiers.add(Modifier.NON_SEALED);
562             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
563             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
564             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
565             if (0 != (flags & SYNCHRONIZED))
566                                           modifiers.add(Modifier.SYNCHRONIZED);
567             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
568             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
569             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);
570             modifiers = Collections.unmodifiableSet(modifiers);
571             modifierSets.put(flags, modifiers);
572         }
573         return modifiers;
574     }
575 
576     // Cache of modifier sets.
577     private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64);
578 
579     public static boolean isStatic(Symbol symbol) {
580         return (symbol.flags() & STATIC) != 0;
581     }
582 
583     public static boolean isEnum(Symbol symbol) {
584         return (symbol.flags() & ENUM) != 0;
585     }
586 
587     public static boolean isConstant(Symbol.VarSymbol symbol) {
588         return symbol.getConstValue() != null;
589     }
590 
591     public enum FlagTarget {
592         /** This flag can appear the JCBlock.
593          */
594         BLOCK,
595         /** This flag can appear on ClassSymbols.
596          */
597         CLASS,
598         /** This flag can appear on ModuleSymbols.
599          */
600         MODULE,
601         /** This flag can appear on PackageSymbols.
602          */
603         PACKAGE,
604         /** This flag can appear on TypeVarSymbols.
605          */
606         TYPE_VAR,
607         /** This flag can appear on MethodSymbols.
608          */
609         METHOD,
610         /** This flag can appear on VarSymbols, includes
611          *  including ParamSymbol, and BindingSymbol.
612          */
613         VARIABLE;
614     }
615 
616     @Retention(RetentionPolicy.RUNTIME)
617     public @interface Use {
618         public FlagTarget[] value();
619     }
620 
621     @Retention(RetentionPolicy.RUNTIME)
622     public @interface NotFlag {}
623 
624     @Retention(RetentionPolicy.RUNTIME)
625     public @interface CustomToStringValue {
626         public String value();
627     }
628 
629     @Retention(RetentionPolicy.RUNTIME)
630     public @interface NoToStringValue {
631     }
632 }