Fri, 09 May 2014 20:33:21 -0700
8041424: 8u20 l10n resource file translation update 1
Reviewed-by: naoto, yhuang
1 /*
2 * Copyright (c) 1999, 2013, 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 */
26 package com.sun.tools.javac.code;
28 import java.util.Collections;
29 import java.util.EnumSet;
30 import java.util.Map;
31 import java.util.Set;
33 import javax.lang.model.element.Modifier;
35 import com.sun.tools.javac.util.Assert;
37 /** Access flags and other modifiers for Java classes and members.
38 *
39 * <p><b>This is NOT part of any supported API.
40 * If you write code that depends on this, you do so at your own risk.
41 * This code and its internal interfaces are subject to change or
42 * deletion without notice.</b>
43 */
44 public class Flags {
46 private Flags() {} // uninstantiable
48 public static String toString(long flags) {
49 StringBuilder buf = new StringBuilder();
50 String sep = "";
51 for (Flag flag : asFlagSet(flags)) {
52 buf.append(sep);
53 buf.append(flag);
54 sep = " ";
55 }
56 return buf.toString();
57 }
59 public static EnumSet<Flag> asFlagSet(long flags) {
60 EnumSet<Flag> flagSet = EnumSet.noneOf(Flag.class);
61 for (Flag flag : Flag.values()) {
62 if ((flags & flag.value) != 0) {
63 flagSet.add(flag);
64 flags &= ~flag.value;
65 }
66 }
67 Assert.check(flags == 0, "Flags parameter contains unknown flags " + flags);
68 return flagSet;
69 }
71 /* Standard Java flags.
72 */
73 public static final int PUBLIC = 1;
74 public static final int PRIVATE = 1<<1;
75 public static final int PROTECTED = 1<<2;
76 public static final int STATIC = 1<<3;
77 public static final int FINAL = 1<<4;
78 public static final int SYNCHRONIZED = 1<<5;
79 public static final int VOLATILE = 1<<6;
80 public static final int TRANSIENT = 1<<7;
81 public static final int NATIVE = 1<<8;
82 public static final int INTERFACE = 1<<9;
83 public static final int ABSTRACT = 1<<10;
84 public static final int STRICTFP = 1<<11;
86 /* Flag that marks a symbol synthetic, added in classfile v49.0. */
87 public static final int SYNTHETIC = 1<<12;
89 /** Flag that marks attribute interfaces, added in classfile v49.0. */
90 public static final int ANNOTATION = 1<<13;
92 /** An enumeration type or an enumeration constant, added in
93 * classfile v49.0. */
94 public static final int ENUM = 1<<14;
96 /** Added in SE8, represents constructs implicitly declared in source. */
97 public static final int MANDATED = 1<<15;
99 public static final int StandardFlags = 0x0fff;
101 // Because the following access flags are overloaded with other
102 // bit positions, we translate them when reading and writing class
103 // files into unique bits positions: ACC_SYNTHETIC <-> SYNTHETIC,
104 // for example.
105 public static final int ACC_SUPER = 0x0020;
106 public static final int ACC_BRIDGE = 0x0040;
107 public static final int ACC_VARARGS = 0x0080;
109 /*****************************************
110 * Internal compiler flags (no bits in the lower 16).
111 *****************************************/
113 /** Flag is set if symbol is deprecated.
114 */
115 public static final int DEPRECATED = 1<<17;
117 /** Flag is set for a variable symbol if the variable's definition
118 * has an initializer part.
119 */
120 public static final int HASINIT = 1<<18;
122 /** Flag is set for compiler-generated anonymous method symbols
123 * that `own' an initializer block.
124 */
125 public static final int BLOCK = 1<<20;
127 /** Flag is set for compiler-generated abstract methods that implement
128 * an interface method (Miranda methods).
129 */
130 public static final int IPROXY = 1<<21;
132 /** Flag is set for nested classes that do not access instance members
133 * or `this' of an outer class and therefore don't need to be passed
134 * a this$n reference. This value is currently set only for anonymous
135 * classes in superclass constructor calls and only for pre 1.4 targets.
136 * todo: use this value for optimizing away this$n parameters in
137 * other cases.
138 */
139 public static final int NOOUTERTHIS = 1<<22;
141 /** Flag is set for package symbols if a package has a member or
142 * directory and therefore exists.
143 */
144 public static final int EXISTS = 1<<23;
146 /** Flag is set for compiler-generated compound classes
147 * representing multiple variable bounds
148 */
149 public static final int COMPOUND = 1<<24;
151 /** Flag is set for class symbols if a class file was found for this class.
152 */
153 public static final int CLASS_SEEN = 1<<25;
155 /** Flag is set for class symbols if a source file was found for this
156 * class.
157 */
158 public static final int SOURCE_SEEN = 1<<26;
160 /* State flags (are reset during compilation).
161 */
163 /** Flag for class symbols is set and later re-set as a lock in
164 * Enter to detect cycles in the superclass/superinterface
165 * relations. Similarly for constructor call cycle detection in
166 * Attr.
167 */
168 public static final int LOCKED = 1<<27;
170 /** Flag for class symbols is set and later re-set to indicate that a class
171 * has been entered but has not yet been attributed.
172 */
173 public static final int UNATTRIBUTED = 1<<28;
175 /** Flag for synthesized default constructors of anonymous classes.
176 */
177 public static final int ANONCONSTR = 1<<29;
179 /** Flag for class symbols to indicate it has been checked and found
180 * acyclic.
181 */
182 public static final int ACYCLIC = 1<<30;
184 /** Flag that marks bridge methods.
185 */
186 public static final long BRIDGE = 1L<<31;
188 /** Flag that marks formal parameters.
189 */
190 public static final long PARAMETER = 1L<<33;
192 /** Flag that marks varargs methods.
193 */
194 public static final long VARARGS = 1L<<34;
196 /** Flag for annotation type symbols to indicate it has been
197 * checked and found acyclic.
198 */
199 public static final long ACYCLIC_ANN = 1L<<35;
201 /** Flag that marks a generated default constructor.
202 */
203 public static final long GENERATEDCONSTR = 1L<<36;
205 /** Flag that marks a hypothetical method that need not really be
206 * generated in the binary, but is present in the symbol table to
207 * simplify checking for erasure clashes - also used for 292 poly sig methods.
208 */
209 public static final long HYPOTHETICAL = 1L<<37;
211 /**
212 * Flag that marks an internal proprietary class.
213 */
214 public static final long PROPRIETARY = 1L<<38;
216 /**
217 * Flag that marks a multi-catch parameter.
218 */
219 public static final long UNION = 1L<<39;
221 /**
222 * Flag that marks a special kind of bridge method (the ones that
223 * come from restricted supertype bounds).
224 */
225 public static final long OVERRIDE_BRIDGE = 1L<<40;
227 /**
228 * Flag that marks an 'effectively final' local variable.
229 */
230 public static final long EFFECTIVELY_FINAL = 1L<<41;
232 /**
233 * Flag that marks non-override equivalent methods with the same signature.
234 */
235 public static final long CLASH = 1L<<42;
237 /**
238 * Flag that marks either a default method or an interface containing default methods.
239 */
240 public static final long DEFAULT = 1L<<43;
242 /**
243 * Flag that marks class as auxiliary, ie a non-public class following
244 * the public class in a source file, that could block implicit compilation.
245 */
246 public static final long AUXILIARY = 1L<<44;
248 /**
249 * Flag that marks that a symbol is not available in the current profile
250 */
251 public static final long NOT_IN_PROFILE = 1L<<45;
253 /**
254 * Flag that indicates that an override error has been detected by Check.
255 */
256 public static final long BAD_OVERRIDE = 1L<<45;
258 /**
259 * Flag that indicates a signature polymorphic method (292).
260 */
261 public static final long SIGNATURE_POLYMORPHIC = 1L<<46;
263 /**
264 * Flag that indicates that an inference variable is used in a 'throws' clause.
265 */
266 public static final long THROWS = 1L<<47;
268 /**
269 * Flag that marks potentially ambiguous overloads
270 */
271 public static final long POTENTIALLY_AMBIGUOUS = 1L<<48;
273 /**
274 * Flag that marks a synthetic method body for a lambda expression
275 */
276 public static final long LAMBDA_METHOD = 1L<<49;
278 /** Modifier masks.
279 */
280 public static final int
281 AccessFlags = PUBLIC | PROTECTED | PRIVATE,
282 LocalClassFlags = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC,
283 MemberClassFlags = LocalClassFlags | INTERFACE | AccessFlags,
284 ClassFlags = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
285 InterfaceVarFlags = FINAL | STATIC | PUBLIC,
286 VarFlags = AccessFlags | FINAL | STATIC |
287 VOLATILE | TRANSIENT | ENUM,
288 ConstructorFlags = AccessFlags,
289 InterfaceMethodFlags = ABSTRACT | PUBLIC,
290 MethodFlags = AccessFlags | ABSTRACT | STATIC | NATIVE |
291 SYNCHRONIZED | FINAL | STRICTFP;
292 public static final long
293 ExtendedStandardFlags = (long)StandardFlags | DEFAULT,
294 ModifierFlags = ((long)StandardFlags & ~INTERFACE) | DEFAULT,
295 InterfaceMethodMask = ABSTRACT | STATIC | PUBLIC | STRICTFP | DEFAULT,
296 AnnotationTypeElementMask = ABSTRACT | PUBLIC,
297 LocalVarFlags = FINAL | PARAMETER;
300 public static Set<Modifier> asModifierSet(long flags) {
301 Set<Modifier> modifiers = modifierSets.get(flags);
302 if (modifiers == null) {
303 modifiers = java.util.EnumSet.noneOf(Modifier.class);
304 if (0 != (flags & PUBLIC)) modifiers.add(Modifier.PUBLIC);
305 if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
306 if (0 != (flags & PRIVATE)) modifiers.add(Modifier.PRIVATE);
307 if (0 != (flags & ABSTRACT)) modifiers.add(Modifier.ABSTRACT);
308 if (0 != (flags & STATIC)) modifiers.add(Modifier.STATIC);
309 if (0 != (flags & FINAL)) modifiers.add(Modifier.FINAL);
310 if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
311 if (0 != (flags & VOLATILE)) modifiers.add(Modifier.VOLATILE);
312 if (0 != (flags & SYNCHRONIZED))
313 modifiers.add(Modifier.SYNCHRONIZED);
314 if (0 != (flags & NATIVE)) modifiers.add(Modifier.NATIVE);
315 if (0 != (flags & STRICTFP)) modifiers.add(Modifier.STRICTFP);
316 if (0 != (flags & DEFAULT)) modifiers.add(Modifier.DEFAULT);
317 modifiers = Collections.unmodifiableSet(modifiers);
318 modifierSets.put(flags, modifiers);
319 }
320 return modifiers;
321 }
323 // Cache of modifier sets.
324 private static final Map<Long, Set<Modifier>> modifierSets =
325 new java.util.concurrent.ConcurrentHashMap<Long, Set<Modifier>>(64);
327 public static boolean isStatic(Symbol symbol) {
328 return (symbol.flags() & STATIC) != 0;
329 }
331 public static boolean isEnum(Symbol symbol) {
332 return (symbol.flags() & ENUM) != 0;
333 }
335 public static boolean isConstant(Symbol.VarSymbol symbol) {
336 return symbol.getConstValue() != null;
337 }
340 public enum Flag {
341 PUBLIC(Flags.PUBLIC),
342 PRIVATE(Flags.PRIVATE),
343 PROTECTED(Flags.PROTECTED),
344 STATIC(Flags.STATIC),
345 FINAL(Flags.FINAL),
346 SYNCHRONIZED(Flags.SYNCHRONIZED),
347 VOLATILE(Flags.VOLATILE),
348 TRANSIENT(Flags.TRANSIENT),
349 NATIVE(Flags.NATIVE),
350 INTERFACE(Flags.INTERFACE),
351 ABSTRACT(Flags.ABSTRACT),
352 DEFAULT(Flags.DEFAULT),
353 STRICTFP(Flags.STRICTFP),
354 BRIDGE(Flags.BRIDGE),
355 SYNTHETIC(Flags.SYNTHETIC),
356 ANNOTATION(Flags.ANNOTATION),
357 DEPRECATED(Flags.DEPRECATED),
358 HASINIT(Flags.HASINIT),
359 BLOCK(Flags.BLOCK),
360 ENUM(Flags.ENUM),
361 MANDATED(Flags.MANDATED),
362 IPROXY(Flags.IPROXY),
363 NOOUTERTHIS(Flags.NOOUTERTHIS),
364 EXISTS(Flags.EXISTS),
365 COMPOUND(Flags.COMPOUND),
366 CLASS_SEEN(Flags.CLASS_SEEN),
367 SOURCE_SEEN(Flags.SOURCE_SEEN),
368 LOCKED(Flags.LOCKED),
369 UNATTRIBUTED(Flags.UNATTRIBUTED),
370 ANONCONSTR(Flags.ANONCONSTR),
371 ACYCLIC(Flags.ACYCLIC),
372 PARAMETER(Flags.PARAMETER),
373 VARARGS(Flags.VARARGS),
374 ACYCLIC_ANN(Flags.ACYCLIC_ANN),
375 GENERATEDCONSTR(Flags.GENERATEDCONSTR),
376 HYPOTHETICAL(Flags.HYPOTHETICAL),
377 PROPRIETARY(Flags.PROPRIETARY),
378 UNION(Flags.UNION),
379 OVERRIDE_BRIDGE(Flags.OVERRIDE_BRIDGE),
380 EFFECTIVELY_FINAL(Flags.EFFECTIVELY_FINAL),
381 CLASH(Flags.CLASH),
382 AUXILIARY(Flags.AUXILIARY),
383 NOT_IN_PROFILE(Flags.NOT_IN_PROFILE),
384 BAD_OVERRIDE(Flags.BAD_OVERRIDE),
385 SIGNATURE_POLYMORPHIC(Flags.SIGNATURE_POLYMORPHIC),
386 THROWS(Flags.THROWS),
387 LAMBDA_METHOD(Flags.LAMBDA_METHOD);
389 Flag(long flag) {
390 this.value = flag;
391 this.lowercaseName = name().toLowerCase();
392 }
394 @Override
395 public String toString() {
396 return lowercaseName;
397 }
399 final long value;
400 final String lowercaseName;
401 }
403 }