Initial revision
From-SVN: r102074
This commit is contained in:
parent
6f4434b39b
commit
f911ba985a
4557 changed files with 1000262 additions and 0 deletions
159
libjava/classpath/java/lang/reflect/AccessibleObject.java
Normal file
159
libjava/classpath/java/lang/reflect/AccessibleObject.java
Normal file
|
@ -0,0 +1,159 @@
|
|||
/* java.lang.reflect.AccessibleObject
|
||||
Copyright (C) 2001, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* This class is the superclass of various reflection classes, and
|
||||
* allows sufficiently trusted code to bypass normal restrictions to
|
||||
* do necessary things like invoke private methods outside of the
|
||||
* class during Serialization. If you don't have a good reason
|
||||
* to mess with this, don't try. Fortunately, there are adequate
|
||||
* security checks before you can set a reflection object as accessible.
|
||||
*
|
||||
* @author Tom Tromey (tromey@cygnus.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Field
|
||||
* @see Constructor
|
||||
* @see Method
|
||||
* @see ReflectPermission
|
||||
* @since 1.2
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class AccessibleObject
|
||||
{
|
||||
/**
|
||||
* True if this object is marked accessible, which means the reflected
|
||||
* object bypasses normal security checks.
|
||||
*/
|
||||
// default visibility for use by inherited classes
|
||||
boolean flag = false;
|
||||
|
||||
/**
|
||||
* Only the three reflection classes that extend this can create an
|
||||
* accessible object. This is not serializable for security reasons.
|
||||
*/
|
||||
protected AccessibleObject()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the accessibility status of this object.
|
||||
*
|
||||
* @return true if this object bypasses security checks
|
||||
*/
|
||||
public boolean isAccessible()
|
||||
{
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to set the flag on a number of objects with a single
|
||||
* security check. If a security manager exists, it is checked for
|
||||
* <code>ReflectPermission("suppressAccessChecks")</code>.<p>
|
||||
*
|
||||
* It is forbidden to set the accessibility flag to true on any constructor
|
||||
* for java.lang.Class. This will result in a SecurityException. If the
|
||||
* SecurityException is thrown for any of the passed AccessibleObjects,
|
||||
* the accessibility flag will be set on AccessibleObjects in the array prior
|
||||
* to the one which resulted in the exception.
|
||||
*
|
||||
* @param array the array of accessible objects
|
||||
* @param flag the desired state of accessibility, true to bypass security
|
||||
* @throws NullPointerException if array is null
|
||||
* @throws SecurityException if the request is denied
|
||||
* @see SecurityManager#checkPermission(java.security.Permission)
|
||||
* @see RuntimePermission
|
||||
*/
|
||||
public static void setAccessible(AccessibleObject[] array, boolean flag)
|
||||
{
|
||||
checkPermission();
|
||||
for (int i = 0; i < array.length; i++)
|
||||
array[i].secureSetAccessible(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the accessibility flag for this reflection object. If a security
|
||||
* manager exists, it is checked for
|
||||
* <code>ReflectPermission("suppressAccessChecks")</code>.<p>
|
||||
*
|
||||
* It is forbidden to set the accessibility flag to true on any constructor for
|
||||
* java.lang.Class. This will result in a SecurityException.
|
||||
*
|
||||
* @param flag the desired state of accessibility, true to bypass security
|
||||
* @throws NullPointerException if array is null
|
||||
* @throws SecurityException if the request is denied
|
||||
* @see SecurityManager#checkPermission(java.security.Permission)
|
||||
* @see RuntimePermission
|
||||
*/
|
||||
public void setAccessible(boolean flag)
|
||||
{
|
||||
checkPermission();
|
||||
secureSetAccessible(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the specified security check, for
|
||||
* <code>ReflectPermission("suppressAccessChecks")</code>.
|
||||
*
|
||||
* @throws SecurityException if permission is denied
|
||||
*/
|
||||
private static void checkPermission()
|
||||
{
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null)
|
||||
sm.checkPermission(new ReflectPermission("suppressAccessChecks"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actual accessibility change, this must always be invoked
|
||||
* after calling checkPermission.
|
||||
*
|
||||
* @param flag the desired status
|
||||
* @throws SecurityException if flag is true and this is a constructor
|
||||
* for <code>java.lang.Class</code>.
|
||||
*/
|
||||
private void secureSetAccessible(boolean flag)
|
||||
{
|
||||
if (flag &&
|
||||
(this instanceof Constructor
|
||||
&& ((Constructor) this).getDeclaringClass() == Class.class))
|
||||
throw new SecurityException("Cannot make object accessible: " + this);
|
||||
this.flag = flag;
|
||||
}
|
||||
}
|
675
libjava/classpath/java/lang/reflect/Array.java
Normal file
675
libjava/classpath/java/lang/reflect/Array.java
Normal file
|
@ -0,0 +1,675 @@
|
|||
/* java.lang.reflect.Array - manipulate arrays by reflection
|
||||
Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
import gnu.classpath.Configuration;
|
||||
|
||||
/**
|
||||
* Array holds static helper functions that allow you to create and
|
||||
* manipulate arrays by reflection. Operations know how to perform widening
|
||||
* conversions, but throw {@link IllegalArgumentException} if you attempt
|
||||
* a narrowing conversion. Also, when accessing primitive arrays, this
|
||||
* class performs object wrapping and unwrapping as necessary.<p>
|
||||
*
|
||||
* <B>Note:</B> This class returns and accepts types as Classes, even
|
||||
* primitive types; there are Class types defined that represent each
|
||||
* different primitive type. They are <code>java.lang.Boolean.TYPE,
|
||||
* java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
|
||||
* byte.class</code>, etc. These are not to be confused with the
|
||||
* classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
|
||||
* real classes. Note also that the shorthand <code>Object[].class</code>
|
||||
* is a convenient way to get array Classes.<p>
|
||||
*
|
||||
* <B>Performance note:</B> This class performs best when it does not have
|
||||
* to convert primitive types. The further along the chain it has to convert,
|
||||
* the worse performance will be. You're best off using the array as whatever
|
||||
* type it already is, and then converting the result. You will do even
|
||||
* worse if you do this and use the generic set() function.
|
||||
*
|
||||
* @author John Keiser
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @author Per Bothner (bothner@cygnus.com)
|
||||
* @see java.lang.Boolean#TYPE
|
||||
* @see java.lang.Byte#TYPE
|
||||
* @see java.lang.Short#TYPE
|
||||
* @see java.lang.Character#TYPE
|
||||
* @see java.lang.Integer#TYPE
|
||||
* @see java.lang.Long#TYPE
|
||||
* @see java.lang.Float#TYPE
|
||||
* @see java.lang.Double#TYPE
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class Array
|
||||
{
|
||||
static
|
||||
{
|
||||
if (Configuration.INIT_LOAD_LIBRARY)
|
||||
{
|
||||
System.loadLibrary("javalangreflect");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is uninstantiable.
|
||||
*/
|
||||
private Array()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new single-dimensioned array.
|
||||
* @param componentType the type of the array to create
|
||||
* @param length the length of the array to create
|
||||
* @return the created array, cast to an Object
|
||||
* @throws NullPointerException if <code>componentType</code> is null
|
||||
* @throws IllegalArgumentException if <code>componentType</code> is
|
||||
* <code>Void.TYPE</code>
|
||||
* @throws NegativeArraySizeException when length is less than 0
|
||||
* @throws OutOfMemoryError if memory allocation fails
|
||||
*/
|
||||
public static Object newInstance(Class componentType, int length)
|
||||
{
|
||||
if (! componentType.isPrimitive())
|
||||
return createObjectArray(componentType, length);
|
||||
if (componentType == boolean.class)
|
||||
return new boolean[length];
|
||||
if (componentType == byte.class)
|
||||
return new byte[length];
|
||||
if (componentType == char.class)
|
||||
return new char[length];
|
||||
if (componentType == short.class)
|
||||
return new short[length];
|
||||
if (componentType == int.class)
|
||||
return new int[length];
|
||||
if (componentType == long.class)
|
||||
return new long[length];
|
||||
if (componentType == float.class)
|
||||
return new float[length];
|
||||
if (componentType == double.class)
|
||||
return new double[length];
|
||||
// assert componentType == void.class
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new multi-dimensioned array. The new array has the same
|
||||
* component type as the argument class, and the number of dimensions
|
||||
* in the new array is the sum of the dimensions of the argument class
|
||||
* and the length of the argument dimensions. Virtual Machine limitations
|
||||
* forbid too many dimensions (usually 255 is the maximum); but even
|
||||
* 50 dimensions of 2 elements in each dimension would exceed your memory
|
||||
* long beforehand!
|
||||
*
|
||||
* @param componentType the type of the array to create.
|
||||
* @param dimensions the dimensions of the array to create. Each element
|
||||
* in <code>dimensions</code> makes another dimension of the new
|
||||
* array. Thus, <code>Array.newInstance(java.lang.Boolean,
|
||||
* new int[]{1,2,3})</code> is the same as
|
||||
* <code>new java.lang.Boolean[1][2][3]</code>
|
||||
* @return the created array, cast to an Object
|
||||
* @throws NullPointerException if componentType or dimension is null
|
||||
* @throws IllegalArgumentException if the the size of
|
||||
* <code>dimensions</code> is 0 or exceeds the maximum number of
|
||||
* array dimensions in the VM; or if componentType is Void.TYPE
|
||||
* @throws NegativeArraySizeException when any of the dimensions is less
|
||||
* than 0
|
||||
* @throws OutOfMemoryError if memory allocation fails
|
||||
*/
|
||||
public static Object newInstance(Class componentType, int[] dimensions)
|
||||
{
|
||||
if (dimensions.length <= 0)
|
||||
throw new IllegalArgumentException ("Empty dimensions array.");
|
||||
return createMultiArray(componentType, dimensions,
|
||||
dimensions.length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array length.
|
||||
* @param array the array
|
||||
* @return the length of the array
|
||||
* @throws IllegalArgumentException if <code>array</code> is not an array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
*/
|
||||
public static int getLength(Object array)
|
||||
{
|
||||
if (array instanceof Object[])
|
||||
return ((Object[]) array).length;
|
||||
if (array instanceof boolean[])
|
||||
return ((boolean[]) array).length;
|
||||
if (array instanceof byte[])
|
||||
return ((byte[]) array). length;
|
||||
if (array instanceof char[])
|
||||
return ((char[]) array).length;
|
||||
if (array instanceof short[])
|
||||
return ((short[]) array).length;
|
||||
if (array instanceof int[])
|
||||
return ((int[]) array).length;
|
||||
if (array instanceof long[])
|
||||
return ((long[]) array).length;
|
||||
if (array instanceof float[])
|
||||
return ((float[]) array).length;
|
||||
if (array instanceof double[])
|
||||
return ((double[]) array).length;
|
||||
if (array == null)
|
||||
throw new NullPointerException();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of an array. Primitive elements will be wrapped in
|
||||
* the corresponding class type.
|
||||
*
|
||||
* @param array the array to access
|
||||
* @param index the array index to access
|
||||
* @return the element at <code>array[index]</code>
|
||||
* @throws IllegalArgumentException if <code>array</code> is not an array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #getBoolean(Object, int)
|
||||
* @see #getByte(Object, int)
|
||||
* @see #getChar(Object, int)
|
||||
* @see #getShort(Object, int)
|
||||
* @see #getInt(Object, int)
|
||||
* @see #getLong(Object, int)
|
||||
* @see #getFloat(Object, int)
|
||||
* @see #getDouble(Object, int)
|
||||
*/
|
||||
public static Object get(Object array, int index)
|
||||
{
|
||||
if (array instanceof Object[])
|
||||
return ((Object[]) array)[index];
|
||||
if (array instanceof boolean[])
|
||||
return ((boolean[]) array)[index] ? Boolean.TRUE : Boolean.FALSE;
|
||||
if (array instanceof byte[])
|
||||
return new Byte(((byte[]) array)[index]);
|
||||
if (array instanceof char[])
|
||||
return new Character(((char[]) array)[index]);
|
||||
if (array instanceof short[])
|
||||
return new Short(((short[]) array)[index]);
|
||||
if (array instanceof int[])
|
||||
return new Integer(((int[]) array)[index]);
|
||||
if (array instanceof long[])
|
||||
return new Long(((long[]) array)[index]);
|
||||
if (array instanceof float[])
|
||||
return new Float(((float[]) array)[index]);
|
||||
if (array instanceof double[])
|
||||
return new Double(((double[]) array)[index]);
|
||||
if (array == null)
|
||||
throw new NullPointerException();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of a boolean array.
|
||||
*
|
||||
* @param array the array to access
|
||||
* @param index the array index to access
|
||||
* @return the boolean element at <code>array[index]</code>
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a boolean
|
||||
* array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #get(Object, int)
|
||||
*/
|
||||
public static boolean getBoolean(Object array, int index)
|
||||
{
|
||||
if (array instanceof boolean[])
|
||||
return ((boolean[]) array)[index];
|
||||
if (array == null)
|
||||
throw new NullPointerException();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of a byte array.
|
||||
*
|
||||
* @param array the array to access
|
||||
* @param index the array index to access
|
||||
* @return the byte element at <code>array[index]</code>
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a byte
|
||||
* array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #get(Object, int)
|
||||
*/
|
||||
public static byte getByte(Object array, int index)
|
||||
{
|
||||
if (array instanceof byte[])
|
||||
return ((byte[]) array)[index];
|
||||
if (array == null)
|
||||
throw new NullPointerException();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of a char array.
|
||||
*
|
||||
* @param array the array to access
|
||||
* @param index the array index to access
|
||||
* @return the char element at <code>array[index]</code>
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a char
|
||||
* array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #get(Object, int)
|
||||
*/
|
||||
public static char getChar(Object array, int index)
|
||||
{
|
||||
if (array instanceof char[])
|
||||
return ((char[]) array)[index];
|
||||
if (array == null)
|
||||
throw new NullPointerException();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of a short array.
|
||||
*
|
||||
* @param array the array to access
|
||||
* @param index the array index to access
|
||||
* @return the short element at <code>array[index]</code>
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a byte
|
||||
* or char array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #get(Object, int)
|
||||
*/
|
||||
public static short getShort(Object array, int index)
|
||||
{
|
||||
if (array instanceof short[])
|
||||
return ((short[]) array)[index];
|
||||
return getByte(array, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of an int array.
|
||||
*
|
||||
* @param array the array to access
|
||||
* @param index the array index to access
|
||||
* @return the int element at <code>array[index]</code>
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a byte,
|
||||
* char, short, or int array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #get(Object, int)
|
||||
*/
|
||||
public static int getInt(Object array, int index)
|
||||
{
|
||||
if (array instanceof int[])
|
||||
return ((int[]) array)[index];
|
||||
if (array instanceof char[])
|
||||
return ((char[]) array)[index];
|
||||
return getShort(array, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of a long array.
|
||||
*
|
||||
* @param array the array to access
|
||||
* @param index the array index to access
|
||||
* @return the long element at <code>array[index]</code>
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a byte,
|
||||
* char, short, int, or long array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #get(Object, int)
|
||||
*/
|
||||
public static long getLong(Object array, int index)
|
||||
{
|
||||
if (array instanceof long[])
|
||||
return ((long[]) array)[index];
|
||||
return getInt(array, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of a float array.
|
||||
*
|
||||
* @param array the array to access
|
||||
* @param index the array index to access
|
||||
* @return the float element at <code>array[index]</code>
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a byte,
|
||||
* char, short, int, long, or float array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #get(Object, int)
|
||||
*/
|
||||
public static float getFloat(Object array, int index)
|
||||
{
|
||||
if (array instanceof float[])
|
||||
return ((float[]) array)[index];
|
||||
return getLong(array, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of a double array.
|
||||
*
|
||||
* @param array the array to access
|
||||
* @param index the array index to access
|
||||
* @return the double element at <code>array[index]</code>
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a byte,
|
||||
* char, short, int, long, float, or double array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #get(Object, int)
|
||||
*/
|
||||
public static double getDouble(Object array, int index)
|
||||
{
|
||||
if (array instanceof double[])
|
||||
return ((double[]) array)[index];
|
||||
return getFloat(array, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an element of an array. If the array is primitive, then the new
|
||||
* value is unwrapped and widened.
|
||||
*
|
||||
* @param array the array to set a value of
|
||||
* @param index the array index to set the value to
|
||||
* @param value the value to set
|
||||
* @throws IllegalArgumentException if <code>array</code> is not an array,
|
||||
* or the array is primitive and unwrapping value fails, or the
|
||||
* value is not assignable to the array component type
|
||||
* @throws NullPointerException if array is null, or if array is primitive
|
||||
* and value is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #setBoolean(Object, int, boolean)
|
||||
* @see #setByte(Object, int, byte)
|
||||
* @see #setChar(Object, int, char)
|
||||
* @see #setShort(Object, int, short)
|
||||
* @see #setInt(Object, int, int)
|
||||
* @see #setLong(Object, int, long)
|
||||
* @see #setFloat(Object, int, float)
|
||||
* @see #setDouble(Object, int, double)
|
||||
*/
|
||||
public static void set(Object array, int index, Object value)
|
||||
{
|
||||
if (array instanceof Object[])
|
||||
{
|
||||
// Too bad the API won't let us throw the easier ArrayStoreException!
|
||||
if (value != null
|
||||
&& ! array.getClass().getComponentType().isInstance(value))
|
||||
throw new IllegalArgumentException();
|
||||
((Object[]) array)[index] = value;
|
||||
}
|
||||
else if (value instanceof Byte)
|
||||
setByte(array, index, ((Byte) value).byteValue());
|
||||
else if (value instanceof Short)
|
||||
setShort(array, index, ((Short) value).shortValue());
|
||||
else if (value instanceof Integer)
|
||||
setInt(array, index, ((Integer) value).intValue());
|
||||
else if (value instanceof Long)
|
||||
setLong(array, index, ((Long) value).longValue());
|
||||
else if (value instanceof Float)
|
||||
setFloat(array, index, ((Float) value).floatValue());
|
||||
else if (value instanceof Double)
|
||||
setDouble(array, index, ((Double) value).doubleValue());
|
||||
else if (value instanceof Character)
|
||||
setChar(array, index, ((Character) value).charValue());
|
||||
else if (value instanceof Boolean)
|
||||
setBoolean(array, index, ((Boolean) value).booleanValue());
|
||||
else if (array == null)
|
||||
throw new NullPointerException();
|
||||
else
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an element of a boolean array.
|
||||
*
|
||||
* @param array the array to set a value of
|
||||
* @param index the array index to set the value to
|
||||
* @param value the value to set
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a boolean
|
||||
* array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #set(Object, int, Object)
|
||||
*/
|
||||
public static void setBoolean(Object array, int index, boolean value)
|
||||
{
|
||||
if (array instanceof boolean[])
|
||||
((boolean[]) array)[index] = value;
|
||||
else if (array == null)
|
||||
throw new NullPointerException();
|
||||
else
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an element of a byte array.
|
||||
*
|
||||
* @param array the array to set a value of
|
||||
* @param index the array index to set the value to
|
||||
* @param value the value to set
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a byte,
|
||||
* short, int, long, float, or double array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #set(Object, int, Object)
|
||||
*/
|
||||
public static void setByte(Object array, int index, byte value)
|
||||
{
|
||||
if (array instanceof byte[])
|
||||
((byte[]) array)[index] = value;
|
||||
else
|
||||
setShort(array, index, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an element of a char array.
|
||||
*
|
||||
* @param array the array to set a value of
|
||||
* @param index the array index to set the value to
|
||||
* @param value the value to set
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a char,
|
||||
* int, long, float, or double array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #set(Object, int, Object)
|
||||
*/
|
||||
public static void setChar(Object array, int index, char value)
|
||||
{
|
||||
if (array instanceof char[])
|
||||
((char[]) array)[index] = value;
|
||||
else
|
||||
setInt(array, index, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an element of a short array.
|
||||
*
|
||||
* @param array the array to set a value of
|
||||
* @param index the array index to set the value to
|
||||
* @param value the value to set
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a short,
|
||||
* int, long, float, or double array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #set(Object, int, Object)
|
||||
*/
|
||||
public static void setShort(Object array, int index, short value)
|
||||
{
|
||||
if (array instanceof short[])
|
||||
((short[]) array)[index] = value;
|
||||
else
|
||||
setInt(array, index, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an element of an int array.
|
||||
*
|
||||
* @param array the array to set a value of
|
||||
* @param index the array index to set the value to
|
||||
* @param value the value to set
|
||||
* @throws IllegalArgumentException if <code>array</code> is not an int,
|
||||
* long, float, or double array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #set(Object, int, Object)
|
||||
*/
|
||||
public static void setInt(Object array, int index, int value)
|
||||
{
|
||||
if (array instanceof int[])
|
||||
((int[]) array)[index] = value;
|
||||
else
|
||||
setLong(array, index, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an element of a long array.
|
||||
*
|
||||
* @param array the array to set a value of
|
||||
* @param index the array index to set the value to
|
||||
* @param value the value to set
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a long,
|
||||
* float, or double array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #set(Object, int, Object)
|
||||
*/
|
||||
public static void setLong(Object array, int index, long value)
|
||||
{
|
||||
if (array instanceof long[])
|
||||
((long[]) array)[index] = value;
|
||||
else
|
||||
setFloat(array, index, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an element of a float array.
|
||||
*
|
||||
* @param array the array to set a value of
|
||||
* @param index the array index to set the value to
|
||||
* @param value the value to set
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a float
|
||||
* or double array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #set(Object, int, Object)
|
||||
*/
|
||||
public static void setFloat(Object array, int index, float value)
|
||||
{
|
||||
if (array instanceof float[])
|
||||
((float[]) array)[index] = value;
|
||||
else
|
||||
setDouble(array, index, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an element of a double array.
|
||||
*
|
||||
* @param array the array to set a value of
|
||||
* @param index the array index to set the value to
|
||||
* @param value the value to set
|
||||
* @throws IllegalArgumentException if <code>array</code> is not a double
|
||||
* array
|
||||
* @throws NullPointerException if <code>array</code> is null
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>index</code> is out of
|
||||
* bounds
|
||||
* @see #set(Object, int, Object)
|
||||
*/
|
||||
public static void setDouble(Object array, int index, double value)
|
||||
{
|
||||
if (array instanceof double[])
|
||||
((double[]) array)[index] = value;
|
||||
else if (array == null)
|
||||
throw new NullPointerException();
|
||||
else
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically and recursively create a multi-dimensioned array of objects.
|
||||
*
|
||||
* @param type guaranteed to be a valid object type
|
||||
* @param dimensions the dimensions of the array
|
||||
* @param index index of the current dimension to build
|
||||
* @return the new multi-dimensioned array
|
||||
* @throws NegativeArraySizeException if any entry of dimensions is negative
|
||||
* @throws OutOfMemoryError if memory allocation fails
|
||||
*/
|
||||
// This would be faster if implemented natively, using the multianewarray
|
||||
// bytecode instead of this recursive call
|
||||
private static Object createMultiArray(Class type, int[] dimensions,
|
||||
int index)
|
||||
{
|
||||
if (index == 0)
|
||||
return newInstance(type, dimensions[0]);
|
||||
|
||||
Object toAdd = createMultiArray(type, dimensions, index - 1);
|
||||
Class thisType = toAdd.getClass();
|
||||
Object[] retval
|
||||
= (Object[]) createObjectArray(thisType, dimensions[index]);
|
||||
if (dimensions[index] > 0)
|
||||
retval[0] = toAdd;
|
||||
int i = dimensions[index];
|
||||
while (--i > 0)
|
||||
retval[i] = createMultiArray(type, dimensions, index - 1);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically create an array of objects.
|
||||
*
|
||||
* @param type guaranteed to be a valid object type
|
||||
* @param dim the length of the array
|
||||
* @return the new array
|
||||
* @throws NegativeArraySizeException if dim is negative
|
||||
* @throws OutOfMemoryError if memory allocation fails
|
||||
*/
|
||||
private static native Object createObjectArray(Class type, int dim);
|
||||
}
|
61
libjava/classpath/java/lang/reflect/GenericArrayType.java
Normal file
61
libjava/classpath/java/lang/reflect/GenericArrayType.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* GenericArrayType.java - Represent an array type with a generic component
|
||||
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* Represents the type of an array's components, which may be
|
||||
* either a parameterized type or a type variable.
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface GenericArrayType
|
||||
extends Type
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the <code>Type</code> of the components within the array.
|
||||
*
|
||||
* @return a <code>Type</code> instance representing the type of
|
||||
* the array's components.
|
||||
*/
|
||||
Type getGenericComponentType();
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/* GenericSignatureFormatError.java - Thrown when a signature is malformed.
|
||||
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* Thrown on encountering a syntactically malformed signature in
|
||||
* a reflective method. During reflection, the generic type signature
|
||||
* of a type, method or constructor may be interpreted by the virtual
|
||||
* machine. This error is thrown if this operation fails.
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
* @since 1.5
|
||||
*/
|
||||
public class GenericSignatureFormatError
|
||||
extends ClassFormatError
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs a new <code>GenericSignatureFormatError</code>.
|
||||
*/
|
||||
public GenericSignatureFormatError()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
137
libjava/classpath/java/lang/reflect/InvocationHandler.java
Normal file
137
libjava/classpath/java/lang/reflect/InvocationHandler.java
Normal file
|
@ -0,0 +1,137 @@
|
|||
/* java.lang.reflect.InvocationHandler - dynamically executes methods in
|
||||
proxy instances
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* This interface defines an invocation handler. Suppose you are using
|
||||
* reflection, and found a method that requires that its parameter
|
||||
* be an object of a given interface. You want to call this method,
|
||||
* but have no idea what classes implement that interface. So, you can
|
||||
* create a {@link Proxy} instance, a convenient way to dynamically
|
||||
* generate a class that meets all the necessary properties of that
|
||||
* interface. But in order for the proxy instance to do any good, it
|
||||
* needs to know what to do when interface methods are invoked! So,
|
||||
* this interface is basically a cool wrapper that provides runtime
|
||||
* code generation needed by proxy instances.
|
||||
*
|
||||
* <p>While this interface was designed for use by Proxy, it will also
|
||||
* work on any object in general.</p>
|
||||
*
|
||||
* <p>Hints for implementing this class:</p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>Don't forget that Object.equals, Object.hashCode, and
|
||||
* Object.toString will call this handler. In particular,
|
||||
* a naive call to proxy.equals, proxy.hashCode, or proxy.toString
|
||||
* will put you in an infinite loop. And remember that string
|
||||
* concatenation also invokes toString.</li>
|
||||
* <li>Obey the contract of the Method object you are handling, or
|
||||
* the proxy instance will be forced to throw a
|
||||
* {@link NullPointerException}, {@link ClassCastException},
|
||||
* or {@link UndeclaredThrowableException}.</li>
|
||||
* <li>Be prepared to wrap/unwrap primitives as necessary.</li>
|
||||
* <li>The Method object may be owned by a different interface than
|
||||
* what was actually used as the qualifying type of the method
|
||||
* invocation in the Java source code. This means that it might
|
||||
* not always be safe to throw an exception listed as belonging
|
||||
* to the method's throws clause.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p><small>For a fun time, create an InvocationHandler that handles the
|
||||
* methods of a proxy instance of the InvocationHandler interface!</small></p>
|
||||
*
|
||||
* @see Proxy
|
||||
* @see UndeclaredThrowableException
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.3
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface InvocationHandler
|
||||
{
|
||||
/**
|
||||
* When a method is invoked on a proxy instance, it is wrapped and
|
||||
* this method is called instead, so that you may decide at runtime
|
||||
* how the original method should behave.
|
||||
*
|
||||
* @param proxy the instance that the wrapped method should be
|
||||
* invoked on. When this method is called by a Proxy object,
|
||||
* `proxy' will be an instance of {@link Proxy}, and oddly enough,
|
||||
* <code>Proxy.getInvocationHandler(proxy)</code> will return
|
||||
* <code>this</code>!
|
||||
* @param method the reflected method to invoke on the proxy.
|
||||
* When this method is called by a Proxy object, 'method'
|
||||
* will be the reflection object owned by the declaring
|
||||
* class or interface, which may be a supertype of the
|
||||
* interfaces the proxy directly implements.
|
||||
* @param args the arguments passed to the original method, or
|
||||
* <code>null</code> if the method takes no arguments.
|
||||
* (But also be prepared to handle a 0-length array).
|
||||
* Arguments of primitive type, such as <code>boolean</code>
|
||||
* or <code>int</code>, are wrapped in the appropriate
|
||||
* class such as {@link Boolean} or {@link Integer}.
|
||||
* @return whatever is necessary to return from the wrapped method.
|
||||
* If the wrapped method is <code>void</code>, the proxy
|
||||
* instance will ignore it. If the wrapped method returns
|
||||
* a primitive, this must be the correct wrapper type whose value
|
||||
* is exactly assignable to the appropriate type (no widening
|
||||
* will be performed); a null object in this case causes a
|
||||
* {@link NullPointerException}. In all remaining cases, if
|
||||
* the returned object is not assignment compatible to the
|
||||
* declared type of the original method, the proxy instance
|
||||
* will generate a {@link ClassCastException}.
|
||||
* @throws Throwable this interface is listed as throwing anything,
|
||||
* but the implementation should only throw unchecked
|
||||
* exceptions and exceptions listed in the throws clause of
|
||||
* all methods being overridden by the proxy instance. If
|
||||
* something is thrown that is not compatible with the throws
|
||||
* clause of all overridden methods, the proxy instance will
|
||||
* wrap the exception in an UndeclaredThrowableException.
|
||||
* Note that an exception listed in the throws clause of the
|
||||
* `method' parameter might not be declared in additional
|
||||
* interfaces also implemented by the proxy object.
|
||||
*
|
||||
* @see Proxy
|
||||
* @see UndeclaredThrowableException
|
||||
*/
|
||||
Object invoke(Object proxy, Method method, Object[] args)
|
||||
throws Throwable;
|
||||
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/* InvocationTargetException.java -- Wrapper exception for reflection
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* InvocationTargetException is sort of a way to "wrap" whatever exception
|
||||
* comes up when a method or constructor is called via Reflection. As of
|
||||
* JDK 1.4, it was retrofitted to match the exception chaining of all other
|
||||
* exceptions, but <code>getTargetException()</code> still works.
|
||||
*
|
||||
* @author John Keiser
|
||||
* @author Tom Tromey (tromey@cygnus.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Method#invoke(Object,Object[])
|
||||
* @see Constructor#newInstance(Object[])
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class InvocationTargetException extends Exception
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.1+.
|
||||
*/
|
||||
private static final long serialVersionUID = 4085088731926701167L;
|
||||
|
||||
/**
|
||||
* The chained exception. This field is only around for serial compatibility.
|
||||
*
|
||||
* @serial the chained exception
|
||||
*/
|
||||
private final Throwable target;
|
||||
|
||||
/**
|
||||
* Construct an exception with null as the cause. The cause is initialized
|
||||
* to null.
|
||||
*/
|
||||
protected InvocationTargetException()
|
||||
{
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an <code>InvocationTargetException</code> using another
|
||||
* exception.
|
||||
*
|
||||
* @param targetException the exception to wrap
|
||||
*/
|
||||
public InvocationTargetException(Throwable targetException)
|
||||
{
|
||||
this(targetException, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an <code>InvocationTargetException</code> using another
|
||||
* exception and an error message.
|
||||
*
|
||||
* @param targetException the exception to wrap
|
||||
* @param err an extra reason for the exception-throwing
|
||||
*/
|
||||
public InvocationTargetException(Throwable targetException, String err)
|
||||
{
|
||||
super(err, targetException);
|
||||
target = targetException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wrapped (targeted) exception.
|
||||
*
|
||||
* @return the targeted exception
|
||||
* @see #getCause()
|
||||
*/
|
||||
public Throwable getTargetException()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cause of this exception (which may be null).
|
||||
*
|
||||
* @return the cause
|
||||
* @since 1.4
|
||||
*/
|
||||
public Throwable getCause()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
}
|
100
libjava/classpath/java/lang/reflect/Member.java
Normal file
100
libjava/classpath/java/lang/reflect/Member.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
/* java.lang.reflect.Member - common query methods in reflection
|
||||
Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* Member is an interface that represents any member of a class (field or
|
||||
* method) or a constructor. You can get information about the declaring
|
||||
* class, name or modifiers of the member with this interface.
|
||||
*
|
||||
* @author John Keiser
|
||||
* @author Per Bothner (bothner@cygnus.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Class
|
||||
* @see Field
|
||||
* @see Method
|
||||
* @see Constructor
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface Member
|
||||
{
|
||||
/**
|
||||
* Represents all members, whether public, private, protected or
|
||||
* package-protected, but only which are declared in this class.
|
||||
* Used in SecurityManager.checkMemberAccess() to determine the
|
||||
* type of members to access.
|
||||
* @see SecurityManager#checkMemberAccess()
|
||||
*/
|
||||
int DECLARED = 1;
|
||||
|
||||
/**
|
||||
* Represents public members only, but includes all inherited members.
|
||||
* Used in SecurityManager.checkMemberAccess() to determine the type of
|
||||
* members to access.
|
||||
* @see SecurityManager#checkMemberAccess()
|
||||
*/
|
||||
int PUBLIC = 0;
|
||||
|
||||
/**
|
||||
* Gets the class that declared this member. This is not the class where
|
||||
* this method was called, or even the class where this Member object
|
||||
* came to life, but the class that declares the member this represents.
|
||||
*
|
||||
* @return the class that declared this member
|
||||
*/
|
||||
Class getDeclaringClass();
|
||||
|
||||
/**
|
||||
* Gets the simple name of this member. This will be a valid Java
|
||||
* identifier, with no qualification.
|
||||
*
|
||||
* @return the name of this member
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the modifiers this member uses. Use the <code>Modifier</code>
|
||||
* class to interpret the values.
|
||||
*
|
||||
* @return an integer representing the modifiers to this Member
|
||||
* @see Modifier
|
||||
*/
|
||||
int getModifiers();
|
||||
}
|
332
libjava/classpath/java/lang/reflect/Modifier.java
Normal file
332
libjava/classpath/java/lang/reflect/Modifier.java
Normal file
|
@ -0,0 +1,332 @@
|
|||
/* java.lang.reflect.Modifier
|
||||
Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* Modifier is a helper class with static methods to determine whether an
|
||||
* int returned from getModifiers() represents static, public, protected,
|
||||
* native, final, etc... and provides an additional method to print
|
||||
* out all of the modifiers in an int in order.
|
||||
* <p>
|
||||
* The methods in this class use the bitmask values in the VM spec to
|
||||
* determine the modifiers of an int. This means that a VM must return a
|
||||
* standard mask, conformant with the VM spec. I don't know if this is how
|
||||
* Sun does it, but I'm willing to bet money that it is.
|
||||
*
|
||||
* @author John Keiser
|
||||
* @author Tom Tromey (tromey@cygnus.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Member#getModifiers()
|
||||
* @see Method#getModifiers()
|
||||
* @see Field#getModifiers()
|
||||
* @see Constructor#getModifiers()
|
||||
* @see Class#getModifiers()
|
||||
* @since 1.1
|
||||
*/
|
||||
public class Modifier
|
||||
{
|
||||
/** <STRONG>This constructor really shouldn't be here ... there are no
|
||||
* instance methods or variables of this class, so instantiation is
|
||||
* worthless. However, this function is in the 1.1 spec, so it is added
|
||||
* for completeness.</STRONG>
|
||||
*/
|
||||
public Modifier()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Public: accessible from any other class.
|
||||
*/
|
||||
public static final int PUBLIC = 0x0001;
|
||||
|
||||
/**
|
||||
* Private: accessible only from the same enclosing class.
|
||||
*/
|
||||
public static final int PRIVATE = 0x0002;
|
||||
|
||||
/**
|
||||
* Protected: accessible only to subclasses, or within the package.
|
||||
*/
|
||||
public static final int PROTECTED = 0x0004;
|
||||
|
||||
/**
|
||||
* Static:<br><ul>
|
||||
* <li>Class: no enclosing instance for nested class.</li>
|
||||
* <li>Field or Method: can be accessed or invoked without an
|
||||
* instance of the declaring class.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int STATIC = 0x0008;
|
||||
|
||||
/**
|
||||
* Final:<br><ul>
|
||||
* <li>Class: no subclasses allowed.</li>
|
||||
* <li>Field: cannot be changed.</li>
|
||||
* <li>Method: cannot be overriden.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int FINAL = 0x0010;
|
||||
|
||||
/**
|
||||
* Synchronized: Method: lock the class while calling this method.
|
||||
*/
|
||||
public static final int SYNCHRONIZED = 0x0020;
|
||||
|
||||
/**
|
||||
* Volatile: Field: cannot be cached.
|
||||
*/
|
||||
public static final int VOLATILE = 0x0040;
|
||||
|
||||
/**
|
||||
* Transient: Field: not serialized or deserialized.
|
||||
*/
|
||||
public static final int TRANSIENT = 0x0080;
|
||||
|
||||
/**
|
||||
* Native: Method: use JNI to call this method.
|
||||
*/
|
||||
public static final int NATIVE = 0x0100;
|
||||
|
||||
/**
|
||||
* Interface: Class: is an interface.
|
||||
*/
|
||||
public static final int INTERFACE = 0x0200;
|
||||
|
||||
/**
|
||||
* Abstract:<br><ul>
|
||||
* <li>Class: may not be instantiated.</li>
|
||||
* <li>Method: may not be called.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int ABSTRACT = 0x0400;
|
||||
|
||||
/**
|
||||
* Strictfp: Method: expressions are FP-strict.<p>
|
||||
* Also used as a modifier for classes, to mean that all initializers
|
||||
* and constructors are FP-strict, but does not show up in
|
||||
* Class.getModifiers.
|
||||
*/
|
||||
public static final int STRICT = 0x0800;
|
||||
|
||||
|
||||
/**
|
||||
* Super - treat invokespecial as polymorphic so that super.foo() works
|
||||
* according to the JLS. This is a reuse of the synchronized constant
|
||||
* to patch a hole in JDK 1.0. *shudder*.
|
||||
*/
|
||||
static final int SUPER = 0x0020;
|
||||
|
||||
/**
|
||||
* All the flags, only used by code in this package.
|
||||
*/
|
||||
static final int ALL_FLAGS = 0xfff;
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is abstract.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if abstract, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isAbstract(int mod)
|
||||
{
|
||||
return (mod & ABSTRACT) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is final.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if final, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isFinal(int mod)
|
||||
{
|
||||
return (mod & FINAL) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is an interface.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if an interface, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isInterface(int mod)
|
||||
{
|
||||
return (mod & INTERFACE) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is native.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if native, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isNative(int mod)
|
||||
{
|
||||
return (mod & NATIVE) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is private.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if private, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isPrivate(int mod)
|
||||
{
|
||||
return (mod & PRIVATE) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is protected.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if protected, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isProtected(int mod)
|
||||
{
|
||||
return (mod & PROTECTED) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is public.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if public, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isPublic(int mod)
|
||||
{
|
||||
return (mod & PUBLIC) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is static.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if static, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isStatic(int mod)
|
||||
{
|
||||
return (mod & STATIC) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is strictfp.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if strictfp, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isStrict(int mod)
|
||||
{
|
||||
return (mod & STRICT) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is synchronized.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if synchronized, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isSynchronized(int mod)
|
||||
{
|
||||
return (mod & SYNCHRONIZED) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is transient.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if transient, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isTransient(int mod)
|
||||
{
|
||||
return (mod & TRANSIENT) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given modifier is volatile.
|
||||
* @param mod the modifier.
|
||||
* @return <code>true</code> if volatile, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isVolatile(int mod)
|
||||
{
|
||||
return (mod & VOLATILE) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of all the modifiers represented by the
|
||||
* given int. The keywords are printed in this order:
|
||||
* <code><public|protected|private> abstract static final transient
|
||||
* volatile synchronized native strictfp interface</code>.
|
||||
*
|
||||
* @param mod the modifier.
|
||||
* @return the String representing the modifiers.
|
||||
*/
|
||||
public static String toString(int mod)
|
||||
{
|
||||
return toString(mod, new StringBuffer()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Package helper method that can take a StringBuffer.
|
||||
* @param mod the modifier
|
||||
* @param r the StringBuffer to which the String representation is appended
|
||||
* @return r, with information appended
|
||||
*/
|
||||
static StringBuffer toString(int mod, StringBuffer r)
|
||||
{
|
||||
if (isPublic(mod))
|
||||
r.append("public ");
|
||||
if (isProtected(mod))
|
||||
r.append("protected ");
|
||||
if (isPrivate(mod))
|
||||
r.append("private ");
|
||||
if (isAbstract(mod))
|
||||
r.append("abstract ");
|
||||
if (isStatic(mod))
|
||||
r.append("static ");
|
||||
if (isFinal(mod))
|
||||
r.append("final ");
|
||||
if (isTransient(mod))
|
||||
r.append("transient ");
|
||||
if (isVolatile(mod))
|
||||
r.append("volatile ");
|
||||
if (isSynchronized(mod))
|
||||
r.append("synchronized ");
|
||||
if (isNative(mod))
|
||||
r.append("native ");
|
||||
if (isStrict(mod))
|
||||
r.append("strictfp ");
|
||||
if (isInterface(mod))
|
||||
r.append("interface ");
|
||||
|
||||
// Trim trailing space.
|
||||
if ((mod & ALL_FLAGS) != 0)
|
||||
r.setLength(r.length() - 1);
|
||||
return r;
|
||||
}
|
||||
}
|
122
libjava/classpath/java/lang/reflect/ParameterizedType.java
Normal file
122
libjava/classpath/java/lang/reflect/ParameterizedType.java
Normal file
|
@ -0,0 +1,122 @@
|
|||
/* ParameterizedType.java -- Represents parameterized types e.g. List<String>
|
||||
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Represents a type which is parameterized over one or more other
|
||||
* types. For example, <code>List<Integer></code> is a parameterized
|
||||
* type, with <code>List</code> parameterized over the type
|
||||
* <code>Integer</code>.
|
||||
* </p>
|
||||
* <p>
|
||||
* Instances of this classes are created as needed, during reflection.
|
||||
* On creating a parameterized type, <code>p</code>, the
|
||||
* <code>GenericTypeDeclaration</code> corresponding to <code>p</code>
|
||||
* is created and resolved. Each type argument of <code>p</code>
|
||||
* is then created recursively; details of this process are availble
|
||||
* in the documentation of <code>TypeVariable</code>. This creation
|
||||
* process only happens once; repetition has no effect.
|
||||
* </p>
|
||||
* <p>
|
||||
* Implementors of this interface must implement an appropriate
|
||||
* <code>equals()</code> method. This method should equate any
|
||||
* two instances of the implementing class that have the same
|
||||
* <code>GenericTypeDeclaration</code> and <code>Type</code>
|
||||
* parameters.
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
* @see GenericTypeDeclaration
|
||||
* @see TypeVariable
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface ParameterizedType
|
||||
extends Type
|
||||
{
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns an array of <code>Type</code> objects, which gives
|
||||
* the parameters of this type.
|
||||
* </p>
|
||||
* <p>
|
||||
* <strong>Note</code>: the returned array may be empty. This
|
||||
* occurs if the supposed <code>ParameterizedType</code> is simply
|
||||
* a normal type wrapped inside a parameterized type.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of <code>Type</code>s, representing the arguments
|
||||
* of this type.
|
||||
* @throws TypeNotPresentException if any of the types referred to by
|
||||
* the parameters of this type do not actually exist.
|
||||
* @throws MalformedParameterizedTypeException if any of the types
|
||||
* refer to a type which can not be instantiated.
|
||||
*/
|
||||
Type[] getActualTypeArguments();
|
||||
|
||||
/**
|
||||
* Returns the type of which this type is a member. For example,
|
||||
* in <code>Top<String>.Bottom<Integer></code>,
|
||||
* <code>Bottom<Integer></code> is a member of
|
||||
* <code>Top<String></code>, and so the latter is returned
|
||||
* by this method. Calling this method on top-level types (such as
|
||||
* <code>Top<String></code>) returns null.
|
||||
*
|
||||
* @return the type which owns this type.
|
||||
* @throws TypeNotPresentException if the owner type referred to by
|
||||
* this type do not actually exist.
|
||||
* @throws MalformedParameterizedTypeException if the owner type
|
||||
* referred to by this type can not be instantiated.
|
||||
*/
|
||||
Type getOwnerType();
|
||||
|
||||
/**
|
||||
* Returns a version of this type without parameters, which corresponds
|
||||
* to the class or interface which declared the type. For example,
|
||||
* the raw type corresponding to <code>List<Double></code>
|
||||
* is <code>List</code>, which was declared by the <code>List</code>
|
||||
* class.
|
||||
*
|
||||
* @return the raw variant of this type (i.e. the type without
|
||||
* parameters).
|
||||
*/
|
||||
Type getRawType();
|
||||
|
||||
}
|
1615
libjava/classpath/java/lang/reflect/Proxy.java
Normal file
1615
libjava/classpath/java/lang/reflect/Proxy.java
Normal file
File diff suppressed because it is too large
Load diff
4
libjava/classpath/java/lang/reflect/README
Normal file
4
libjava/classpath/java/lang/reflect/README
Normal file
|
@ -0,0 +1,4 @@
|
|||
README for java.lang.reflect:
|
||||
|
||||
java.lang.reflect is now mostly empty. We've carved out the classes that have
|
||||
to do with the VM and put them into the VM interface.
|
102
libjava/classpath/java/lang/reflect/ReflectPermission.java
Normal file
102
libjava/classpath/java/lang/reflect/ReflectPermission.java
Normal file
|
@ -0,0 +1,102 @@
|
|||
/* ReflectPermission.java - named permission for reflaction
|
||||
Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
import java.security.BasicPermission;
|
||||
|
||||
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
|
||||
* "The Java Language Specification", ISBN 0-201-63451-1
|
||||
* plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements permissions for reflection. This is a named
|
||||
* permission, and the only defined name is suppressAccessChecks, which
|
||||
* allows suppression of normal Java objects when using reflection.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <th>Permission Target Name</th>
|
||||
* <th>What Permission Allows</th>
|
||||
* <th>Risk of Allowing Permission</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><code>suppressAccessChecks</code></td>
|
||||
* <td>Ability to access fields, invoke methods, and construct objects
|
||||
* via reflection, including non-public members in contexts where
|
||||
* such access is not legal at compile-time.</td>
|
||||
* <td>This is dangerous. It exposes possibly confidential information,
|
||||
* and malicious code could interfere with the internals of the Virtual
|
||||
* Machine by corrupting private data.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.2
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class ReflectPermission
|
||||
extends BasicPermission
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.2.
|
||||
*/
|
||||
private static final long serialVersionUID = 7412737110241507485L;
|
||||
|
||||
/**
|
||||
* Construct a ReflectPermission with the given name.
|
||||
*
|
||||
* @param name The permission name
|
||||
*/
|
||||
public ReflectPermission(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a ReflectPermission with the given name.
|
||||
*
|
||||
* @param name The permission name
|
||||
* @param actions The actions; this is ignored and should be null
|
||||
*/
|
||||
public ReflectPermission(String name, String actions)
|
||||
{
|
||||
super(name, actions);
|
||||
}
|
||||
}
|
4
libjava/classpath/java/lang/reflect/TODO
Executable file
4
libjava/classpath/java/lang/reflect/TODO
Executable file
|
@ -0,0 +1,4 @@
|
|||
TODO for java.lang.reflect Java side
|
||||
|
||||
- more tests!
|
||||
- Java 2 support (waiting on java.lang Java 2 support)
|
55
libjava/classpath/java/lang/reflect/Type.java
Normal file
55
libjava/classpath/java/lang/reflect/Type.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* Type.java - Superinterface for all types.
|
||||
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* Represents any <code>Type</code> within the Java programming
|
||||
* language. This may be a primitive type (e.g. <code>int</code>,
|
||||
* an array type (e.g. <code>double[]>/code>), a raw type
|
||||
* (e.g. <code>Calendar</code>), a parameterized type
|
||||
* (e.g. <code>List<Boolean></code>, or a type
|
||||
* variable (e.g. <code>T extends String</code>).
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface Type
|
||||
{
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
/* UndeclaredThrowableException.java -- wraps an undeclared checked exception
|
||||
thrown by a Proxy invocation handler
|
||||
Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* This exception class is thrown by a {@link Proxy} instance if
|
||||
* the {@link InvocationHandler#invoke(Object, Method, Object[]) invoke}
|
||||
* method of that instance's InvocationHandler attempts to throw an
|
||||
* exception that not declared by the throws clauses of all of the
|
||||
* interface methods that the proxy instance is implementing.
|
||||
*
|
||||
* <p>When thrown by Proxy, this class will always wrap a checked
|
||||
* exception, never {@link Error} or {@link RuntimeException},
|
||||
* which are unchecked.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Proxy
|
||||
* @see InvocationHandler
|
||||
* @since 1.3
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class UndeclaredThrowableException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.3+.
|
||||
*/
|
||||
private static final long serialVersionUID = 330127114055056639L;
|
||||
|
||||
/**
|
||||
* The immutable exception that this wraps. This field is redundant
|
||||
* with {@link Throwable#cause}, but is necessary for serial compatibility.
|
||||
*
|
||||
* @serial the chained exception
|
||||
*/
|
||||
private final Throwable undeclaredThrowable;
|
||||
|
||||
/**
|
||||
* Wraps the given checked exception into a RuntimeException, with no
|
||||
* detail message. {@link Throwable#initCause(Throwable)} will fail
|
||||
* on this instance.
|
||||
*
|
||||
* @param cause the undeclared throwable that caused this exception,
|
||||
* may be null
|
||||
*/
|
||||
public UndeclaredThrowableException(Throwable cause)
|
||||
{
|
||||
this(cause, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the given checked exception into a RuntimeException, with the
|
||||
* specified detail message. {@link Throwable#initCause(Throwable)} will
|
||||
* fail on this instance.
|
||||
*
|
||||
* @param cause the undeclared throwable that caused this exception,
|
||||
* may be null
|
||||
* @param message the message, may be null
|
||||
*/
|
||||
public UndeclaredThrowableException(Throwable cause, String message)
|
||||
{
|
||||
super(message, cause);
|
||||
undeclaredThrowable = cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cause of this exception. If this exception was created
|
||||
* by a {@link Proxy} instance, it will be a non-null checked
|
||||
* exception. This method pre-dates exception chaining, and is now
|
||||
* simply a longer way to call <code>getCause()</code>.
|
||||
*
|
||||
* @return the cause of this exception, may be null
|
||||
* @see #getCause()
|
||||
*/
|
||||
public Throwable getUndeclaredThrowable()
|
||||
{
|
||||
return undeclaredThrowable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cause of this exception. If this exception was created
|
||||
* by a {@link Proxy} instance, it will be a non-null checked
|
||||
* exception.
|
||||
*
|
||||
* @return the cause of this exception, may be null
|
||||
* @since 1.4
|
||||
*/
|
||||
public Throwable getCause()
|
||||
{
|
||||
return undeclaredThrowable;
|
||||
}
|
||||
}
|
115
libjava/classpath/java/lang/reflect/WildcardType.java
Normal file
115
libjava/classpath/java/lang/reflect/WildcardType.java
Normal file
|
@ -0,0 +1,115 @@
|
|||
/* WildcardType.java -- A wildcard type expression e.g. ? extends String
|
||||
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
/**
|
||||
* Represents a wildcard type expression, where the type variable
|
||||
* is unnamed. The simplest example of this is <code>?</code>,
|
||||
* which represents any unbounded type. Another example is
|
||||
* <code>? extends Number</code>, which specifies any type
|
||||
* which is a subclass of <code>Number</code> (<code>Number</code>
|
||||
* is the upper bound).
|
||||
* </p>
|
||||
* <p>
|
||||
* <code>? super String</code> gives the type a less common lower bound,
|
||||
* which means that the type must be either a <code>String</code> or one
|
||||
* of its superclasses. This can be useful in working with collections.
|
||||
* You may want a method to add instances of a class to a collection
|
||||
* with a more generic type (e.g. adding <code>String</code>s to
|
||||
* a list of <code>Object</code>s), but don't want to allow users
|
||||
* to pass in a collection with a more specific type.
|
||||
* </p>
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface WildcardType extends Type
|
||||
{
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns an array of <code>Type</code>s, which specify the
|
||||
* lower bounds of this type. The default lower bound is
|
||||
* <code>null</code>, which causes this method to return an
|
||||
* empty array.
|
||||
* </p>
|
||||
* <p>
|
||||
* In generating the array of <code>Type</code>s, each
|
||||
* <code>ParameterizedType</code> or <code>TypeVariable</code> is
|
||||
* created, (see the documentation for these classes for details of this
|
||||
* process), if necessary, while all other types are simply
|
||||
* resolved.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of <code>Type</code> objects, representing
|
||||
* the wildcard type's lower bounds.
|
||||
* @throws TypeNotPresentException if any of the types referred to by
|
||||
* the lower bounds of this type do not actually exist.
|
||||
* @throws MalformedParameterizedTypeException if any of the types
|
||||
* refer to a type which can not be instantiated.
|
||||
*/
|
||||
Type[] getLowerBounds();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns an array of <code>Type</code>s, which specify the
|
||||
* upper bounds of this type. The default upper bound is
|
||||
* <code>Object</code>, which causes this method to return an
|
||||
* array, containing just the <code>Type</code> instance for
|
||||
* <code>Object</code>.
|
||||
* </p>
|
||||
* <p>
|
||||
* In generating the array of <code>Type</code>s, each
|
||||
* <code>ParameterizedType</code> or <code>TypeVariable</code> is
|
||||
* created, (see the documentation for these classes for details of this
|
||||
* process), if necessary, while all other types are simply
|
||||
* resolved.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of <code>Type</code> objects, representing
|
||||
* the wildcard type's upper bounds.
|
||||
* @throws TypeNotPresentException if any of the types referred to by
|
||||
* the upper bounds of this type do not actually exist.
|
||||
* @throws MalformedParameterizedTypeException if any of the types
|
||||
* refer to a type which can not be instantiated.
|
||||
*/
|
||||
Type[] getUpperBounds();
|
||||
|
||||
}
|
47
libjava/classpath/java/lang/reflect/package.html
Normal file
47
libjava/classpath/java/lang/reflect/package.html
Normal file
|
@ -0,0 +1,47 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<!-- package.html - describes classes in java.lang.reflect package.
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. -->
|
||||
|
||||
<html>
|
||||
<head><title>GNU Classpath - java.lang.reflect</title></head>
|
||||
|
||||
<body>
|
||||
<p>Runtime inspection and manipulation of object classes, methods, arguments
|
||||
and fields.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue