KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > AccessibleImpl


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdi.internal;
12
13
14 import java.lang.reflect.Field JavaDoc;
15 import java.lang.reflect.Modifier JavaDoc;
16
17 import com.sun.jdi.Accessible;
18
19 /**
20  * this class implements the corresponding interfaces
21  * declared by the JDI specification. See the com.sun.jdi package
22  * for more information.
23  *
24  */

25 public abstract class AccessibleImpl extends MirrorImpl implements Accessible {
26     /** Modifier bit flag: Is synthetic. see MODIFIER_ACC_SYNTHETIC. */
27     public static final int MODIFIER_SYNTHETIC = 0xf0000000;
28     /** Modifier bit flag: Is public; may be accessed from outside its package. */
29     public static final int MODIFIER_ACC_PUBLIC = 0x0001;
30     /** Modifier bit flag: Is private; usable only within the defining class. */
31     public static final int MODIFIER_ACC_PRIVATE = 0x0002;
32     /** Modifier bit flag: Is protected; may be accessed within subclasses. */
33     public static final int MODIFIER_ACC_PROTECTED = 0x0004;
34     /** Modifier bit flag: Is static. */
35     public static final int MODIFIER_ACC_STATIC = 0x0008;
36     /** Modifier bit flag: Is final; no overriding is allowed. */
37     public static final int MODIFIER_ACC_FINAL = 0x0010;
38     /** Modifier bit flag: Is synchronized; wrap use in monitor lock. */
39     public static final int MODIFIER_ACC_SYNCHRONIZED = 0x0020;
40     /** Modifier bit flag: Treat superclass methods specially in invokespecial. */
41     public static final int MODIFIER_ACC_SUPER = 0x0020;
42     /** Modifier bit flag: Is bridge; the method is a synthetic method created to support generic types. */
43     public static final int MODIFIER_ACC_BRIDGE = 0x0040;
44     /** Modifier bit flag: Is volitile; cannot be reached. */
45     public static final int MODIFIER_ACC_VOLITILE = 0x0040;
46     /** Modifier bit flag: Is transient; not written or read by a persistent object manager. */
47     public static final int MODIFIER_ACC_TRANSIENT = 0x0080;
48     /** Modifier bit flag: Is varargs; the method has been declared with variable number of arguments. */
49     public static final int MODIFIER_ACC_VARARGS = 0x0080;
50     /** Modifier bit flag: Is enum; the field hold an element of an enumerated type. */
51     public static final int MODIFIER_ACC_ENUM = 0x0100;
52     /** Modifier bit flag: Is native; implemented in a language other than Java. */
53     public static final int MODIFIER_ACC_NATIVE = 0x0100;
54     /** Modifier bit flag: Is abstract; no implementation is provided. */
55     public static final int MODIFIER_ACC_ABSTRACT = 0x0400;
56     /** Modifier bit flag: Is strict; the method floating-point mode is FP-strict*/
57     public static final int MODIFIER_ACC_STRICT = 0x0800;
58     /** Modifier bit flag: Is synthetic. see MODIFIER_SYNTHETIC. */
59     public static final int MODIFIER_ACC_SYNTHETIC = 0x1000;
60     
61     /** Mapping of command codes to strings. */
62     private static String JavaDoc[] fgModifiers = null;
63     
64     /**
65      * Creates new instance.
66      */

67     public AccessibleImpl(String JavaDoc description, VirtualMachineImpl vmImpl) {
68         super(description, vmImpl);
69     }
70
71     /**
72      * @return Returns true if object is package private.
73      */

74     public boolean isPackagePrivate() {
75         return !(isPrivate() || isPublic() || isProtected());
76     }
77         
78     /**
79      * @return Returns true if object is private.
80      */

81     public boolean isPrivate() {
82         return (modifiers() & MODIFIER_ACC_PRIVATE) != 0;
83     }
84     
85     /**
86      * @return Returns true if object is pubic.
87      */

88     public boolean isPublic() {
89         return (modifiers() & MODIFIER_ACC_PUBLIC) != 0;
90     }
91     
92     /**
93      * @return Returns true if object is protected.
94      */

95     public boolean isProtected() {
96         return (modifiers() & MODIFIER_ACC_PROTECTED) != 0;
97     }
98     
99     /**
100      * Retrieves constant mappings.
101      */

102     public static void getConstantMaps() {
103         if (fgModifiers != null) {
104             return;
105         }
106         
107         Field JavaDoc[] fields = AccessibleImpl.class.getDeclaredFields();
108         fgModifiers = new String JavaDoc[32];
109         
110         for (int i = 0; i < fields.length; i++) {
111             Field JavaDoc field = fields[i];
112             int modifiers= field.getModifiers();
113             if ((modifiers & Modifier.PUBLIC) == 0 || (modifiers & Modifier.STATIC) == 0 || (modifiers & Modifier.FINAL) == 0)
114                 continue;
115                 
116             String JavaDoc name = field.getName();
117             if (!name.startsWith("MODIFIER_")) {//$NON-NLS-1$
118
continue;
119             }
120                 
121             name = name.substring(9);
122             
123             try {
124                 int value = field.getInt(null);
125                 
126                 for (int j = 0; j < 32; j++) {
127                     if ((1 << j & value) != 0) {
128                         fgModifiers[j]= name;
129                         break;
130                     }
131                 }
132             } catch (IllegalAccessException JavaDoc e) {
133                 // Will not occur for own class.
134
} catch (IllegalArgumentException JavaDoc e) {
135                 // Should not occur.
136
// We should take care that all public static final constants
137
// in this class are numbers that are convertible to int.
138
}
139         }
140     }
141     
142     /**
143      * @return Returns an array with string representations of tags.
144      */

145      public static String JavaDoc[] getModifierStrings() {
146         getConstantMaps();
147         return fgModifiers;
148      }
149 }
150
Popular Tags