KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > bytecode > Access


1 // Copyright (c) 1997 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.bytecode;
5
6 /** Access flags. */
7 /* When using JDK 1.1, replace this class by java.lang.reflec.Modifiers. */
8
9 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
31     = (short)(PUBLIC|FINAL|SUPER|INTERFACE|ABSTRACT|SYNTHETIC|ANNOTATION|ENUM);
32   public static final short FIELD_MODIFIERS
33     = (short)(PUBLIC|PRIVATE|PROTECTED|STATIC|FINAL
34           |VOLATILE|TRANSIENT|SYNTHETIC|ENUM);
35   public static final short METHOD_MODIFIERS
36     = (short)(PUBLIC|PRIVATE|PROTECTED|STATIC|FINAL|SYNCHRONIZED
37           |BRIDGE|VARARGS|NATIVE|ABSTRACT|STRICT|SYNTHETIC);
38
39   public static String JavaDoc toString(int flags)
40   {
41     return toString(flags, '\0');
42   }
43
44   /** Return a string naming the access bits in flags.
45    * @param kind 'C' for a class, 'M' for a method, 'F' for a field.
46    */

47   public static String JavaDoc toString(int flags, char kind)
48   {
49     short mask
50       = (kind == 'C' ? CLASS_MODIFIERS
51      : kind == 'F' ? FIELD_MODIFIERS
52      : kind == 'M' ? METHOD_MODIFIERS
53      : (CLASS_MODIFIERS|FIELD_MODIFIERS|METHOD_MODIFIERS));
54     short bad_flags = (short) (flags & ~mask);
55     flags &= mask;
56     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
57     if ((flags & PUBLIC) != 0) buf.append(" public");
58     if ((flags & PRIVATE) != 0) buf.append(" private");
59     if ((flags & PROTECTED) != 0) buf.append(" protected");
60     if ((flags & STATIC) != 0) buf.append(" static");
61     if ((flags & FINAL) != 0) buf.append(" final");
62     if ((flags & SYNCHRONIZED) != 0)
63       buf.append(kind == 'C' ? " super" : " synchronized");
64     if ((flags & VOLATILE) != 0)
65       buf.append(kind == 'M' ? " bridge" : " volatile");
66     if ((flags & TRANSIENT) != 0)
67       buf.append(kind == 'M' ? " varargs" : " transient");
68     if ((flags & NATIVE) != 0) buf.append(" native");
69     if ((flags & INTERFACE) != 0) buf.append(" interface");
70     if ((flags & ABSTRACT) != 0) buf.append(" abstract");
71     if ((flags & STRICT) != 0) buf.append(" strict");
72     if ((flags & ENUM) != 0) buf.append(" enum");
73     if ((flags & SYNTHETIC) != 0) buf.append(" synthetic");
74     if ((flags & ANNOTATION) != 0) buf.append(" annotation");
75     if (bad_flags != 0)
76       {
77     buf.append(" unknown-flags:0x");
78     buf.append(Integer.toHexString(bad_flags));
79       }
80     return buf.toString();
81   }
82 }
83
Popular Tags