summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2002-02-23 09:19:52 +0000
committerEric Blake <ebb9@byu.net>2002-02-23 09:19:52 +0000
commit70f6e1ec80b4ffc5370564b2710ee194054da42f (patch)
tree9f2b7ce9aa35a53393b9876f6492f2ec90cfde62 /gnu
parente746a862de38f2e1a5d53b17e633ad2400a7e6c8 (diff)
downloadclasspath-70f6e1ec80b4ffc5370564b2710ee194054da42f.tar.gz
2002-02-23 Eric Blake <ebb9@email.byu.edu>
* java/lang/Makefile.am (EXTRA_DIST): Add AssertionError.java and StackTraceElement.java. * java/lang/AssertionError.java: New file. * java/lang/ClassLoader.java: Add some synchronization and code cleanups to use improved VMClassLoader. Add assertion status fields and methods. * java/lang/StackTraceElement.java: New file. * vm/reference/java/lang/Class.java (desiredAssertionStatus): Add. Other locations: clean up code. * vm/reference/java/lang/Throwable.java (cause, stackTrace): Add exception chaining, and Java code for stack traces (native code unimplemented). * vm/reference/java/lang/VMClassLoader.java: Add (unimplemented) hooks to compile assertion status. (defineClass, loadClass): Add prototypes for missing native hooks. * vm/reference/java/lang/VMSecurityManager.java: Formatting. * gnu/java/lang/ClassHelper.java (getAllMethodsAtDeclaration), (getAllFieldsAtDeclaration): Delete, as they were just duplicates. (getAllMethods, getAllFields): Optimize. * gnu/java/lang/ArrayHelper.java: Formatting and Javadoc. (equalsArray): Delete, it duplicates java.util.Arrays.equals. * gnu/java/beans/BeanInfoEmbryo.java (hasMethod): Use Arrays.equals instead of ArrayHelper.equalsArray.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/java/beans/BeanInfoEmbryo.java19
-rw-r--r--gnu/java/lang/ArrayHelper.java72
-rw-r--r--gnu/java/lang/ClassHelper.java186
3 files changed, 96 insertions, 181 deletions
diff --git a/gnu/java/beans/BeanInfoEmbryo.java b/gnu/java/beans/BeanInfoEmbryo.java
index 4aed20b9f..473aa790c 100644
--- a/gnu/java/beans/BeanInfoEmbryo.java
+++ b/gnu/java/beans/BeanInfoEmbryo.java
@@ -1,5 +1,5 @@
/* gnu.java.beans.BeanInfoEmbryo
- Copyright (C) 1998 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -130,14 +130,15 @@ public class BeanInfoEmbryo {
}
public boolean hasMethod(MethodDescriptor m) {
- for(int i=0;i<methods.size();i++) {
- Method thisMethod = ((MethodDescriptor)methods.elementAt(i)).getMethod();
- if(m.getMethod().getName().equals(thisMethod.getName())
- && ArrayHelper.equalsArray(m.getMethod().getParameterTypes(), thisMethod.getParameterTypes())) {
- return true;
- }
- }
- return false;
+ for(int i=0;i<methods.size();i++) {
+ Method thisMethod = ((MethodDescriptor)methods.elementAt(i)).getMethod();
+ if(m.getMethod().getName().equals(thisMethod.getName())
+ && Arrays.equals(m.getMethod().getParameterTypes(),
+ thisMethod.getParameterTypes())) {
+ return true;
+ }
+ }
+ return false;
}
public void addMethod(MethodDescriptor m) {
methods.addElement(m);
diff --git a/gnu/java/lang/ArrayHelper.java b/gnu/java/lang/ArrayHelper.java
index 271e248f5..5ce0a99f5 100644
--- a/gnu/java/lang/ArrayHelper.java
+++ b/gnu/java/lang/ArrayHelper.java
@@ -1,5 +1,5 @@
-/* gnu.java.lang.ArrayHelper
- Copyright (C) 1998 Free Software Foundation, Inc.
+/* ArrayHelper.java -- Helper methods for handling array operations
+ Copyright (C) 1998, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -7,7 +7,7 @@ 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
@@ -39,36 +39,40 @@ exception statement from your version. */
package gnu.java.lang;
/**
- ** ArrayHelper helps you do things with arrays.
- **
- ** @author John Keiser
- ** @version 1.1.0, 29 Jul 1998
- **/
-
-public class ArrayHelper {
- public static boolean contains(Object[] array, Object searchFor) {
- return indexOf(array,searchFor) != -1;
- }
-
- public static int indexOf(Object[] array, Object searchFor) {
- for(int i=0;i<array.length;i++) {
- if(array[i].equals(searchFor)) {
- return i;
- }
- }
- return -1;
- }
+ * ArrayHelper helps you do things with arrays.
+ *
+ * @author John Keiser
+ */
+public class ArrayHelper
+{
+ /**
+ * Counterpart to java.util.Collection.contains.
+ *
+ * @param array the array to search
+ * @param searchFor the object to locate
+ * @return true if some array element <code>equals(searchFor)</code>
+ */
+ public static boolean contains(Object[] array, Object searchFor)
+ {
+ return indexOf(array, searchFor) != -1;
+ }
- public static boolean equalsArray(Object[] a, Object[] b) {
- if(a.length == b.length) {
- for(int i=0;i<a.length;i++) {
- if(!a[i].equals(b[i])) {
- return false;
- }
- }
- return true;
- } else {
- return false;
- }
- }
+ /**
+ * Counterpart to java.util.Collection.indexOf.
+ *
+ * @param array the array to search
+ * @param searchFor the object to locate
+ * @return the index of the first equal object, or -1
+ */
+ public static int indexOf(Object[] array, Object searchFor)
+ {
+ for (int i = 0; i < array.length; i++)
+ {
+ if(array[i].equals(searchFor))
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
}
diff --git a/gnu/java/lang/ClassHelper.java b/gnu/java/lang/ClassHelper.java
index 8363248e7..16d699e34 100644
--- a/gnu/java/lang/ClassHelper.java
+++ b/gnu/java/lang/ClassHelper.java
@@ -90,14 +90,13 @@ public class ClassHelper
}
/** Cache of methods found in getAllMethods(). */
- static Hashtable allMethods = new Hashtable();
-
- /** Cache of methods found in getAllMethodsAtDeclaration(). */
- static Hashtable allMethodsAtDeclaration = new Hashtable();
+ private static Map allMethods = new HashMap();
/**
* Get all the methods, public, private and otherwise, from the class,
- * getting them from the most recent class to find them.
+ * getting them from the most recent class to find them. This may not
+ * be quite the correct approach, as this includes methods that are not
+ * inherited or accessible from clazz, so beware.
*
* @param clazz the class to start at
* @return all methods declared or inherited in clazz
@@ -107,91 +106,45 @@ public class ClassHelper
Method[] retval = (Method[]) allMethods.get(clazz);
if (retval == null)
{
- Method[] superMethods;
- if (clazz.getSuperclass() != null)
- superMethods = getAllMethods(clazz.getSuperclass());
- else
- superMethods = new Method[0];
- Vector v = new Vector();
- Method[] currentMethods = clazz.getDeclaredMethods();
- for (int i = 0; i < currentMethods.length; i++)
- v.addElement(currentMethods[i]);
- for (int i = 0; i < superMethods.length; i++)
- {
- boolean addOK = true;
- for (int j = 0; j < currentMethods.length; j++)
- {
- if (getTruncatedName(superMethods[i].getName())
- .equals(getTruncatedName(currentMethods[j].getName()))
- && ArrayHelper.equalsArray(superMethods[i].getParameterTypes(),
- currentMethods[j].getParameterTypes()))
- {
- addOK = false;
- }
- }
- if(addOK)
- v.addElement(superMethods[i]);
- }
- retval = new Method[v.size()];
- v.copyInto(retval);
- allMethods.put(clazz,retval);
- }
- return retval;
- }
-
- /**
- * Get all the methods, public, private and otherwise, from the class,
- * and get them from their point of declaration.
- *
- * @param clazz the class to start at
- * @return all methods declared or inherited in clazz
- */
- public static Method[] getAllMethodsAtDeclaration(Class clazz)
- {
- Method[] retval = (Method[]) allMethodsAtDeclaration.get(clazz);
- if (retval == null)
- {
- Method[] superMethods;
- if (clazz.getSuperclass() != null)
- superMethods = getAllMethodsAtDeclaration(clazz.getSuperclass());
- else
- superMethods = new Method[0];
- Vector v = new Vector();
- Method[] currentMethods = clazz.getDeclaredMethods();
- for (int i = 0; i < superMethods.length; i++)
- v.addElement(superMethods[i]);
- for (int i = 0; i < superMethods.length; i++)
+ Set methods = new HashSet();
+ Class c = clazz;
+ while (c != null)
{
- boolean addOK = true;
- for (int j = 0; j < currentMethods.length; j++)
+ Method[] currentMethods = c.getDeclaredMethods();
+ loop:
+ for (int i = 0; i < currentMethods.length; i++)
{
- if (getTruncatedName(superMethods[i].getName())
- .equals(getTruncatedName(currentMethods[j].getName()))
- && ArrayHelper.equalsArray(superMethods[i].getParameterTypes(),
- currentMethods[j].getParameterTypes()))
+ Method current = currentMethods[i];
+ int size = methods.size();
+ Iterator iter = methods.iterator();
+ while (--size >= 0)
{
- addOK = false;
+ Method override = (Method) iter.next();
+ if (current.getName().equals(override.getName())
+ && Arrays.equals(current.getParameterTypes(),
+ override.getParameterTypes())
+ && current.getReturnType() == override.getReturnType())
+ continue loop;
}
+ methods.add(current);
}
- if(addOK)
- v.addElement(superMethods[i]);
+ c = c.getSuperclass();
}
- retval = new Method[v.size()];
- v.copyInto(retval);
- allMethodsAtDeclaration.put(clazz,retval);
+ retval = new Method[methods.size()];
+ methods.toArray(retval);
+ allMethods.put(clazz, retval);
}
return retval;
}
/** Cache of fields found in getAllFields(). */
- static Hashtable allFields = new Hashtable();
-
- /** Cache of fields found in getAllFieldsAtDeclaration(). */
- static Hashtable allFieldsAtDeclaration = new Hashtable();
+ private static Map allFields = new HashMap();
/**
* Get all the fields, public, private and otherwise, from the class,
- * getting them from the most recent class to find them.
+ * getting them from the most recent class to find them. This may not
+ * be quite the correct approach, as this includes fields that are not
+ * inherited or accessible from clazz, so beware.
*
* @param clazz the class to start at
* @return all fields declared or inherited in clazz
@@ -201,74 +154,31 @@ public class ClassHelper
Field[] retval = (Field[]) allFields.get(clazz);
if (retval == null)
{
- Field[] superFields;
- if (clazz.getSuperclass() != null)
- superFields = getAllFields(clazz.getSuperclass());
- else
- superFields = new Field[0];
- Vector v = new Vector();
- Field[] currentFields = clazz.getDeclaredFields();
- for (int i = 0; i < currentFields.length; i++)
- v.addElement(currentFields[i]);
- for (int i = 0; i < superFields.length; i++)
- {
- boolean addOK = true;
- for (int j = 0; j < currentFields.length; j++)
- {
- if (getTruncatedName(superFields[i].getName())
- .equals(getTruncatedName(currentFields[j].getName())))
- {
- addOK = false;
- }
- }
- if (addOK)
- v.addElement(superFields[i]);
- }
- retval = new Field[v.size()];
- v.copyInto(retval);
- allFields.put(clazz,retval);
- }
- return retval;
- }
-
- /**
- * Get all the fields, public, private and otherwise, from the class,
- * and get them from their point of declaration.
- *
- * @param clazz the class to start at
- * @return all fields declared or inherited in clazz
- */
- public static Field[] getAllFieldsAtDeclaration(Class clazz)
- {
- Field[] retval = (Field[]) allFieldsAtDeclaration.get(clazz);
- if (retval == null)
- {
- Field[] superFields;
- if (clazz.getSuperclass() != null)
- superFields = getAllFieldsAtDeclaration(clazz.getSuperclass());
- else
- superFields = new Field[0];
- Vector v = new Vector();
- Field[] currentFields = clazz.getDeclaredFields();
- for (int i = 0; i < superFields.length; i++)
- v.addElement(superFields[i]);
- for (int i = 0; i < superFields.length; i++)
+ Set fields = new HashSet();
+ Class c = clazz;
+ while (c != null)
{
- boolean addOK = true;
- for (int j = 0; j < currentFields.length; j++)
+ Field[] currentFields = c.getDeclaredFields();
+ loop:
+ for (int i = 0; i < currentFields.length; i++)
{
- if (getTruncatedName(superFields[i].getName())
- .equals(getTruncatedName(currentFields[j].getName())))
+ Field current = currentFields[i];
+ int size = fields.size();
+ Iterator iter = fields.iterator();
+ while (--size >= 0)
{
- addOK = false;
+ Field override = (Field) iter.next();
+ if (current.getName().equals(override.getName())
+ && current.getType() == override.getType())
+ continue loop;
}
+ fields.add(current);
}
- if(addOK)
- v.addElement(superFields[i]);
+ c = c.getSuperclass();
}
- retval = new Field[v.size()];
- v.copyInto(retval);
- allFieldsAtDeclaration.put(clazz,retval);
+ retval = new Field[fields.size()];
+ fields.toArray(retval);
+ allFields.put(clazz, retval);
}
return retval;
}