OSDN Git Service

libjava/ChangeLog:
[pf3gnuchains/gcc-fork.git] / libjava / classpath / vm / reference / java / lang / reflect / VMConstructor.java
1 /* java.lang.reflect.VMConstructor - VM interface for reflection of Java constructors
2    Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10  
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package java.lang.reflect;
40
41 import java.lang.annotation.Annotation;
42
43 import java.util.Arrays;
44
45 final class VMConstructor
46 {
47   Class clazz;
48   int slot;
49
50   /** 
51    * This field allows us to refer back to the main constructor instance.
52    *  It is set by the constructor of Constructor.
53    */
54   Constructor cons;
55
56   VMConstructor(Class clazz, int slot)
57   {
58     this.clazz = clazz;
59     this.slot = slot;
60   }
61
62   public Class getDeclaringClass()
63   {
64     return clazz;
65   }
66
67   /**
68    * Return the raw modifiers for this constructor.  In particular
69    * this will include the synthetic and varargs bits.
70    * @return the constructor's modifiers
71    */
72   native int getModifiersInternal();
73
74   /**
75    * Get the parameter list for this constructor, in declaration order. If the
76    * constructor takes no parameters, returns a 0-length array (not null).
77    *
78    * @return a list of the types of the constructor's parameters
79    */
80   native Class[] getParameterTypes();
81
82   /**
83    * Get the exception types this constructor says it throws, in no particular
84    * order. If the constructor has no throws clause, returns a 0-length array
85    * (not null).
86    *
87    * @return a list of the types in the constructor's throws clause
88    */
89   native Class[] getExceptionTypes();
90
91   native Object construct(Object[] args)
92     throws InstantiationException, IllegalAccessException,
93     InvocationTargetException;
94
95   /**
96    * Return the String in the Signature attribute for this constructor. If there
97    * is no Signature attribute, return null.
98    */
99   native String getSignature();
100   
101   /**
102    * <p>
103    * Return an array of arrays representing the annotations on each
104    * of the constructor's parameters.  The outer array is aligned against
105    * the parameters of the constructors and is thus equal in length to
106    * the number of parameters (thus having a length zero if there are none).
107    * Each array element in the outer array contains an inner array which
108    * holds the annotations.  This array has a length of zero if the parameter
109    * has no annotations.
110    * </p>
111    * <p>
112    * The returned annotations are serialized.  Changing the annotations has
113    * no affect on the return value of future calls to this method.
114    * </p>
115    * 
116    * @return an array of arrays which represents the annotations used on the
117    *         parameters of this constructor.  The order of the array elements
118    *         matches the declaration order of the parameters.
119    * @since 1.5
120    */
121   native Annotation[][] getParameterAnnotations();
122
123   /**
124    * Compare two objects to see if they are semantically equivalent.
125    * Two Constructors are semantically equivalent if they have the same
126    * declaring class and the same parameter list.  This ignores different
127    * exception clauses, but since you can't create a Method except through the
128    * VM, this is just the == relation.
129    *
130    * @param o the object to compare to
131    * @return <code>true</code> if they are equal; <code>false</code> if not.
132    */
133   public boolean equals(Object o)
134   {
135     if (!(o instanceof Constructor))
136       return false;
137     Constructor that = (Constructor)o; 
138     if (clazz != that.getDeclaringClass())
139       return false;
140     if (!Arrays.equals(getParameterTypes(), that.getParameterTypes()))
141       return false;
142     return true;
143   }
144
145   /**
146    * Returns the element's annotation for the specified annotation type,
147    * or <code>null</code> if no such annotation exists.
148    *
149    * @param annotationClass the type of annotation to look for.
150    * @return this element's annotation for the specified type, or
151    *         <code>null</code> if no such annotation exists.
152    * @throws NullPointerException if the annotation class is <code>null</code>.
153    */
154   native Annotation getAnnotation(Class annotationClass);
155
156   /**
157    * Returns all annotations directly defined by the element.  If there are
158    * no annotations directly associated with the element, then a zero-length
159    * array will be returned.  The returned array may be modified by the client
160    * code, but this will have no effect on the annotation content of this
161    * class, and hence no effect on the return value of this method for
162    * future callers.
163    *
164    * @return the annotations directly defined by the element.
165    * @since 1.5
166    */
167   native Annotation[] getDeclaredAnnotations();
168
169 }