Configured build for Ubuntu and added Stempel polish analyzer
[pylucene.git] / jcc / _jcc / java / lang / reflect / Constructor.cpp
1 /*
2  *   Licensed under the Apache License, Version 2.0 (the "License");
3  *   you may not use this file except in compliance with the License.
4  *   You may obtain a copy of the License at
5  *
6  *       http://www.apache.org/licenses/LICENSE-2.0
7  *
8  *   Unless required by applicable law or agreed to in writing, software
9  *   distributed under the License is distributed on an "AS IS" BASIS,
10  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  *   See the License for the specific language governing permissions and
12  *   limitations under the License.
13  */
14
15 #include <jni.h>
16 #include "JCCEnv.h"
17 #include "JArray.h"
18
19 #include "java/lang/Class.h"
20 #include "java/lang/Object.h"
21 #include "java/lang/String.h"
22 #include "java/lang/reflect/Constructor.h"
23 #ifdef _java_generics
24 #include "java/lang/reflect/Type.h"
25 #include "java/lang/reflect/TypeVariable.h"
26 #endif
27
28 namespace java {
29     namespace lang {
30         namespace reflect {
31
32             enum {
33                 mid_getModifiers,
34                 mid_getSignature,
35                 mid_getParameterTypes,
36                 mid_getExceptionTypes,
37 #ifdef _java_generics
38                 mid_getTypeParameters,
39                 mid_getGenericExceptionTypes,
40                 mid_getGenericParameterTypes,
41 #endif
42                 max_mid
43             };
44
45             Class *Constructor::class$ = NULL;
46             jmethodID *Constructor::_mids = NULL;
47
48             jclass Constructor::initializeClass()
49             {
50                 if (!class$)
51                 {
52                     jclass cls = env->findClass("java/lang/reflect/Constructor");
53
54                     _mids = new jmethodID[max_mid];
55                     _mids[mid_getModifiers] =
56                         env->getMethodID(cls, "getModifiers",
57                                          "()I");
58                     _mids[mid_getParameterTypes] =
59                         env->getMethodID(cls, "getParameterTypes",
60                                          "()[Ljava/lang/Class;");
61                     _mids[mid_getExceptionTypes] =
62                         env->getMethodID(cls, "getExceptionTypes",
63                                          "()[Ljava/lang/Class;");
64
65 #ifdef _java_generics
66                     _mids[mid_getTypeParameters] =
67                         env->getMethodID(cls, "getTypeParameters",
68                                          "()[Ljava/lang/reflect/TypeVariable;");
69                     _mids[mid_getGenericExceptionTypes] =
70                         env->getMethodID(cls, "getGenericExceptionTypes",
71                                          "()[Ljava/lang/reflect/Type;");
72                     _mids[mid_getGenericParameterTypes] =
73                         env->getMethodID(cls, "getGenericParameterTypes",
74                                          "()[Ljava/lang/reflect/Type;");
75 #endif
76
77                     class$ = (Class *) new JObject(cls);
78                 }
79                 
80                 return (jclass) class$->this$;
81             }
82
83             int Constructor::getModifiers() const
84             {
85                 return env->callIntMethod(this$, _mids[mid_getModifiers]);
86             }
87
88             JArray<Class> Constructor::getParameterTypes() const
89             {
90                 jobjectArray array = (jobjectArray)
91                     env->callObjectMethod(this$, _mids[mid_getParameterTypes]);
92
93                 return JArray<Class>(array);
94             }
95
96             JArray<Class> Constructor::getExceptionTypes() const
97             {
98                 jobjectArray array = (jobjectArray)
99                     env->callObjectMethod(this$, _mids[mid_getExceptionTypes]);
100
101                 return JArray<Class>(array);
102             }
103
104 #ifdef _java_generics
105             JArray<TypeVariable> Constructor::getTypeParameters() const
106             {
107                 return JArray<TypeVariable>(env->callObjectMethod(this$, _mids[mid_getTypeParameters]));
108             }
109
110             JArray<Type> Constructor::getGenericExceptionTypes() const
111             {
112                 return JArray<Type>(env->callObjectMethod(this$, _mids[mid_getGenericExceptionTypes]));
113             }
114
115             JArray<Type> Constructor::getGenericParameterTypes() const
116             {
117                 return JArray<Type>(env->callObjectMethod(this$, _mids[mid_getGenericParameterTypes]));
118             }
119 #endif
120         }
121     }
122 }
123
124
125 #include "structmember.h"
126 #include "functions.h"
127 #include "macros.h"
128
129 namespace java {
130     namespace lang {
131         namespace reflect {
132
133             static PyObject *t_Constructor_getModifiers(t_Constructor *self);
134             static PyObject *t_Constructor_getParameterTypes(t_Constructor *self);
135             static PyObject *t_Constructor_getExceptionTypes(t_Constructor *self);
136 #ifdef _java_generics
137             static PyObject *t_Constructor_getTypeParameters(t_Constructor *self);
138             static PyObject *t_Constructor_getGenericExceptionTypes(t_Constructor *self);
139             static PyObject *t_Constructor_getGenericParameterTypes(t_Constructor *self);
140 #endif
141
142             static PyMethodDef t_Constructor__methods_[] = {
143                 DECLARE_METHOD(t_Constructor, getModifiers, METH_NOARGS),
144                 DECLARE_METHOD(t_Constructor, getParameterTypes, METH_NOARGS),
145                 DECLARE_METHOD(t_Constructor, getExceptionTypes, METH_NOARGS),
146 #ifdef _java_generics
147                 DECLARE_METHOD(t_Constructor, getTypeParameters, METH_NOARGS),
148                 DECLARE_METHOD(t_Constructor, getGenericExceptionTypes, METH_NOARGS),
149                 DECLARE_METHOD(t_Constructor, getGenericParameterTypes, METH_NOARGS),
150 #endif
151                 { NULL, NULL, 0, NULL }
152             };
153
154             DECLARE_TYPE(Constructor, t_Constructor, Object, Constructor,
155                          abstract_init, 0, 0, 0, 0, 0);
156
157             static PyObject *t_Constructor_getModifiers(t_Constructor *self)
158             {
159                 jint modifiers;
160
161                 OBJ_CALL(modifiers = self->object.getModifiers());
162                 return PyInt_FromLong(modifiers);                
163             }
164
165             static PyObject *t_Constructor_getParameterTypes(t_Constructor *self)
166             {
167                 JArray<Class> types((jobject) NULL);
168                 OBJ_CALL(types = self->object.getParameterTypes());
169                 return types.toSequence(t_Class::wrap_Object);
170             }
171
172             static PyObject *t_Constructor_getExceptionTypes(t_Constructor *self)
173             {
174                 JArray<Class> types((jobject) NULL);
175                 OBJ_CALL(types = self->object.getExceptionTypes());
176                 return types.toSequence(t_Class::wrap_Object);
177             }
178
179 #ifdef _java_generics
180             static PyObject *t_Constructor_getTypeParameters(t_Constructor *self)
181             {
182                 JArray<TypeVariable> result((jobject) NULL);
183                 OBJ_CALL(result = self->object.getTypeParameters());
184
185                 return result.toSequence(t_TypeVariable::wrap_Object);
186             }
187
188             static PyObject *t_Constructor_getGenericExceptionTypes(t_Constructor *self)
189             {
190                 JArray<Type> result((jobject) NULL);
191                 OBJ_CALL(result = self->object.getGenericExceptionTypes());
192
193                 return result.toSequence(t_Type::wrap_Object);
194             }
195
196             static PyObject *t_Constructor_getGenericParameterTypes(t_Constructor *self)
197             {
198                 JArray<Type> result((jobject) NULL);
199                 OBJ_CALL(result = self->object.getGenericParameterTypes());
200
201                 return result.toSequence(t_Type::wrap_Object);
202             }
203 #endif
204         }
205     }
206 }