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

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.

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

368     public static final long SEALED = 1L<<48; // part of ExtendedStandardFlags, cannot be reused
369 
370     /**
371      * Flag that marks a synthetic method body for a lambda expression
372      */
373     @Use({FlagTarget.METHOD})
374     public static final long LAMBDA_METHOD = 1L<<49;
375 
376     /**
377      * Flag that marks a synthetic local capture field in a local/anon class
378      */
379     @Use({FlagTarget.VARIABLE})
380     public static final long LOCAL_CAPTURE_FIELD = 1L<<49;
381 
382     /**
383      * Flag to control recursion in TransTypes
384      */
385     @Use({FlagTarget.CLASS})
386     public static final long TYPE_TRANSLATED = 1L<<50;
387 
388     /** Flag is set for the outer this field of an inner class.
389      */
390     @Use({FlagTarget.VARIABLE})
391     public static final long OUTER_THIS_FIELD = 1L<<50;
392 
393     /**
394      * Flag to indicate class symbol is for module-info
395      */
396     @Use({FlagTarget.CLASS})
397     public static final long MODULE = 1L<<51;
398 
399     /**
400      * Flag to indicate the given ModuleSymbol is an automatic module.
401      */
402     @Use({FlagTarget.MODULE})
403     public static final long AUTOMATIC_MODULE = 1L<<52;
404 
405     /**
406      * Flag to indicate the given PackageSymbol contains any non-.java and non-.class resources.
407      */
408     @Use({FlagTarget.PACKAGE})
409     public static final long HAS_RESOURCE = 1L<<52;
410 
411     /**
412      * Flag to indicate the given ParamSymbol has a user-friendly name filled.

508 
509     /**
510      * Flag to indicate parameters that require identity.
511      */
512     @Use({FlagTarget.VARIABLE}) //ParamSymbols only
513     public static final long REQUIRES_IDENTITY = 1L<<62;
514 
515     /**
516      * Flag to indicate type annotations have been queued for field initializers.
517      */
518     @Use({FlagTarget.VARIABLE})
519     public static final long FIELD_INIT_TYPE_ANNOTATIONS_QUEUED = 1L<<53;
520 
521     /**
522      * Flag to indicate that the class/interface was declared with the non-sealed modifier.
523      */
524     @Use({FlagTarget.CLASS})
525     @CustomToStringValue("non-sealed")
526     public static final long NON_SEALED = 1L<<63;  // part of ExtendedStandardFlags, cannot be reused
527 
528     /**
529      * Flag to indicate that a field is strict
530      */
531     @Use({FlagTarget.VARIABLE})
532     public static final long STRICT = 1L<<19; // VarSymbols
533 
534     /**
535      * Describe modifier flags as they might appear in source code, i.e.,
536      * separated by spaces and in the order suggested by JLS 8.1.1.
537      */
538     public static String toSource(long flags) {
539         return asModifierSet(flags).stream()
540           .map(Modifier::toString)
541           .collect(Collectors.joining(" "));
542     }
543 
544     /** Modifier masks.
545      */
546     @NotFlag
547     public static final int
548         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
549         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC | IDENTITY_TYPE,
550         StaticLocalClassFlags             = LocalClassFlags | STATIC | INTERFACE,
551         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
552         MemberStaticClassFlags            = MemberClassFlags | STATIC,
553         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
554         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
555         VarFlags                          = AccessFlags | FINAL | STATIC |
556                                             VOLATILE | TRANSIENT | ENUM,
557         ConstructorFlags                  = AccessFlags,
558         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
559         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
560                                             SYNCHRONIZED | FINAL | STRICTFP,
561         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
562                                             SYNCHRONIZED | FINAL | STRICTFP;
563     @NotFlag
564     public static final long
565         //NOTE: flags in ExtendedStandardFlags cannot be overlayed across Symbol kinds:
566         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED | VALUE_CLASS,
567         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED | VALUE_CLASS,
568         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED | VALUE_CLASS,
569         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED | VALUE_CLASS,
570         ExtendedLocalClassFlags           = (long) LocalClassFlags | VALUE_CLASS,
571         ExtendedStaticLocalClassFlags     = (long) StaticLocalClassFlags | VALUE_CLASS,
572         ValueFieldFlags                   = (long) VarFlags | STRICT | FINAL,
573         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED | VALUE_CLASS,
574         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
575         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
576         LocalVarFlags                     = FINAL | PARAMETER,
577         ReceiverParamFlags                = PARAMETER;
578 
579     @SuppressWarnings("preview") // allow use of VALUE_CLASS when building jdk.compiler.interim
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 >