diff options
| author | Brian Jones <cbj@gnu.org> | 1998-11-24 02:11:01 +0000 |
|---|---|---|
| committer | Brian Jones <cbj@gnu.org> | 1998-11-24 02:11:01 +0000 |
| commit | d0837293cf963ec049c30023f60ec1956c623f15 (patch) | |
| tree | aabd56948766c1a8d04ee259da2e5aee3d33b63e /vm/reference/java | |
| parent | 4fe025dc8f90fa38ebb862d5ee1db5f1bc7e03b8 (diff) | |
| download | classpath-d0837293cf963ec049c30023f60ec1956c623f15.tar.gz | |
void setSigners(Object[]) instead of public (readded)
Diffstat (limited to 'vm/reference/java')
| -rwxr-xr-x | vm/reference/java/lang/Class.java | 739 |
1 files changed, 368 insertions, 371 deletions
diff --git a/vm/reference/java/lang/Class.java b/vm/reference/java/lang/Class.java index 77b446685..05ed8bc18 100755 --- a/vm/reference/java/lang/Class.java +++ b/vm/reference/java/lang/Class.java @@ -22,7 +22,6 @@ package java.lang; import java.lang.reflect.*; import gnu.java.lang.*; -import java.io.*; /** ** A Class represents a Java type. There will never be @@ -49,376 +48,374 @@ import java.io.*; ** @since JDK1.0 **/ -/* - * CLASSPATH: public java.lang.Class(); - * JDK : public java.lang.Package getPackage(); - * JDK : public java.security.ProtectionDomain getProtectionDomain(); - * JDK : public static java.lang.Class forName(java.lang.String, boolean, java.lang.ClassLoader); - * CLASSPATH: public void setSigners(java.lang.Object[]); - */ +public class Class { + Class superclass = null; + String name = null; + Object[] signers = null; + + /** Return the human-readable form of this Object. For + ** class, that means "interface " or "class " plus the + ** classname. + ** @return the human-readable form of this Object. + ** @since JDK1.0 + **/ + public String toString() { + return (isInterface() ? "interface " : "class ") + getName(); + } + + /** Get the name of this class, separated by dots for + ** package separators. + ** @return the name of this class. + ** @since JDK1.0 + **/ + public String getName() { + if(name != null) + return name; + else + return nativeGetName(); + } + + /** Get whether this class is an interface or not. Array + ** types are not interfaces. + ** @return whether this class is an interface or not. + ** @since JDK1.0 + **/ + public native boolean isInterface(); + + /** Get the direct superclass of this class. If this is + ** an interface, it will get the direct superinterface. + ** @return the direct superclass of this class. + ** @since JDK1.0 + **/ + public Class getSuperclass() { + if(superclass != null) + return superclass; + else + return nativeGetSuperclass(); + } + + /** Get the interfaces this class <EM>directly</EM> + ** implements, in the order that they were declared. + ** This method may return an empty array, but will + ** never return null. + ** @return the interfaces this class directly implements. + ** @since JDK1.0 + **/ + public native Class[] getInterfaces(); + + /** Get a new instance of this class by calling the + ** no-argument constructor. + ** @return a new instance of this class. + ** @exception InstantiationException if there is not a + ** no-arg constructor for this class, or if + ** an exception occurred during instantiation, + ** or if the target constructor throws an + ** exception. + ** @exception IllegalAccessException if you are not + ** allowed to access the no-arg constructor of + ** this Class for whatever reason. + ** @since JDK1.0 + **/ + public Object newInstance() throws InstantiationException, IllegalAccessException { + try { + return getConstructor(new Class[0]).newInstance(new Object[0]); + } catch(SecurityException e) { + throw new IllegalAccessException("Cannot access no-arg constructor"); + } catch(IllegalArgumentException e) { + throw new UnknownError("IllegalArgumentException thrown from Constructor.newInstance(). Something is rotten in Denmark."); + } catch(InvocationTargetException e) { + throw new InstantiationException("Target threw an exception."); + } catch(NoSuchMethodException e) { + throw new InstantiationException("Method not found"); + } + } + + /** Get the ClassLoader that loaded this class. If it was + ** loaded by the system classloader, this method will + ** return null. + ** @return the ClassLoader that loaded this class. + ** @since JDK1.0 + **/ + public native ClassLoader getClassLoader(); + + /** Use the system classloader to load and link a class. + ** @param name the name of the class to find. + ** @return the Class object representing the class. + ** @exception ClassNotFoundException if the class was not + ** found by the system classloader. + ** @since JDK1.0 + **/ + public static native Class forName(String name) throws ClassNotFoundException; + + /** Discover whether an Object is an instance of this + ** Class. Think of it as almost like + ** <CODE>o instanceof (this class)</CODE>. + ** @param o the Object to check + ** @return whether o is an instance of this class. + ** @since JDK1.1 + **/ + public native boolean isInstance(Object o); + + /** Discover whether an instance of the Class parameter + ** would be an instance of this Class as well. Think of + ** doing <CODE>isInstance(c.newInstance())</CODE> or even + ** <CODE>c instanceof (this class)</CODE>. + ** @param c the class to check + ** @return whether an instance of c would be an instance + ** of this class as well. + ** @since JDK1.1 + **/ + public native boolean isAssignableFrom(Class c); + + /** Return whether this class is an array type. + ** @return whether this class is an array type. + ** @since JDK1.1 + **/ + public boolean isArray() { + return getName().charAt(0) == '['; + } + + /** Return whether this class is a primitive type. A + ** primitive type class is a class representing a kind of + ** "placeholder" for the various primitive types. You + ** can access the various primitive type classes through + ** java.lang.Boolean.TYPE, java.lang.Integer.TYPE, etc. + ** @return whether this class is a primitive type. + ** @since JDK1.1 + **/ + public native boolean isPrimitive(); + + /** If this is an array, get the Class representing the + ** type of array. Examples: [[java.lang.String would + ** return [java.lang.String, and calling getComponentType + ** on that would give java.lang.String. If this is not + ** an array, returns null. + ** @return the array type of this class, or null. + ** @since JDK1.1 + **/ + public Class getComponentType() { + if(isArray()) { + try { + return Class.forName(name.substring(1)); + } catch(ClassNotFoundException e) { + return null; + } + } else { + return null; + } + } + + /** Get the signers of this class. + ** @return the signers of this class. + ** @since JDK1.1 + **/ + public Object[] getSigners() { + return signers; + } + + /** Set the signers of this class. + ** @param signers the signers of this class. + ** @since JDK1.1 + **/ + void setSigners(Object[] signers) { + this.signers = signers; + } + + /** Get a resource URL using this class's package using + ** the getClassLoader().getResource() method. If this + ** class was loaded using the system classloader, + ** ClassLoader.getSystemResource() is used instead.<P> + ** + ** If the name you supply is absolute (it starts with a + ** <CODE>/</CODE>), then it is passed on to getResource() + ** as is. If it is relative, the package name is + ** prepended, with <CODE>.</CODE>'s replaced with + ** <CODE>/</CODE> slashes.<P> + ** + ** The URL returned is system- and classloader- + ** dependent, and could change across implementations. + ** @param name the name of the resource, generally a + ** path. + ** @return the URL to the resource. + **/ + public java.net.URL getResource(String name) { + if(name.length() > 0 && name.charAt(0) != '/') { + name = ClassHelper.getPackagePortion(getName()).replace('.','/') + "/" + name; + } + ClassLoader c = getClassLoader(); + if(c == null) { + return ClassLoader.getSystemResource(name); + } else { + return c.getResource(name); + } + } + + /** Get a resource using this class's package using the + ** getClassLoader().getResource() method. If this class + ** was loaded using the system classloader, + ** ClassLoader.getSystemResource() is used instead.<P> + ** + ** If the name you supply is absolute (it starts with a + ** <CODE>/</CODE>), then it is passed on to getResource() + ** as is. If it is relative, the package name is + ** prepended, with <CODE>.</CODE>'s replaced with + ** <CODE>/</CODE> slashes.<P> + ** + ** The URL returned is system- and classloader- + ** dependent, and could change across implementations. + ** @param name the name of the resource, generally a + ** path. + ** @return An InputStream with the contents of the + ** resource in it. + **/ + public java.io.InputStream getResourceAsStream(String name) { + if(name.length() > 0 && name.charAt(0) != '/') { + name = ClassHelper.getPackagePortion(getName()).replace('.','/') + "/" + name; + } + ClassLoader c = getClassLoader(); + if(c == null) { + return ClassLoader.getSystemResourceAsStream(name); + } else { + return c.getResourceAsStream(name); + } + } + + /** Get the modifiers of this class. These can be checked + ** against using java.lang.reflect.Modifier. + ** @return the modifiers of this class. + ** @see java.lang.reflect.Modifer + ** @since JDK1.1 + **/ + public native int getModifiers(); + + /** If this is an inner class, return the class that + ** declared it. If not, return null. + ** @return the declaring class of this class. + ** @since JDK1.1 + **/ + public native Class getDeclaringClass(); + + /** Get all the public inner classes, declared in this + ** class or inherited from superclasses, that are + ** members of this class. + ** @return all public inner classes in this class. + **/ + public native Class[] getClasses(); + + /** Get all the inner classes declared in this class. + ** @return all inner classes declared in this class. + ** @exception SecurityException if you do not have access + ** to non-public inner classes of this class. + **/ + public native Class[] getDeclaredClasses() throws SecurityException; + + /** Get a public constructor from this class. + ** @param args the argument types for the constructor. + ** @return the constructor. + ** @exception NoSuchMethodException if the constructor does + ** not exist. + ** @exception SecurityException if you do not have access to public + ** members of this class. + **/ + public native Constructor getConstructor(Class[] args) throws NoSuchMethodException, SecurityException; + + /** Get a constructor declared in this class. + ** @param args the argument types for the constructor. + ** @return the constructor. + ** @exception NoSuchMethodException if the constructor does + ** not exist in this class. + ** @exception SecurityException if you do not have access to + ** non-public members of this class. + **/ + public native Constructor getDeclaredConstructor(Class[] args) throws NoSuchMethodException, SecurityException; + + /** Get all public constructors from this class. + ** @return all public constructors in this class. + ** @exception SecurityException if you do not have access to public + ** members of this class. + **/ + public native Constructor[] getConstructors() throws SecurityException; + + /** Get all constructors declared in this class. + ** @return all constructors declared in this class. + ** @exception SecurityException if you do not have access to + ** non-public members of this class. + **/ + public native Constructor[] getDeclaredConstructors() throws SecurityException; + + + /** Get a public method from this class. + ** @param name the name of the method. + ** @param args the argument types for the method. + ** @return the method. + ** @exception NoSuchMethodException if the method does + ** not exist. + ** @exception SecurityException if you do not have access to public + ** members of this class. + **/ + public native Method getMethod(String name, Class[] args) throws NoSuchMethodException, SecurityException; + + /** Get a method declared in this class. + ** @param name the name of the method. + ** @param args the argument types for the method. + ** @return the method. + ** @exception NoSuchMethodException if the method does + ** not exist in this class. + ** @exception SecurityException if you do not have access to + ** non-public members of this class. + **/ + public native Method getDeclaredMethod(String name, Class[] args) throws NoSuchMethodException, SecurityException; + + /** Get all public methods from this class. + ** @return all public methods in this class. + ** @exception SecurityException if you do not have access to public + ** members of this class. + **/ + public native Method[] getMethods() throws SecurityException; + + /** Get all methods declared in this class. + ** @return all methods declared in this class. + ** @exception SecurityException if you do not have access to + ** non-public members of this class. + **/ + public native Method[] getDeclaredMethods() throws SecurityException; + + + /** Get a public field from this class. + ** @param name the name of the field. + ** @return the field. + ** @exception NoSuchFieldException if the field does + ** not exist. + ** @exception SecurityException if you do not have access to public + ** members of this class. + **/ + public native Field getField(String name) throws NoSuchFieldException, SecurityException; + + /** Get a field declared in this class. + ** @param name the name of the field. + ** @return the field. + ** @exception NoSuchFieldException if the field does + ** not exist in this class. + ** @exception SecurityException if you do not have access to + ** non-public members of this class. + **/ + public native Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException; + + /** Get all public fields from this class. + ** @return all public fields in this class. + ** @exception SecurityException if you do not have access to public + ** members of this class. + **/ + public native Field[] getFields() throws SecurityException; + + /** Get all fields declared in this class. + ** @return all fieilds declared in this class. + ** @exception SecurityException if you do not have access to + ** non-public members of this class. + **/ + public native Field[] getDeclaredFields() throws SecurityException; -public final class Class extends Object - // implements java.io.Serializable -{ - Class superclass = null; - String name = null; - Object[] signers = null; - - /** Return the human-readable form of this Object. For - ** class, that means "interface " or "class " plus the - ** classname. - ** @return the human-readable form of this Object. - ** @since JDK1.0 - **/ - public String toString() { - return (isInterface() ? "interface " : "class ") + getName(); - } - - /** Get the name of this class, separated by dots for - ** package separators. - ** @return the name of this class. - ** @since JDK1.0 - **/ - public String getName() { - if(name != null) - return name; - else - return nativeGetName(); - } - - /** Get whether this class is an interface or not. Array - ** types are not interfaces. - ** @return whether this class is an interface or not. - ** @since JDK1.0 - **/ - public native boolean isInterface(); - - /** Get the direct superclass of this class. If this is - ** an interface, it will get the direct superinterface. - ** @return the direct superclass of this class. - ** @since JDK1.0 - **/ - public Class getSuperclass() { - if(superclass != null) - return superclass; - else - return nativeGetSuperclass(); - } - - /** Get the interfaces this class <EM>directly</EM> - ** implements, in the order that they were declared. - ** This method may return an empty array, but will - ** never return null. - ** @return the interfaces this class directly implements. - ** @since JDK1.0 - **/ - public native Class[] getInterfaces(); - - /** Get a new instance of this class by calling the - ** no-argument constructor. - ** @return a new instance of this class. - ** @exception InstantiationException if there is not a - ** no-arg constructor for this class, or if - ** an exception occurred during instantiation, - ** or if the target constructor throws an - ** exception. - ** @exception IllegalAccessException if you are not - ** allowed to access the no-arg constructor of - ** this Class for whatever reason. - ** @since JDK1.0 - **/ - public Object newInstance() throws InstantiationException, IllegalAccessException { - try { - return getConstructor(new Class[0]).newInstance(new Object[0]); - } catch(SecurityException e) { - throw new IllegalAccessException("Cannot access no-arg constructor"); - } catch(IllegalArgumentException e) { - throw new UnknownError("IllegalArgumentException thrown from Constructor.newInstance(). Something is rotten in Denmark."); - } catch(InvocationTargetException e) { - throw new InstantiationException("Target threw an exception."); - } catch(NoSuchMethodException e) { - throw new InstantiationException("Method not found"); - } - } - - /** Get the ClassLoader that loaded this class. If it was - ** loaded by the system classloader, this method will - ** return null. - ** @return the ClassLoader that loaded this class. - ** @since JDK1.0 - **/ - public native ClassLoader getClassLoader(); - - /** Use the system classloader to load and link a class. - ** @param name the name of the class to find. - ** @return the Class object representing the class. - ** @exception ClassNotFoundException if the class was not - ** found by the system classloader. - ** @since JDK1.0 - **/ - public static native Class forName(String name) throws ClassNotFoundException; - - /** Discover whether an Object is an instance of this - ** Class. Think of it as almost like - ** <CODE>o instanceof (this class)</CODE>. - ** @param o the Object to check - ** @return whether o is an instance of this class. - ** @since JDK1.1 - **/ - public native boolean isInstance(Object o); - - /** Discover whether an instance of the Class parameter - ** would be an instance of this Class as well. Think of - ** doing <CODE>isInstance(c.newInstance())</CODE> or even - ** <CODE>c instanceof (this class)</CODE>. - ** @param c the class to check - ** @return whether an instance of c would be an instance - ** of this class as well. - ** @since JDK1.1 - **/ - public native boolean isAssignableFrom(Class c); - - /** Return whether this class is an array type. - ** @return whether this class is an array type. - ** @since JDK1.1 - **/ - public boolean isArray() { - return getName().charAt(0) == '['; - } - - /** Return whether this class is a primitive type. A - ** primitive type class is a class representing a kind of - ** "placeholder" for the various primitive types. You - ** can access the various primitive type classes through - ** java.lang.Boolean.TYPE, java.lang.Integer.TYPE, etc. - ** @return whether this class is a primitive type. - ** @since JDK1.1 - **/ - public native boolean isPrimitive(); - - /** If this is an array, get the Class representing the - ** type of array. Examples: [[java.lang.String would - ** return [java.lang.String, and calling getComponentType - ** on that would give java.lang.String. If this is not - ** an array, returns null. - ** @return the array type of this class, or null. - ** @since JDK1.1 - **/ - public Class getComponentType() { - if(isArray()) { - try { - return Class.forName(name.substring(1)); - } catch(ClassNotFoundException e) { - return null; - } - } else { - return null; - } - } - - /** Get the signers of this class. - ** @return the signers of this class. - ** @since JDK1.1 - **/ - public Object[] getSigners() { - return signers; - } - - /** Get a resource URL using this class's package using - ** the getClassLoader().getResource() method. If this - ** class was loaded using the system classloader, - ** ClassLoader.getSystemResource() is used instead.<P> - ** - ** If the name you supply is absolute (it starts with a - ** <CODE>/</CODE>), then it is passed on to getResource() - ** as is. If it is relative, the package name is - ** prepended, with <CODE>.</CODE>'s replaced with - ** <CODE>/</CODE> slashes.<P> - ** - ** The URL returned is system- and classloader- - ** dependent, and could change across implementations. - ** @param name the name of the resource, generally a - ** path. - ** @return the URL to the resource. - **/ - public java.net.URL getResource(String name) { - if(name.length() > 0 && name.charAt(0) != '/') { - name = ClassHelper.getPackagePortion(getName()).replace('.','/') + "/" + name; - } - ClassLoader c = getClassLoader(); - if(c == null) { - return ClassLoader.getSystemResource(name); - } else { - return c.getResource(name); - } - } - - /** Get a resource using this class's package using the - ** getClassLoader().getResource() method. If this class - ** was loaded using the system classloader, - ** ClassLoader.getSystemResource() is used instead.<P> - ** - ** If the name you supply is absolute (it starts with a - ** <CODE>/</CODE>), then it is passed on to getResource() - ** as is. If it is relative, the package name is - ** prepended, with <CODE>.</CODE>'s replaced with - ** <CODE>/</CODE> slashes.<P> - ** - ** The URL returned is system- and classloader- - ** dependent, and could change across implementations. - ** @param name the name of the resource, generally a - ** path. - ** @return An InputStream with the contents of the - ** resource in it. - **/ - public java.io.InputStream getResourceAsStream(String name) { - if(name.length() > 0 && name.charAt(0) != '/') { - name = ClassHelper.getPackagePortion(getName()).replace('.','/') + "/" + name; - } - ClassLoader c = getClassLoader(); - if(c == null) { - return ClassLoader.getSystemResourceAsStream(name); - } else { - return c.getResourceAsStream(name); - } - } - - /** Get the modifiers of this class. These can be checked - ** against using java.lang.reflect.Modifier. - ** @return the modifiers of this class. - ** @see java.lang.reflect.Modifer - ** @since JDK1.1 - **/ - public native int getModifiers(); - - /** If this is an inner class, return the class that - ** declared it. If not, return null. - ** @return the declaring class of this class. - ** @since JDK1.1 - **/ - public native Class getDeclaringClass(); - - /** Get all the public inner classes, declared in this - ** class or inherited from superclasses, that are - ** members of this class. - ** @return all public inner classes in this class. - **/ - public native Class[] getClasses(); - - /** Get all the inner classes declared in this class. - ** @return all inner classes declared in this class. - ** @exception SecurityException if you do not have access - ** to non-public inner classes of this class. - **/ - public native Class[] getDeclaredClasses() throws SecurityException; - - /** Get a public constructor from this class. - ** @param args the argument types for the constructor. - ** @return the constructor. - ** @exception NoSuchMethodException if the constructor does - ** not exist. - ** @exception SecurityException if you do not have access to public - ** members of this class. - **/ - public native Constructor getConstructor(Class[] args) throws NoSuchMethodException, SecurityException; - - /** Get a constructor declared in this class. - ** @param args the argument types for the constructor. - ** @return the constructor. - ** @exception NoSuchMethodException if the constructor does - ** not exist in this class. - ** @exception SecurityException if you do not have access to - ** non-public members of this class. - **/ - public native Constructor getDeclaredConstructor(Class[] args) throws NoSuchMethodException, SecurityException; - - /** Get all public constructors from this class. - ** @return all public constructors in this class. - ** @exception SecurityException if you do not have access to public - ** members of this class. - **/ - public native Constructor[] getConstructors() throws SecurityException; - - /** Get all constructors declared in this class. - ** @return all constructors declared in this class. - ** @exception SecurityException if you do not have access to - ** non-public members of this class. - **/ - public native Constructor[] getDeclaredConstructors() throws SecurityException; - - - /** Get a public method from this class. - ** @param name the name of the method. - ** @param args the argument types for the method. - ** @return the method. - ** @exception NoSuchMethodException if the method does - ** not exist. - ** @exception SecurityException if you do not have access to public - ** members of this class. - **/ - public native Method getMethod(String name, Class[] args) throws NoSuchMethodException, SecurityException; - - /** Get a method declared in this class. - ** @param name the name of the method. - ** @param args the argument types for the method. - ** @return the method. - ** @exception NoSuchMethodException if the method does - ** not exist in this class. - ** @exception SecurityException if you do not have access to - ** non-public members of this class. - **/ - public native Method getDeclaredMethod(String name, Class[] args) throws NoSuchMethodException, SecurityException; - - /** Get all public methods from this class. - ** @return all public methods in this class. - ** @exception SecurityException if you do not have access to public - ** members of this class. - **/ - public native Method[] getMethods() throws SecurityException; - - /** Get all methods declared in this class. - ** @return all methods declared in this class. - ** @exception SecurityException if you do not have access to - ** non-public members of this class. - **/ - public native Method[] getDeclaredMethods() throws SecurityException; - - - /** Get a public field from this class. - ** @param name the name of the field. - ** @return the field. - ** @exception NoSuchFieldException if the field does - ** not exist. - ** @exception SecurityException if you do not have access to public - ** members of this class. - **/ - public native Field getField(String name) throws NoSuchFieldException, SecurityException; - - /** Get a field declared in this class. - ** @param name the name of the field. - ** @return the field. - ** @exception NoSuchFieldException if the field does - ** not exist in this class. - ** @exception SecurityException if you do not have access to - ** non-public members of this class. - **/ - public native Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException; - - /** Get all public fields from this class. - ** @return all public fields in this class. - ** @exception SecurityException if you do not have access to public - ** members of this class. - **/ - public native Field[] getFields() throws SecurityException; - - /** Get all fields declared in this class. - ** @return all fieilds declared in this class. - ** @exception SecurityException if you do not have access to - ** non-public members of this class. - **/ - public native Field[] getDeclaredFields() throws SecurityException; - - private native String nativeGetName(); - private native Class nativeGetSuperclass(); + private native String nativeGetName(); + private native Class nativeGetSuperclass(); } |
