FSF GCC merge 02/23/03
[official-gcc.git] / libjava / java / lang / reflect / Constructor.java
blob4a30e2ae394a803621c222c8d7564598fcda7f6d
1 // Constructor.java - Represents a constructor for a class.
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
9 details. */
11 package java.lang.reflect;
13 /**
14 * @author Tom Tromey <tromey@cygnus.com>
15 * @date December 12, 1998
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 * newInstance() needs to be written.
24 public final class Constructor extends AccessibleObject implements Member
26 public boolean equals (Object obj)
28 if (! (obj instanceof Constructor))
29 return false;
30 Constructor c = (Constructor) obj;
31 return declaringClass == c.declaringClass && offset == c.offset;
34 public Class getDeclaringClass ()
36 return declaringClass;
39 public Class[] getExceptionTypes ()
41 if (exception_types == null)
42 getType();
43 return (Class[]) exception_types.clone();
46 public native int getModifiers ();
48 public String getName ()
50 return declaringClass.getName();
53 public Class[] getParameterTypes ()
55 if (parameter_types == null)
56 getType ();
57 return (Class[]) parameter_types.clone();
60 public int hashCode ()
62 // FIXME.
63 return getName().hashCode() + declaringClass.getName().hashCode();
66 // Update cached values from method descriptor in class.
67 private native void getType ();
69 public native Object newInstance (Object[] args)
70 throws InstantiationException, IllegalAccessException,
71 IllegalArgumentException, InvocationTargetException;
73 public String toString ()
75 if (parameter_types == null)
76 getType ();
77 StringBuffer b = new StringBuffer ();
78 Modifier.toString(getModifiers(), b);
79 b.append(" ");
80 Method.appendClassName (b, declaringClass);
81 b.append("(");
82 for (int i = 0; i < parameter_types.length; ++i)
84 Method.appendClassName (b, parameter_types[i]);
85 if (i < parameter_types.length - 1)
86 b.append(",");
88 b.append(")");
89 return b.toString();
92 // Can't create these.
93 private Constructor ()
97 // Declaring class.
98 private Class declaringClass;
100 // Exception types.
101 private Class[] exception_types;
102 // Parameter types.
103 private Class[] parameter_types;
105 // Offset in bytes from the start of declaringClass's methods array.
106 private int offset;