OSDN Git Service

* All files: Updated copyright to reflect Cygnus purchase.
[pf3gnuchains/gcc-fork.git] / libjava / java / lang / reflect / Constructor.java
1 // Constructor.java - Represents a constructor for a class.
2
3 /* Copyright (C) 1998, 1999  Red Hat, Inc.
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  *          newInstance() needs to be written.
22  */
23
24 public final class Constructor extends AccessibleObject implements Member
25 {
26   public boolean equals (Object obj)
27     {
28       if (! (obj instanceof Constructor))
29         return false;
30       Constructor c = (Constructor) obj;
31       return declaringClass == c.declaringClass && offset == c.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 String getName ()
47   {
48     return declaringClass.getName();
49   }
50
51   public Class[] getParameterTypes ()
52     {
53       if (parameter_types == null)
54         getType ();
55       return (Class[]) parameter_types.clone();
56     }
57
58   public int hashCode ()
59     {
60       // FIXME.
61       return getName().hashCode() + declaringClass.getName().hashCode();
62     }
63
64   // Update cached values from method descriptor in class.
65   private native void getType ();
66
67   public native Object newInstance (Object[] args)
68     throws InstantiationException, IllegalAccessException,
69            IllegalArgumentException, InvocationTargetException;
70
71   public String toString ()
72     {
73       if (parameter_types == null)
74         getType ();
75       StringBuffer b = new StringBuffer ();
76       b.append(Modifier.toString(getModifiers()));
77       b.append(" ");
78       b.append(getName());
79       b.append("(");
80       for (int i = 0; i < parameter_types.length; ++i)
81         {
82           b.append(parameter_types[i].toString());
83           if (i < parameter_types.length - 1)
84             b.append(",");
85         }
86       b.append(")");
87       return b.toString();
88     }
89
90   // Can't create these.
91   private Constructor ()
92     {
93     }
94
95   // Declaring class.
96   private Class declaringClass;
97
98   // Exception types.
99   private Class[] exception_types;
100   // Parameter types.
101   private Class[] parameter_types;
102
103   // Offset in bytes from the start of declaringClass's methods array.
104   private int offset;
105 }