1    
2    /*
3    
4      The author of this software is Ian Kaplan
5      Bear Products International
6      www.bearcave.com
7      iank@bearcave.com
8    
9      Copyright (c) Ian Kaplan, 1999, 2000
10   
11     See copyright file for usage and licensing
12   
13   */
14   
15   package util;
16   
17   /*
18    * accString
19    *
20   
21      The class constructor is passed an access value
22      and the class initializes to the associated
23      string.
24   
25    */
26   public final class accString implements access_and_modifier_flags {
27   
28     private static String getName( int val ) {
29       String str = null;
30   
31       switch ( val ) {
32       case ACC_PUBLIC:
33         str = "public";
34         break;
35       case ACC_PRIVATE:
36         str = "private";
37         break;
38       case ACC_PROTECTED:
39         str = "protected";
40         break;
41       case ACC_STATIC:
42         str = "static";
43         break;
44       case ACC_FINAL:
45         str = "final";
46         break;
47       case ACC_SYNC:
48         str = "synchronized";
49         break;
50       case ACC_VOLATILE:
51         str = "volatile";
52         break;
53       case ACC_TRANSIENT:
54         str = "transient";
55         break;
56       case ACC_NATIVE:
57         str = "native";
58         break;
59       case ACC_INTERFACE:
60         str = "interface ";
61         break;
62       case ACC_ABSTRACT:
63         str = "abstract";
64         break;
65       case ACC_STRICT:
66         str = "strict";
67         break;
68       } // switch
69       return str;
70     } // getName
71   
72     
73     //
74     // toString
75     // 
76     // This function is passed an access or modifier bitmap.  It
77     // returns a string with the equivalent names.
78     //
79     public static String toString( int mod, boolean isMethod ) {
80       String modStr = null;
81   
82       if (mod > 0) {
83         int mask, cur_mod;
84         boolean firstName = true;
85         
86         for (mask = 1; mask < 0x0010000; mask = mask << 1) {
87   	cur_mod = mod & mask;
88   	if (cur_mod != 0) {
89   
90   	  // ACC_SYNCHRONIZED and ACC_SUPER have the same value.
91   	  // If a method is being processed then the value
92   	  // indicates a "synchronized" modifier.
93   	  if (cur_mod == ACC_SYNC && (!isMethod))
94   	    continue;
95   
96   	  if (! firstName) {
97   	    modStr = modStr + " " + getName( cur_mod );
98   	  }
99   	  else {
100  	    modStr = getName( cur_mod );
101  	    firstName = false;
102  	  }
103  	}
104        } // for
105      } // if
106  
107      return modStr;
108    } // toString
109  
110  } // accString
111