Initial revision
[gcc.git] / libjava / java / lang / reflect / Method.java
1 // Method.java - Represent method of class or interface.
2
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
4
5 This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
10
11 package java.lang.reflect;
12
13 /**
14 * @author Tom Tromey <tromey@cygnus.com>
15 * @date December 12, 1998
16 */
17 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
18 * "The Java Language Specification", ISBN 0-201-63451-1
19 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
20 * Status: Incomplete: needs a private constructor, and
21 * invoke() needs to be finished.
22 */
23
24 public final class Method extends AccessibleObject implements Member
25 {
26 public boolean equals (Object obj)
27 {
28 if (! (obj instanceof Method))
29 return false;
30 Method m = (Method) obj;
31 return declaringClass == m.declaringClass && offset == m.offset;
32 }
33
34 public Class getDeclaringClass ()
35 {
36 return declaringClass;
37 }
38
39 public Class[] getExceptionTypes ()
40 {
41 return (Class[]) exception_types.clone();
42 }
43
44 public native int getModifiers ();
45
46 public native String getName ();
47
48 private native void getType ();
49
50 public Class[] getParameterTypes ()
51 {
52 if (parameter_types == null)
53 getType();
54 return (Class[]) parameter_types.clone();
55 }
56
57 public Class getReturnType ()
58 {
59 if (return_type == null)
60 getType();
61 return return_type;
62 }
63
64 public int hashCode ()
65 {
66 // FIXME.
67 return name.hashCode() + declaringClass.getName().hashCode();
68 }
69
70 public native Object invoke (Object obj, Object[] args)
71 throws IllegalAccessException, IllegalArgumentException,
72 InvocationTargetException;
73
74 public String toString ()
75 {
76 StringBuffer b = new StringBuffer ();
77 b.append(Modifier.toString(getModifiers()));
78 b.append(" ");
79 b.append(return_type.toString());
80 b.append(" ");
81 b.append(declaringClass.toString());
82 b.append(".");
83 b.append(name);
84 b.append("(");
85 for (int i = 0; i < parameter_types.length; ++i)
86 {
87 b.append(parameter_types[i].toString());
88 if (i < parameter_types.length - 1)
89 b.append(",");
90 }
91 b.append(")");
92 if (exception_types.length > 0)
93 {
94 b.append(" throws ");
95 for (int i = 0; i < exception_types.length; ++i)
96 {
97 b.append(exception_types[i].toString());
98 if (i < exception_types.length - 1)
99 b.append(",");
100 }
101 }
102 return b.toString();
103 }
104
105 private Method ()
106 {
107 }
108
109 // Declaring class.
110 private Class declaringClass;
111
112 // Exception types.
113 private Class[] exception_types;
114 // Name cache. (Initially null.)
115 private String name;
116 // Parameter types.
117 private Class[] parameter_types;
118 // Return type.
119 private Class return_type;
120
121 // Offset in bytes from the start of declaringClass's methods array.
122 private int offset;
123 }