< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java

Print this page

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     /** Flag is set for compiler-generated anonymous method symbols
160      *  that `own' an initializer block.
161      */
162     @Use({FlagTarget.METHOD})
163     public static final int BLOCK            = 1<<20;




164 
165     /** Flag is set for ClassSymbols that are being compiled from source.
166      */
167     @Use({FlagTarget.CLASS})
168     public static final int FROM_SOURCE      = 1<<21;
169 
170     /** Flag is set for nested classes that do not access instance members
171      *  or `this' of an outer class and therefore don't need to be passed
172      *  a this$n reference.  This value is currently set only for anonymous
173      *  classes in superclass constructor calls.
174      *  todo: use this value for optimizing away this$n parameters in
175      *  other cases.
176      */
177     @Use({FlagTarget.CLASS, FlagTarget.VARIABLE})
178     public static final int NOOUTERTHIS  = 1<<22;
179 
180     /** Flag is set for package symbols if a package has a member or
181      *  directory and therefore exists.
182      */
183     @Use({FlagTarget.CLASS, FlagTarget.PACKAGE})

379     public static final long HAS_RESOURCE = 1L<<52;
380 
381     /**
382      * Flag to indicate the given ParamSymbol has a user-friendly name filled.
383      */
384     @Use({FlagTarget.VARIABLE}) //ParamSymbols only
385     public static final long NAME_FILLED = 1L<<52;
386 
387     /**
388      * Flag to indicate the given ModuleSymbol is a system module.
389      */
390     @Use({FlagTarget.MODULE})
391     public static final long SYSTEM_MODULE = 1L<<53;
392 
393     /**
394      * Flag to indicate the given ClassSymbol is a value based.
395      */
396     @Use({FlagTarget.CLASS})
397     public static final long VALUE_BASED = 1L<<53;
398 






399     /**
400      * Flag to indicate the given symbol has a @Deprecated annotation.
401      */
402     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
403     public static final long DEPRECATED_ANNOTATION = 1L<<54;
404 
405     /**
406      * Flag to indicate the given symbol has been deprecated and marked for removal.
407      */
408     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
409     public static final long DEPRECATED_REMOVAL = 1L<<55;
410 
411     /**
412      * Flag to indicate the API element in question is for a preview API.
413      */
414     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
415     public static final long PREVIEW_API = 1L<<56; //any Symbol kind
416 
417     /**
418      * Flag for synthesized default constructors of anonymous classes that have an enclosing expression.

478 
479     /**
480      * Flag to indicate parameters that require identity.
481      */
482     @Use({FlagTarget.VARIABLE}) //ParamSymbols only
483     public static final long REQUIRES_IDENTITY = 1L<<62;
484 
485     /**
486      * Flag to indicate type annotations have been queued for field initializers.
487      */
488     @Use({FlagTarget.VARIABLE})
489     public static final long FIELD_INIT_TYPE_ANNOTATIONS_QUEUED = 1L<<53;
490 
491     /**
492      * Flag to indicate that the class/interface was declared with the non-sealed modifier.
493      */
494     @Use({FlagTarget.CLASS})
495     @CustomToStringValue("non-sealed")
496     public static final long NON_SEALED = 1L<<63;  // part of ExtendedStandardFlags, cannot be reused
497 












498     /**
499      * Describe modifier flags as they might appear in source code, i.e.,
500      * separated by spaces and in the order suggested by JLS 8.1.1.
501      */
502     public static String toSource(long flags) {
503         return asModifierSet(flags).stream()
504           .map(Modifier::toString)
505           .collect(Collectors.joining(" "));
506     }
507 
508     /** Modifier masks.
509      */
510     @NotFlag
511     public static final int
512         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
513         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC,
514         StaticLocalFlags                  = LocalClassFlags | STATIC | INTERFACE,
515         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
516         MemberStaticClassFlags            = MemberClassFlags | STATIC,
517         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
518         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
519         VarFlags                          = AccessFlags | FINAL | STATIC |
520                                             VOLATILE | TRANSIENT | ENUM,
521         ConstructorFlags                  = AccessFlags,
522         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
523         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
524                                             SYNCHRONIZED | FINAL | STRICTFP,
525         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
526                                             SYNCHRONIZED | FINAL | STRICTFP;
527     @NotFlag
528     public static final long
529         //NOTE: flags in ExtendedStandardFlags cannot be overlayed across Symbol kinds:
530         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED,
531         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED,
532         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED,
533         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED,
534         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED,



535         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
536         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
537         LocalVarFlags                     = FINAL | PARAMETER,
538         ReceiverParamFlags                = PARAMETER;
539 
540     public static Set<Modifier> asModifierSet(long flags) {
541         Set<Modifier> modifiers = modifierSets.get(flags);
542         if (modifiers == null) {
543             modifiers = java.util.EnumSet.noneOf(Modifier.class);
544             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
545             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
546             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
547             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
548             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
549             if (0 != (flags & SEALED))    modifiers.add(Modifier.SEALED);
550             if (0 != (flags & NON_SEALED))
551                                           modifiers.add(Modifier.NON_SEALED);
552             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
553             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
554             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
555             if (0 != (flags & SYNCHRONIZED))
556                                           modifiers.add(Modifier.SYNCHRONIZED);
557             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
558             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
559             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);

560             modifiers = Collections.unmodifiableSet(modifiers);
561             modifierSets.put(flags, modifiers);
562         }
563         return modifiers;
564     }
565 
566     // Cache of modifier sets.
567     private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64);
568 
569     public static boolean isStatic(Symbol symbol) {
570         return (symbol.flags() & STATIC) != 0;
571     }
572 
573     public static boolean isEnum(Symbol symbol) {
574         return (symbol.flags() & ENUM) != 0;
575     }
576 
577     public static boolean isConstant(Symbol.VarSymbol symbol) {
578         return symbol.getConstValue() != null;
579     }

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})

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.

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     }
< prev index next >