1 // Method.java - Represent method of class or interface.
3 /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 package java
.lang
.reflect
;
13 import gnu
.gcj
.RawData
;
16 * @author Tom Tromey <tromey@cygnus.com>
17 * @date December 12, 1998
19 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
20 * "The Java Language Specification", ISBN 0-201-63451-1
21 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
22 * Status: Complete, but not correct: access checks aren't done.
25 public final class Method
extends AccessibleObject
implements Member
27 public boolean equals (Object obj
)
29 if (! (obj
instanceof Method
))
31 Method m
= (Method
) obj
;
32 return declaringClass
== m
.declaringClass
&& offset
== m
.offset
;
35 public Class
getDeclaringClass ()
37 return declaringClass
;
40 public Class
[] getExceptionTypes ()
42 if (exception_types
== null)
44 return (Class
[]) exception_types
.clone();
47 public native int getModifiers ();
49 public native String
getName ();
51 private native void getType ();
53 public Class
[] getParameterTypes ()
55 if (parameter_types
== null)
57 return (Class
[]) parameter_types
.clone();
60 public Class
getReturnType ()
62 if (return_type
== null)
67 public int hashCode ()
70 return getName().hashCode() + declaringClass
.getName().hashCode();
73 public native Object
invoke (Object obj
, Object
[] args
)
74 throws IllegalAccessException
, IllegalArgumentException
,
75 InvocationTargetException
;
77 // Append a class name to a string buffer. We try to print the
78 // fully-qualified name, the way that a Java programmer would expect
79 // it to be written. Weirdly, Class has no appropriate method for
81 static void appendClassName (StringBuffer buf
, Class k
)
85 appendClassName (buf
, k
.getComponentType ());
90 // This is correct for primitive and reference types. Really
91 // we'd like `Main$Inner' to be printed as `Main.Inner', I
92 // think, but that is a pain.
93 buf
.append (k
.getName ());
97 public String
toString ()
99 if (parameter_types
== null)
102 StringBuffer b
= new StringBuffer ();
103 Modifier
.toString(getModifiers(), b
);
105 appendClassName (b
, return_type
);
107 appendClassName (b
, declaringClass
);
111 for (int i
= 0; i
< parameter_types
.length
; ++i
)
113 appendClassName (b
, parameter_types
[i
]);
114 if (i
< parameter_types
.length
- 1)
118 if (exception_types
.length
> 0)
120 b
.append(" throws ");
121 for (int i
= 0; i
< exception_types
.length
; ++i
)
123 appendClassName (b
, exception_types
[i
]);
124 if (i
< exception_types
.length
- 1)
136 private Class declaringClass
;
139 private Class
[] exception_types
;
140 // Name cache. (Initially null.)
143 private Class
[] parameter_types
;
145 private Class return_type
;
147 // Offset in bytes from the start of declaringClass's methods array.