patch for Constructor.java

Aaron Place beavis at ihug.co.nz
Fri Feb 5 03:37:03 PST 1999


The toString() method of java.lang.reflect.Constructor does not print
anything for the throw construct.  The attatched patch fixes this.  It
also tidies up some other things in the same class.  The code has been
changed to be the same as in Method.java.

Aaron.


-------------- next part --------------
--- libraries/javalib/java/lang/reflect/Constructor.java.orig	Fri Feb  5 20:53:28 1999
+++ libraries/javalib/java/lang/reflect/Constructor.java	Fri Feb  5 21:01:36 1999
@@ -19,7 +19,7 @@
 	private Class clazz;
 	private int slot;
 	private Class[] parameterTypes;
-	private Class[] exceptiontypes;
+	private Class[] exceptionTypes;
 
 public boolean equals(Object obj)
 	{
@@ -62,7 +62,7 @@
 
 public Class[] getExceptionTypes()
 	{
-	return (exceptiontypes);
+	return (exceptionTypes);
 }
 
 native public int getModifiers();
@@ -86,17 +86,17 @@
 
 public String toString()
 	{
-	StringBuffer str = new StringBuffer();;
+	StringBuffer str = new StringBuffer();
 	int mod = getModifiers();
 
 	// Modifier
-	if ((mod & 1) == 1) {
+	if (Modifier.isPublic(mod)) {
 		str.append("public ");
 	}
-	else if ((mod & 2) == 2) {
+	else if (Modifier.isPrivate(mod)) {
 		str.append("private ");
 	}
-	else if ((mod & 4) == 4) {
+	else if (Modifier.isProtected(mod)) {
 		str.append("protected ");
 	}
 
@@ -112,7 +112,17 @@
 		}
 	}
 	str.append(")");
+	
+        if (exceptionTypes.length > 0) {
+	        str.append(" throws ");
+                for (int i = 0; i < exceptionTypes.length; i++) {
+                        str.append(exceptionTypes[i].getName());
+                        if (i+1 < exceptionTypes.length) {
+			        str.append(",");
+                        }
+                }
+        }
 
 	return (new String(str));
-}
+	}
 }


More information about the kaffe mailing list