01: // Copyright (c) 1997 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.bytecode;
05:
06: /** Access flags. */
07: /* When using JDK 1.1, replace this class by java.lang.reflec.Modifiers. */
08:
09: public class Access {
10: static public final short PUBLIC = 0x0001;
11: static public final short PRIVATE = 0x0002;
12: static public final short PROTECTED = 0x0004;
13: static public final short STATIC = 0x0008;
14: static public final short FINAL = 0x0010;
15: static public final short SUPER = 0x0020;
16: static public final short SYNCHRONIZED = 0x0020;
17: static public final short VOLATILE = 0x0040;
18: static public final short BRIDGE = 0x0040;
19: static public final short TRANSIENT = 0x0080;
20: static public final short VARARGS = 0x0080;
21: static public final short NATIVE = 0x0100;
22: static public final short INTERFACE = 0x0200;
23: static public final short ABSTRACT = 0x0400;
24: static public final short STRICT = 0x0800;
25: static public final short SYNTHETIC = 0x1000;
26: static public final short ANNOTATION = 0x2000;
27: static public final short ENUM = 0x4000;
28: // unassigned 0x8000
29:
30: public static final short CLASS_MODIFIERS = (short) (PUBLIC | FINAL
31: | SUPER | INTERFACE | ABSTRACT | SYNTHETIC | ANNOTATION | ENUM);
32: public static final short FIELD_MODIFIERS = (short) (PUBLIC
33: | PRIVATE | PROTECTED | STATIC | FINAL | VOLATILE
34: | TRANSIENT | SYNTHETIC | ENUM);
35: public static final short METHOD_MODIFIERS = (short) (PUBLIC
36: | PRIVATE | PROTECTED | STATIC | FINAL | SYNCHRONIZED
37: | BRIDGE | VARARGS | NATIVE | ABSTRACT | STRICT | SYNTHETIC);
38:
39: public static String toString(int flags) {
40: return toString(flags, '\0');
41: }
42:
43: /** Return a string naming the access bits in flags.
44: * @param kind 'C' for a class, 'M' for a method, 'F' for a field.
45: */
46: public static String toString(int flags, char kind) {
47: short mask = (kind == 'C' ? CLASS_MODIFIERS
48: : kind == 'F' ? FIELD_MODIFIERS
49: : kind == 'M' ? METHOD_MODIFIERS
50: : (CLASS_MODIFIERS | FIELD_MODIFIERS | METHOD_MODIFIERS));
51: short bad_flags = (short) (flags & ~mask);
52: flags &= mask;
53: StringBuffer buf = new StringBuffer();
54: if ((flags & PUBLIC) != 0)
55: buf.append(" public");
56: if ((flags & PRIVATE) != 0)
57: buf.append(" private");
58: if ((flags & PROTECTED) != 0)
59: buf.append(" protected");
60: if ((flags & STATIC) != 0)
61: buf.append(" static");
62: if ((flags & FINAL) != 0)
63: buf.append(" final");
64: if ((flags & SYNCHRONIZED) != 0)
65: buf.append(kind == 'C' ? " super" : " synchronized");
66: if ((flags & VOLATILE) != 0)
67: buf.append(kind == 'M' ? " bridge" : " volatile");
68: if ((flags & TRANSIENT) != 0)
69: buf.append(kind == 'M' ? " varargs" : " transient");
70: if ((flags & NATIVE) != 0)
71: buf.append(" native");
72: if ((flags & INTERFACE) != 0)
73: buf.append(" interface");
74: if ((flags & ABSTRACT) != 0)
75: buf.append(" abstract");
76: if ((flags & STRICT) != 0)
77: buf.append(" strict");
78: if ((flags & ENUM) != 0)
79: buf.append(" enum");
80: if ((flags & SYNTHETIC) != 0)
81: buf.append(" synthetic");
82: if ((flags & ANNOTATION) != 0)
83: buf.append(" annotation");
84: if (bad_flags != 0) {
85: buf.append(" unknown-flags:0x");
86: buf.append(Integer.toHexString(bad_flags));
87: }
88: return buf.toString();
89: }
90: }
|