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

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.

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     }

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     /** Variable with implicit/inferred type.
171      */
172     @Use(FlagTarget.VARIABLE)
173     public static final int VAR_VARIABLE     = 1<<21;
174 
175     /** Flag is set for compiler-generated anonymous method symbols
176      *  that `own' an initializer block.
177      */
178     @Use({FlagTarget.METHOD})
179     public static final int BLOCK            = 1<<21;
180 
181     /** Marks a type as a value class */
182     @Use({FlagTarget.CLASS})
183     public static final int VALUE_CLASS      = 1<<20;
184 
185     /** A parameter of a lambda function.
186      */
187     @Use(FlagTarget.VARIABLE)
188     public static final int LAMBDA_PARAMETER     = 1<<23;
189 
190     /** Flag is set for ClassSymbols that are being compiled from source.
191      */
192     @Use({FlagTarget.CLASS})
193     public static final int FROM_SOURCE      = 1<<21;
194 
195     /** Flag is set for nested classes that do not access instance members
196      *  or `this' of an outer class and therefore don't need to be passed
197      *  a this$n reference.  This value is currently set only for anonymous
198      *  classes in superclass constructor calls.
199      *  todo: use this value for optimizing away this$n parameters in
200      *  other cases.
201      */
202     @Use({FlagTarget.CLASS, FlagTarget.VARIABLE})
203     public static final int NOOUTERTHIS  = 1<<22;
204 
205     /** Flag is set for package symbols if a package has a member or
206      *  directory and therefore exists.
207      */
208     @Use({FlagTarget.CLASS, FlagTarget.PACKAGE})

404     public static final long HAS_RESOURCE = 1L<<52;
405 
406     /**
407      * Flag to indicate the given ParamSymbol has a user-friendly name filled.
408      */
409     @Use({FlagTarget.VARIABLE}) //ParamSymbols only
410     public static final long NAME_FILLED = 1L<<52;
411 
412     /**
413      * Flag to indicate the given ModuleSymbol is a system module.
414      */
415     @Use({FlagTarget.MODULE})
416     public static final long SYSTEM_MODULE = 1L<<53;
417 
418     /**
419      * Flag to indicate the given ClassSymbol is a value based.
420      */
421     @Use({FlagTarget.CLASS})
422     public static final long VALUE_BASED = 1L<<53;
423 
424     /**
425      * Flag to indicate the given ClassSymbol is a value based.
426      */
427     @Use({FlagTarget.CLASS})
428     public static final long MIGRATED_VALUE_CLASS = 1L<<57; //ClassSymbols only
429 
430     /**
431      * Flag to indicate the given symbol has a @Deprecated annotation.
432      */
433     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
434     public static final long DEPRECATED_ANNOTATION = 1L<<54;
435 
436     /**
437      * Flag to indicate the given symbol has been deprecated and marked for removal.
438      */
439     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
440     public static final long DEPRECATED_REMOVAL = 1L<<55;
441 
442     /**
443      * Flag to indicate the API element in question is for a preview API.
444      */
445     @Use({FlagTarget.CLASS, FlagTarget.METHOD, FlagTarget.MODULE, FlagTarget.PACKAGE, FlagTarget.TYPE_VAR, FlagTarget.VARIABLE})
446     public static final long PREVIEW_API = 1L<<56; //any Symbol kind
447 
448     /**
449      * Flag for synthesized default constructors of anonymous classes that have an enclosing expression.

509 
510     /**
511      * Flag to indicate parameters that require identity.
512      */
513     @Use({FlagTarget.VARIABLE}) //ParamSymbols only
514     public static final long REQUIRES_IDENTITY = 1L<<62;
515 
516     /**
517      * Flag to indicate type annotations have been queued for field initializers.
518      */
519     @Use({FlagTarget.VARIABLE})
520     public static final long FIELD_INIT_TYPE_ANNOTATIONS_QUEUED = 1L<<53;
521 
522     /**
523      * Flag to indicate that the class/interface was declared with the non-sealed modifier.
524      */
525     @Use({FlagTarget.CLASS})
526     @CustomToStringValue("non-sealed")
527     public static final long NON_SEALED = 1L<<63;  // part of ExtendedStandardFlags, cannot be reused
528 
529     /**
530      * Flag to indicate that a field is strict
531      */
532     @Use({FlagTarget.VARIABLE})
533     public static final long STRICT = 1L<<19; // VarSymbols
534 
535     /**
536      * Describe modifier flags as they might appear in source code, i.e.,
537      * separated by spaces and in the order suggested by JLS 8.1.1.
538      */
539     public static String toSource(long flags) {
540         return asModifierSet(flags).stream()
541           .map(Modifier::toString)
542           .collect(Collectors.joining(" "));
543     }
544 
545     /** Modifier masks.
546      */
547     @NotFlag
548     public static final int
549         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
550         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC | IDENTITY_TYPE,
551         StaticLocalClassFlags             = LocalClassFlags | STATIC | INTERFACE,
552         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
553         MemberStaticClassFlags            = MemberClassFlags | STATIC,
554         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
555         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
556         VarFlags                          = AccessFlags | FINAL | STATIC |
557                                             VOLATILE | TRANSIENT | ENUM,
558         ConstructorFlags                  = AccessFlags,
559         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
560         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
561                                             SYNCHRONIZED | FINAL | STRICTFP,
562         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
563                                             SYNCHRONIZED | FINAL | STRICTFP;
564     @NotFlag
565     public static final long
566         //NOTE: flags in ExtendedStandardFlags cannot be overlayed across Symbol kinds:
567         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED | VALUE_CLASS,
568         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED | VALUE_CLASS,
569         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED | VALUE_CLASS,
570         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED | VALUE_CLASS,
571         ExtendedLocalClassFlags           = (long) LocalClassFlags | VALUE_CLASS,
572         ExtendedStaticLocalClassFlags     = (long) StaticLocalClassFlags | VALUE_CLASS,
573         ValueFieldFlags                   = (long) VarFlags | STRICT | FINAL,
574         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED | VALUE_CLASS,
575         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
576         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
577         LocalVarFlags                     = FINAL | PARAMETER,
578         ReceiverParamFlags                = PARAMETER;
579 
580     public static Set<Modifier> asModifierSet(long flags) {
581         Set<Modifier> modifiers = modifierSets.get(flags);
582         if (modifiers == null) {
583             modifiers = java.util.EnumSet.noneOf(Modifier.class);
584             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
585             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
586             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
587             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
588             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
589             if (0 != (flags & SEALED))    modifiers.add(Modifier.SEALED);
590             if (0 != (flags & NON_SEALED))
591                                           modifiers.add(Modifier.NON_SEALED);
592             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
593             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
594             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
595             if (0 != (flags & SYNCHRONIZED))
596                                           modifiers.add(Modifier.SYNCHRONIZED);
597             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
598             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
599             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);
600             if (0 != (flags & VALUE_CLASS))     modifiers.add(Modifier.VALUE);
601             modifiers = Collections.unmodifiableSet(modifiers);
602             modifierSets.put(flags, modifiers);
603         }
604         return modifiers;
605     }
606 
607     // Cache of modifier sets.
608     private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64);
609 
610     public static boolean isStatic(Symbol symbol) {
611         return (symbol.flags() & STATIC) != 0;
612     }
613 
614     public static boolean isEnum(Symbol symbol) {
615         return (symbol.flags() & ENUM) != 0;
616     }
617 
618     public static boolean isConstant(Symbol.VarSymbol symbol) {
619         return symbol.getConstValue() != null;
620     }
< prev index next >