aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/lang/reflect
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2001-08-24 17:24:44 +0000
committerTom Tromey <tromey@gcc.gnu.org>2001-08-24 17:24:44 +0000
commit224b7b7b0c8a69e60e87a871a9ed828c99f389d8 (patch)
treeb60d1cfd5772caf8f4b4422879feb1f039755a71 /libjava/java/lang/reflect
parent66b461ce02570f05b7ddd76e2de1a82f3a6618e3 (diff)
downloadgcc-224b7b7b0c8a69e60e87a871a9ed828c99f389d8.zip
gcc-224b7b7b0c8a69e60e87a871a9ed828c99f389d8.tar.gz
gcc-224b7b7b0c8a69e60e87a871a9ed828c99f389d8.tar.bz2
Field.java (toString): Use Method.appendClassName.
* java/lang/reflect/Field.java (toString): Use Method.appendClassName. * java/lang/reflect/Constructor.java (toString): Use Method.appendClassName. * java/lang/reflect/Method.java: Reindented. (appendClassName): New method. (toString): Use it. * defineclass.cc (handleMethod ): Initialize `throws' field of method. (read_one_method_attribute): Handle Exceptions attribute. * java/lang/reflect/natMethod.cc (ClassClass): Removed. (ObjectClass): Removed. (getType): Compute `exception_types'. * java/lang/Class.h (struct _Jv_Method): Added `throws' field. From-SVN: r45153
Diffstat (limited to 'libjava/java/lang/reflect')
-rw-r--r--libjava/java/lang/reflect/Constructor.java4
-rw-r--r--libjava/java/lang/reflect/Field.java6
-rw-r--r--libjava/java/lang/reflect/Method.java142
-rw-r--r--libjava/java/lang/reflect/natMethod.cc29
4 files changed, 105 insertions, 76 deletions
diff --git a/libjava/java/lang/reflect/Constructor.java b/libjava/java/lang/reflect/Constructor.java
index 2d527c3..cd07a43 100644
--- a/libjava/java/lang/reflect/Constructor.java
+++ b/libjava/java/lang/reflect/Constructor.java
@@ -77,11 +77,11 @@ public final class Constructor extends AccessibleObject implements Member
StringBuffer b = new StringBuffer ();
b.append(Modifier.toString(getModifiers()));
b.append(" ");
- b.append(getName());
+ Method.appendClassName (b, declaringClass);
b.append("(");
for (int i = 0; i < parameter_types.length; ++i)
{
- b.append(parameter_types[i].getName());
+ Method.appendClassName (b, parameter_types[i]);
if (i < parameter_types.length - 1)
b.append(",");
}
diff --git a/libjava/java/lang/reflect/Field.java b/libjava/java/lang/reflect/Field.java
index 76243f3..aad5148 100644
--- a/libjava/java/lang/reflect/Field.java
+++ b/libjava/java/lang/reflect/Field.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
@@ -257,9 +257,9 @@ public final class Field extends AccessibleObject implements Member
Modifier.toString(mods, sbuf);
sbuf.append(' ');
}
- sbuf.append(getType().getName());
+ Method.appendClassName (sbuf, getType ());
sbuf.append(' ');
- sbuf.append(getDeclaringClass().getName());
+ Method.appendClassName (sbuf, getDeclaringClass());
sbuf.append('.');
sbuf.append(getName());
return sbuf.toString();
diff --git a/libjava/java/lang/reflect/Method.java b/libjava/java/lang/reflect/Method.java
index e616670..7bd0a31 100644
--- a/libjava/java/lang/reflect/Method.java
+++ b/libjava/java/lang/reflect/Method.java
@@ -25,24 +25,24 @@ import gnu.gcj.RawData;
public final class Method extends AccessibleObject implements Member
{
public boolean equals (Object obj)
- {
- if (! (obj instanceof Method))
- return false;
- Method m = (Method) obj;
- return declaringClass == m.declaringClass && offset == m.offset;
- }
+ {
+ if (! (obj instanceof Method))
+ return false;
+ Method m = (Method) obj;
+ return declaringClass == m.declaringClass && offset == m.offset;
+ }
public Class getDeclaringClass ()
- {
- return declaringClass;
- }
+ {
+ return declaringClass;
+ }
public Class[] getExceptionTypes ()
- {
- if (exception_types == null)
- getType();
- return (Class[]) exception_types.clone();
- }
+ {
+ if (exception_types == null)
+ getType();
+ return (Class[]) exception_types.clone();
+ }
public native int getModifiers ();
@@ -51,62 +51,82 @@ public final class Method extends AccessibleObject implements Member
private native void getType ();
public Class[] getParameterTypes ()
- {
- if (parameter_types == null)
- getType();
- return (Class[]) parameter_types.clone();
- }
+ {
+ if (parameter_types == null)
+ getType();
+ return (Class[]) parameter_types.clone();
+ }
public Class getReturnType ()
- {
- if (return_type == null)
- getType();
- return return_type;
- }
+ {
+ if (return_type == null)
+ getType();
+ return return_type;
+ }
public int hashCode ()
- {
- // FIXME.
- return getName().hashCode() + declaringClass.getName().hashCode();
- }
+ {
+ // FIXME.
+ return getName().hashCode() + declaringClass.getName().hashCode();
+ }
public native Object invoke (Object obj, Object[] args)
throws IllegalAccessException, IllegalArgumentException,
- InvocationTargetException;
+ InvocationTargetException;
+
+ // Append a class name to a string buffer. We try to print the
+ // fully-qualified name, the way that a Java programmer would expect
+ // it to be written. Weirdly, Class has no appropriate method for
+ // this.
+ static void appendClassName (StringBuffer buf, Class k)
+ {
+ if (k.isArray ())
+ {
+ appendClassName (buf, k.getComponentType ());
+ buf.append ("[]");
+ }
+ else
+ {
+ // This is correct for primitive and reference types. Really
+ // we'd like `Main$Inner' to be printed as `Main.Inner', I
+ // think, but that is a pain.
+ buf.append (k.getName ());
+ }
+ }
public String toString ()
- {
- if (parameter_types == null)
- getType ();
-
- StringBuffer b = new StringBuffer ();
- Modifier.toString(getModifiers(), b);
- b.append(" ");
- b.append(return_type.getName());
- b.append(" ");
- b.append(declaringClass.getName());
- b.append(".");
- b.append(getName());
- b.append("(");
- for (int i = 0; i < parameter_types.length; ++i)
- {
- b.append(parameter_types[i].getName());
- if (i < parameter_types.length - 1)
- b.append(",");
- }
- b.append(")");
- if (exception_types.length > 0)
- {
- b.append(" throws ");
- for (int i = 0; i < exception_types.length; ++i)
- {
- b.append(exception_types[i].getName());
- if (i < exception_types.length - 1)
- b.append(",");
- }
- }
- return b.toString();
- }
+ {
+ if (parameter_types == null)
+ getType ();
+
+ StringBuffer b = new StringBuffer ();
+ Modifier.toString(getModifiers(), b);
+ b.append(" ");
+ appendClassName (b, return_type);
+ b.append(" ");
+ appendClassName (b, declaringClass);
+ b.append(".");
+ b.append(getName());
+ b.append("(");
+ for (int i = 0; i < parameter_types.length; ++i)
+ {
+ appendClassName (b, parameter_types[i]);
+ if (i < parameter_types.length - 1)
+ b.append(",");
+ }
+ b.append(")");
+ if (exception_types.length > 0)
+ {
+ b.append(" throws ");
+ for (int i = 0; i < exception_types.length; ++i)
+ {
+ appendClassName (b, exception_types[i]);
+ if (i < exception_types.length - 1)
+ b.append(",");
+ }
+ }
+ return b.toString();
+ }
private Method ()
{
diff --git a/libjava/java/lang/reflect/natMethod.cc b/libjava/java/lang/reflect/natMethod.cc
index f269d2f..96cc132 100644
--- a/libjava/java/lang/reflect/natMethod.cc
+++ b/libjava/java/lang/reflect/natMethod.cc
@@ -1,6 +1,6 @@
// natMethod.cc - Native code for Method class.
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
@@ -38,10 +38,6 @@ details. */
#include <gcj/method.h>
#include <gnu/gcj/RawData.h>
-// FIXME: remove these
-#define ObjectClass java::lang::Object::class$
-#define ClassClass java::lang::Class::class$
-
#include <stdlib.h>
#if USE_LIBFFI
@@ -200,14 +196,27 @@ java::lang::reflect::Method::getName ()
void
java::lang::reflect::Method::getType ()
{
- _Jv_GetTypesFromSignature (_Jv_FromReflectedMethod (this),
+ _Jv_Method *method = _Jv_FromReflectedMethod (this);
+ _Jv_GetTypesFromSignature (method,
declaringClass,
&parameter_types,
&return_type);
- // FIXME: for now we have no way to get exception information.
- exception_types = (JArray<jclass> *) JvNewObjectArray (0, &ClassClass,
- NULL);
+ int count = 0;
+ if (method->throws != NULL)
+ {
+ while (method->throws[count] != NULL)
+ ++count;
+ }
+
+ exception_types
+ = (JArray<jclass> *) JvNewObjectArray (count,
+ &java::lang::Class::class$,
+ NULL);
+ jclass *elts = elements (exception_types);
+ for (int i = 0; i < count; ++i)
+ elts[i] = _Jv_FindClassFromSignature (method->throws[i]->data,
+ declaringClass->getClassLoader ());
}
void
@@ -254,7 +263,7 @@ _Jv_GetTypesFromSignature (jmethodID method,
}
JArray<jclass> *args = (JArray<jclass> *)
- JvNewObjectArray (numArgs, &ClassClass, NULL);
+ JvNewObjectArray (numArgs, &java::lang::Class::class$, NULL);
jclass* argPtr = elements (args);
for (ptr = sig->data; *ptr != '\0'; ptr++)
{