Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / vm / reference / java / lang / VMClass.java
blob1b4c13e6b5a176cab448944c3e4fd6b4d8ada546
1 /* VMClass.java -- VM Specific Class methods
2 Copyright (C) 2003, 2004 Free Software Foundation
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.lang;
40 import java.lang.reflect.Array;
41 import java.lang.reflect.Constructor;
42 import java.lang.reflect.Field;
43 import java.lang.reflect.Method;
44 import java.lang.reflect.Modifier;
47 * This class is a reference version, mainly for compiling a class library
48 * jar. It is likely that VM implementers replace this with their own
49 * version that can communicate effectively with the VM.
52 /**
54 * @author Etienne Gagnon <etienne.gagnon@uqam.ca>
55 * @author Archie Cobbs <archie@dellroad.org>
56 * @author C. Brian Jones <cbj@gnu.org>
58 final class VMClass
61 // Only static methods. Cannot be instantiated.
62 private VMClass()
66 /**
67 * Discover whether an Object is an instance of this Class. Think of it
68 * as almost like <code>o instanceof (this class)</code>.
70 * @param klass the Class object that's calling us
71 * @param o the Object to check
72 * @return whether o is an instance of this class
73 * @since 1.1
75 static native boolean isInstance(Class klass, Object o);
77 /**
78 * Discover whether an instance of the Class parameter would be an
79 * instance of this Class as well. Think of doing
80 * <code>isInstance(c.newInstance())</code> or even
81 * <code>c.newInstance() instanceof (this class)</code>. While this
82 * checks widening conversions for objects, it must be exact for primitive
83 * types.
85 * @param klass the Class object that's calling us
86 * @param c the class to check
87 * @return whether an instance of c would be an instance of this class
88 * as well
89 * @throws NullPointerException if c is null
90 * @since 1.1
92 static native boolean isAssignableFrom(Class klass, Class c);
94 /**
95 * Check whether this class is an interface or not. Array types are not
96 * interfaces.
98 * @param klass the Class object that's calling us
99 * @return whether this class is an interface or not
101 static native boolean isInterface(Class klass);
104 * Return whether this class is a primitive type. A primitive type class
105 * is a class representing a kind of "placeholder" for the various
106 * primitive types, or void. You can access the various primitive type
107 * classes through java.lang.Boolean.TYPE, java.lang.Integer.TYPE, etc.,
108 * or through boolean.class, int.class, etc.
110 * @param klass the Class object that's calling us
111 * @return whether this class is a primitive type
112 * @see Boolean#TYPE
113 * @see Byte#TYPE
114 * @see Character#TYPE
115 * @see Short#TYPE
116 * @see Integer#TYPE
117 * @see Long#TYPE
118 * @see Float#TYPE
119 * @see Double#TYPE
120 * @see Void#TYPE
121 * @since 1.1
123 static native boolean isPrimitive(Class klass);
126 * Get the name of this class, separated by dots for package separators.
127 * Primitive types and arrays are encoded as:
128 * <pre>
129 * boolean Z
130 * byte B
131 * char C
132 * short S
133 * int I
134 * long J
135 * float F
136 * double D
137 * void V
138 * array type [<em>element type</em>
139 * class or interface, alone: &lt;dotted name&gt;
140 * class or interface, as element type: L&lt;dotted name&gt;;
142 * @param klass the Class object that's calling us
143 * @return the name of this class
145 static native String getName(Class klass);
148 * Get the direct superclass of this class. If this is an interface,
149 * Object, a primitive type, or void, it will return null. If this is an
150 * array type, it will return Object.
152 * @param klass the Class object that's calling us
153 * @return the direct superclass of this class
155 static native Class getSuperclass(Class klass);
158 * Get the interfaces this class <EM>directly</EM> implements, in the
159 * order that they were declared. This returns an empty array, not null,
160 * for Object, primitives, void, and classes or interfaces with no direct
161 * superinterface. Array types return Cloneable and Serializable.
163 * @param klass the Class object that's calling us
164 * @return the interfaces this class directly implements
166 static native Class[] getInterfaces(Class klass);
169 * If this is an array, get the Class representing the type of array.
170 * Examples: "[[Ljava.lang.String;" would return "[Ljava.lang.String;", and
171 * calling getComponentType on that would give "java.lang.String". If
172 * this is not an array, returns null.
174 * @param klass the Class object that's calling us
175 * @return the array type of this class, or null
176 * @see Array
177 * @since 1.1
179 static native Class getComponentType(Class klass);
182 * Get the modifiers of this class. These can be decoded using Modifier,
183 * and is limited to one of public, protected, or private, and any of
184 * final, static, abstract, or interface. An array class has the same
185 * public, protected, or private modifier as its component type, and is
186 * marked final but not an interface. Primitive types and void are marked
187 * public and final, but not an interface.
189 * @param klass the Class object that's calling us
190 * @param ignoreInnerClassesAttrib if set, return the real modifiers, not
191 * the ones specified in the InnerClasses attribute.
192 * @return the modifiers of this class
193 * @see Modifier
194 * @since 1.1
196 static native int getModifiers(Class klass, boolean ignoreInnerClassesAttrib);
199 * If this is a nested or inner class, return the class that declared it.
200 * If not, return null.
202 * @param klass the Class object that's calling us
203 * @return the declaring class of this class
204 * @since 1.1
206 static native Class getDeclaringClass(Class klass);
209 * Like <code>getDeclaredClasses()</code> but without the security checks.
211 * @param klass the Class object that's calling us
212 * @param publicOnly Only public classes should be returned
214 static native Class[] getDeclaredClasses(Class klass, boolean publicOnly);
217 * Like <code>getDeclaredFields()</code> but without the security checks.
219 * @param klass the Class object that's calling us
220 * @param publicOnly Only public fields should be returned
222 static native Field[] getDeclaredFields(Class klass, boolean publicOnly);
225 * Like <code>getDeclaredMethods()</code> but without the security checks.
227 * @param klass the Class object that's calling us
228 * @param publicOnly Only public methods should be returned
230 static native Method[] getDeclaredMethods(Class klass, boolean publicOnly);
233 * Like <code>getDeclaredConstructors()</code> but without
234 * the security checks.
236 * @param klass the Class object that's calling us
237 * @param publicOnly Only public constructors should be returned
239 static native Constructor[] getDeclaredConstructors(Class klass, boolean publicOnly);
242 * Return the class loader of this class.
244 * @param klass the Class object that's calling us
245 * @return the class loader
247 static native ClassLoader getClassLoader(Class klass);
250 * Load the requested class and record the specified loader as the
251 * initiating class loader.
253 * @param name the name of the class to find
254 * @param initialize should the class initializer be run?
255 * @param loader the class loader to use (or null for the bootstrap loader)
256 * @return the Class object representing the class or null for noop
257 * @throws ClassNotFoundException if the class was not found by the
258 * class loader
259 * @throws LinkageError if linking the class fails
260 * @throws ExceptionInInitializerError if the class loads, but an exception
261 * occurs during initialization
263 static native Class forName(String name, boolean initialize,
264 ClassLoader loader)
265 throws ClassNotFoundException;
268 * Return whether this class is an array type.
270 * @param klass the Class object that's calling us
271 * @return true if this class is an array type
272 * operation
274 static native boolean isArray(Class klass);
277 * Throw a checked exception without declaring it.
279 static native void throwException(Throwable t);
281 } // class VMClass