Index: java/lang/Class.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/lang/Class.java,v retrieving revision 1.11 diff -u -b -B -r1.11 Class.java --- java/lang/Class.java 22 Oct 2003 18:29:05 -0000 1.11 +++ java/lang/Class.java 25 Jan 2004 14:02:24 -0000 @@ -1,5 +1,6 @@ -/* Class.java -- Reference implementation of access to object metadata - Copyright (C) 1998, 2002, 2003 Free Software Foundation +/* Class.java -- Representation of a Java class. + Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004 + Free Software Foundation This file is part of GNU Classpath. @@ -55,13 +56,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import gnu.java.lang.ClassHelper; - -/* - * This class is a reference version, mainly for compiling a class library - * jar. It is likely that VM implementers replace this with their own - * version that can communicate effectively with the VM. - */ /** * A Class represents a Java type. There will never be multiple Class @@ -86,6 +80,7 @@ * * @author John Keiser * @author Eric Blake
+ * @author Tom Tromey * @since 1.0 * @see ClassLoader */ @@ -125,20 +120,6 @@ } /** - * Return the human-readable form of this Object. For an object, this - * is either "interface " or "class " followed bygetName()
,
- * for primitive types and void it is just getName()
.
- *
- * @return the human-readable form of this Object
- */
- public String toString()
- {
- if (isPrimitive())
- return getName();
- return (isInterface() ? "interface " : "class ") + getName();
- }
-
- /**
* Use the classloader of the current class to load, link, and initialize
* a class. This is equivalent to your code calling
* Class.forName(name, true, getClass().getClassLoader())
.
@@ -282,8 +263,8 @@
if (caller != this &&
(Modifier.isPrivate(modifiers)
|| getClassLoader() != caller.getClassLoader()
- || !ClassHelper.getPackagePortion(getName())
- .equals(ClassHelper.getPackagePortion(caller.getName()))))
+ || !getPackagePortion(getName())
+ .equals(getPackagePortion(caller.getName()))))
throw new IllegalAccessException(getName()
+ " has an inaccessible constructor");
}
@@ -465,7 +446,7 @@
{
ClassLoader cl = getClassLoader();
if (cl != null)
- return cl.getPackage(ClassHelper.getPackagePortion(getName()));
+ return cl.getPackage(getPackagePortion(getName()));
return null;
}
@@ -816,7 +796,7 @@
* checkMemberAccess(this, Member.PUBLIC)
as well as
* checkPackageAccess
both having to succeed.
*
- * @param name the name of the method
+ * @param methodName the name of the method
* @param types the type of each parameter
* @return the method
* @throws NoSuchMethodException if the method does not exist
@@ -824,36 +804,36 @@
* @see #getMethods()
* @since 1.1
*/
- public Method getMethod(String name, Class[] args)
+ public Method getMethod(String methodName, Class[] args)
throws NoSuchMethodException
{
memberAccessCheck(Member.PUBLIC);
- Method method = internalGetMethod(name, args);
- if (method != null)
+ Method method = internalGetMethod(methodName, args);
+ if (method == null)
+ throw new NoSuchMethodException(methodName);
return method;
- throw new NoSuchMethodException();
}
/**
* Like getMethod(String,Class[])
but without the security
* checks and returns null instead of throwing NoSuchMethodException.
*/
- public Method internalGetMethod(String name, Class[] args)
+ public Method internalGetMethod(String methodName, Class[] args)
{
- Method match = matchMethod(getDeclaredMethods(true), name, args);
+ Method match = matchMethod(getDeclaredMethods(true), methodName, args);
if (match != null)
return match;
Class superClass = getSuperclass();
if (superClass != null)
{
- match = superClass.internalGetMethod(name, args);
+ match = superClass.internalGetMethod(methodName, args);
if(match != null)
return match;
}
Class[] interfaces = getInterfaces();
for (int i = 0; i < interfaces.length; i++)
{
- match = interfaces[i].internalGetMethod(name, args);
+ match = interfaces[i].internalGetMethod(methodName, args);
if (match != null)
return match;
}
@@ -1139,7 +1119,7 @@
public InputStream getResourceAsStream(String name)
{
if (name.length() > 0 && name.charAt(0) != '/')
- name = ClassHelper.getPackagePortion(getName()).replace('.','/')
+ name = getPackagePortion(getName()).replace('.','/')
+ "/" + name;
ClassLoader c = getClassLoader();
if (c == null)
@@ -1168,7 +1148,7 @@
public URL getResource(String name)
{
if(name.length() > 0 && name.charAt(0) != '/')
- name = ClassHelper.getPackagePortion(getName()).replace('.','/')
+ name = getPackagePortion(getName()).replace('.','/')
+ "/" + name;
ClassLoader c = getClassLoader();
if (c == null)
@@ -1184,7 +1164,8 @@
* RuntimePermission("getProtectionDomain")
.
*
* @return the protection domain
- * @throws SecurityException if the security check fails
+ * @throws SecurityException if the security manager exists and the caller
+ * does not have RuntimePermission("getProtectionDomain")
.
* @see RuntimePermission
* @since 1.2
*/
@@ -1198,6 +1179,20 @@
}
/**
+ * Return the human-readable form of this Object. For an object, this
+ * is either "interface " or "class " followed by getName()
,
+ * for primitive types and void it is just getName()
.
+ *
+ * @return the human-readable form of this Object
+ */
+ public String toString()
+ {
+ if (isPrimitive())
+ return getName();
+ return (isInterface() ? "interface " : "class ") + getName();
+ }
+
+ /**
* Returns the desired assertion status of this class, if it were to be
* initialized at this moment. The class assertion status, if set, is
* returned; the backup is the default package status; then if there is
@@ -1235,14 +1230,14 @@
if (c.packageAssertionStatus != null)
synchronized (c)
{
- String name = ClassHelper.getPackagePortion(getName());
+ String name = getPackagePortion(getName());
if ("".equals(name))
status = c.packageAssertionStatus.get(null);
else
do
{
status = c.packageAssertionStatus.get(name);
- name = ClassHelper.getPackagePortion(name);
+ name = getPackagePortion(name);
}
while (! "".equals(name) && status == null);
if (status != null)
@@ -1250,14 +1245,14 @@
}
else
{
- String name = ClassHelper.getPackagePortion(getName());
+ String name = getPackagePortion(getName());
if ("".equals(name))
status = ClassLoader.systemPackageAssertionStatus.get(null);
else
do
{
status = ClassLoader.systemPackageAssertionStatus.get(name);
- name = ClassHelper.getPackagePortion(name);
+ name = getPackagePortion(name);
}
while (! "".equals(name) && status == null);
if (status != null)
@@ -1266,4 +1261,17 @@
return c.defaultAssertionStatus;
}
-} // class Class
+ /**
+ * Strip the last portion of the name (after the last dot).
+ *
+ * @param name the name to get package of
+ * @return the package name, or "" if no package
+ */
+ public static String getPackagePortion(String name)
+ {
+ int lastInd = name.lastIndexOf('.');
+ if (lastInd == -1)
+ return "";
+ return name.substring(0, lastInd);
+ }
+}