001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdi.internal;
011:
012: import java.lang.reflect.Field;
013: import java.lang.reflect.Modifier;
014:
015: import com.sun.jdi.Accessible;
016:
017: /**
018: * this class implements the corresponding interfaces
019: * declared by the JDI specification. See the com.sun.jdi package
020: * for more information.
021: *
022: */
023: public abstract class AccessibleImpl extends MirrorImpl implements
024: Accessible {
025: /** Modifier bit flag: Is synthetic. see MODIFIER_ACC_SYNTHETIC. */
026: public static final int MODIFIER_SYNTHETIC = 0xf0000000;
027: /** Modifier bit flag: Is public; may be accessed from outside its package. */
028: public static final int MODIFIER_ACC_PUBLIC = 0x0001;
029: /** Modifier bit flag: Is private; usable only within the defining class. */
030: public static final int MODIFIER_ACC_PRIVATE = 0x0002;
031: /** Modifier bit flag: Is protected; may be accessed within subclasses. */
032: public static final int MODIFIER_ACC_PROTECTED = 0x0004;
033: /** Modifier bit flag: Is static. */
034: public static final int MODIFIER_ACC_STATIC = 0x0008;
035: /** Modifier bit flag: Is final; no overriding is allowed. */
036: public static final int MODIFIER_ACC_FINAL = 0x0010;
037: /** Modifier bit flag: Is synchronized; wrap use in monitor lock. */
038: public static final int MODIFIER_ACC_SYNCHRONIZED = 0x0020;
039: /** Modifier bit flag: Treat superclass methods specially in invokespecial. */
040: public static final int MODIFIER_ACC_SUPER = 0x0020;
041: /** Modifier bit flag: Is bridge; the method is a synthetic method created to support generic types. */
042: public static final int MODIFIER_ACC_BRIDGE = 0x0040;
043: /** Modifier bit flag: Is volitile; cannot be reached. */
044: public static final int MODIFIER_ACC_VOLITILE = 0x0040;
045: /** Modifier bit flag: Is transient; not written or read by a persistent object manager. */
046: public static final int MODIFIER_ACC_TRANSIENT = 0x0080;
047: /** Modifier bit flag: Is varargs; the method has been declared with variable number of arguments. */
048: public static final int MODIFIER_ACC_VARARGS = 0x0080;
049: /** Modifier bit flag: Is enum; the field hold an element of an enumerated type. */
050: public static final int MODIFIER_ACC_ENUM = 0x0100;
051: /** Modifier bit flag: Is native; implemented in a language other than Java. */
052: public static final int MODIFIER_ACC_NATIVE = 0x0100;
053: /** Modifier bit flag: Is abstract; no implementation is provided. */
054: public static final int MODIFIER_ACC_ABSTRACT = 0x0400;
055: /** Modifier bit flag: Is strict; the method floating-point mode is FP-strict*/
056: public static final int MODIFIER_ACC_STRICT = 0x0800;
057: /** Modifier bit flag: Is synthetic. see MODIFIER_SYNTHETIC. */
058: public static final int MODIFIER_ACC_SYNTHETIC = 0x1000;
059:
060: /** Mapping of command codes to strings. */
061: private static String[] fgModifiers = null;
062:
063: /**
064: * Creates new instance.
065: */
066: public AccessibleImpl(String description, VirtualMachineImpl vmImpl) {
067: super (description, vmImpl);
068: }
069:
070: /**
071: * @return Returns true if object is package private.
072: */
073: public boolean isPackagePrivate() {
074: return !(isPrivate() || isPublic() || isProtected());
075: }
076:
077: /**
078: * @return Returns true if object is private.
079: */
080: public boolean isPrivate() {
081: return (modifiers() & MODIFIER_ACC_PRIVATE) != 0;
082: }
083:
084: /**
085: * @return Returns true if object is pubic.
086: */
087: public boolean isPublic() {
088: return (modifiers() & MODIFIER_ACC_PUBLIC) != 0;
089: }
090:
091: /**
092: * @return Returns true if object is protected.
093: */
094: public boolean isProtected() {
095: return (modifiers() & MODIFIER_ACC_PROTECTED) != 0;
096: }
097:
098: /**
099: * Retrieves constant mappings.
100: */
101: public static void getConstantMaps() {
102: if (fgModifiers != null) {
103: return;
104: }
105:
106: Field[] fields = AccessibleImpl.class.getDeclaredFields();
107: fgModifiers = new String[32];
108:
109: for (int i = 0; i < fields.length; i++) {
110: Field field = fields[i];
111: int modifiers = field.getModifiers();
112: if ((modifiers & Modifier.PUBLIC) == 0
113: || (modifiers & Modifier.STATIC) == 0
114: || (modifiers & Modifier.FINAL) == 0)
115: continue;
116:
117: String name = field.getName();
118: if (!name.startsWith("MODIFIER_")) {//$NON-NLS-1$
119: continue;
120: }
121:
122: name = name.substring(9);
123:
124: try {
125: int value = field.getInt(null);
126:
127: for (int j = 0; j < 32; j++) {
128: if ((1 << j & value) != 0) {
129: fgModifiers[j] = name;
130: break;
131: }
132: }
133: } catch (IllegalAccessException e) {
134: // Will not occur for own class.
135: } catch (IllegalArgumentException e) {
136: // Should not occur.
137: // We should take care that all public static final constants
138: // in this class are numbers that are convertible to int.
139: }
140: }
141: }
142:
143: /**
144: * @return Returns an array with string representations of tags.
145: */
146: public static String[] getModifierStrings() {
147: getConstantMaps();
148: return fgModifiers;
149: }
150: }
|