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
6 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "java/lang/Class.h"
20 #include "java/lang/Object.h"
21 #include "java/lang/String.h"
22 #include "java/lang/reflect/Method.h"
24 #include "java/lang/reflect/Type.h"
25 #include "java/lang/reflect/TypeVariable.h"
36 mid_getParameterTypes,
37 mid_getExceptionTypes,
38 mid_getDeclaringClass,
40 mid_getTypeParameters,
41 mid_getGenericExceptionTypes,
42 mid_getGenericParameterTypes,
43 mid_getGenericReturnType,
48 Class *Method::class$ = NULL;
49 jmethodID *Method::_mids = NULL;
51 jclass Method::initializeClass()
55 jclass cls = env->findClass("java/lang/reflect/Method");
57 _mids = new jmethodID[max_mid];
58 _mids[mid_getModifiers] =
59 env->getMethodID(cls, "getModifiers",
61 _mids[mid_getReturnType] =
62 env->getMethodID(cls, "getReturnType",
63 "()Ljava/lang/Class;");
65 env->getMethodID(cls, "getName",
66 "()Ljava/lang/String;");
68 _mids[mid_getParameterTypes] =
69 env->getMethodID(cls, "getParameterTypes",
70 "()[Ljava/lang/Class;");
71 _mids[mid_getExceptionTypes] =
72 env->getMethodID(cls, "getExceptionTypes",
73 "()[Ljava/lang/Class;");
74 _mids[mid_getDeclaringClass] =
75 env->getMethodID(cls, "getDeclaringClass",
76 "()Ljava/lang/Class;");
78 _mids[mid_getTypeParameters] =
79 env->getMethodID(cls, "getTypeParameters",
80 "()[Ljava/lang/reflect/TypeVariable;");
81 _mids[mid_getGenericExceptionTypes] =
82 env->getMethodID(cls, "getGenericExceptionTypes",
83 "()[Ljava/lang/reflect/Type;");
84 _mids[mid_getGenericParameterTypes] =
85 env->getMethodID(cls, "getGenericParameterTypes",
86 "()[Ljava/lang/reflect/Type;");
87 _mids[mid_getGenericReturnType] =
88 env->getMethodID(cls, "getGenericReturnType",
89 "()Ljava/lang/reflect/Type;");
92 class$ = (Class *) new JObject(cls);
95 return (jclass) class$->this$;
98 int Method::getModifiers() const
100 return env->callIntMethod(this$, _mids[mid_getModifiers]);
103 Class Method::getReturnType() const
105 return Class(env->callObjectMethod(this$, _mids[mid_getReturnType]));
108 String Method::getName() const
110 return String(env->callObjectMethod(this$, _mids[mid_getName]));
113 JArray<Class> Method::getParameterTypes() const
115 jobjectArray array = (jobjectArray)
116 env->callObjectMethod(this$, _mids[mid_getParameterTypes]);
118 return JArray<Class>(array);
121 JArray<Class> Method::getExceptionTypes() const
123 jobjectArray array = (jobjectArray)
124 env->callObjectMethod(this$, _mids[mid_getExceptionTypes]);
126 return JArray<Class>(array);
129 Class Method::getDeclaringClass() const
131 return Class(env->callObjectMethod(this$, _mids[mid_getDeclaringClass]));
134 #ifdef _java_generics
135 JArray<TypeVariable> Method::getTypeParameters() const
137 return JArray<TypeVariable>(env->callObjectMethod(this$, _mids[mid_getTypeParameters]));
140 JArray<Type> Method::getGenericExceptionTypes() const
142 return JArray<Type>(env->callObjectMethod(this$, _mids[mid_getGenericExceptionTypes]));
145 JArray<Type> Method::getGenericParameterTypes() const
147 return JArray<Type>(env->callObjectMethod(this$, _mids[mid_getGenericParameterTypes]));
150 Type Method::getGenericReturnType() const
152 return Type(env->callObjectMethod(this$, _mids[mid_getGenericReturnType]));
160 #include "structmember.h"
161 #include "functions.h"
168 static PyObject *t_Method_cast_(PyTypeObject *type, PyObject *arg);
169 static PyObject *t_Method_instance_(PyTypeObject *type, PyObject *arg);
170 static PyObject *t_Method_getModifiers(t_Method *self);
171 static PyObject *t_Method_getReturnType(t_Method *self);
172 static PyObject *t_Method_getName(t_Method *self);
173 static PyObject *t_Method_getParameterTypes(t_Method *self);
174 static PyObject *t_Method_getExceptionTypes(t_Method *self);
175 static PyObject *t_Method_getDeclaringClass(t_Method *self);
176 #ifdef _java_generics
177 static PyObject *t_Method_getTypeParameters(t_Method *self);
178 static PyObject *t_Method_getGenericExceptionTypes(t_Method *self);
179 static PyObject *t_Method_getGenericParameterTypes(t_Method *self);
180 static PyObject *t_Method_getGenericReturnType(t_Method *self);
183 static PyMethodDef t_Method__methods_[] = {
184 DECLARE_METHOD(t_Method, cast_, METH_O | METH_CLASS),
185 DECLARE_METHOD(t_Method, instance_, METH_O | METH_CLASS),
186 DECLARE_METHOD(t_Method, getModifiers, METH_NOARGS),
187 DECLARE_METHOD(t_Method, getReturnType, METH_NOARGS),
188 DECLARE_METHOD(t_Method, getName, METH_NOARGS),
189 DECLARE_METHOD(t_Method, getParameterTypes, METH_NOARGS),
190 DECLARE_METHOD(t_Method, getExceptionTypes, METH_NOARGS),
191 DECLARE_METHOD(t_Method, getDeclaringClass, METH_NOARGS),
192 #ifdef _java_generics
193 DECLARE_METHOD(t_Method, getTypeParameters, METH_NOARGS),
194 DECLARE_METHOD(t_Method, getGenericExceptionTypes, METH_NOARGS),
195 DECLARE_METHOD(t_Method, getGenericParameterTypes, METH_NOARGS),
196 DECLARE_METHOD(t_Method, getGenericReturnType, METH_NOARGS),
198 { NULL, NULL, 0, NULL }
201 DECLARE_TYPE(Method, t_Method, Object, Method,
202 abstract_init, 0, 0, 0, 0, 0);
204 static PyObject *t_Method_cast_(PyTypeObject *type, PyObject *arg)
206 if (!(arg = castCheck(arg, Method::initializeClass, 1)))
208 return t_Method::wrap_Object(Method(((t_Method *) arg)->object.this$));
211 static PyObject *t_Method_instance_(PyTypeObject *type, PyObject *arg)
213 if (!castCheck(arg, Method::initializeClass, 0))
218 static PyObject *t_Method_getModifiers(t_Method *self)
222 OBJ_CALL(modifiers = self->object.getModifiers());
223 return PyInt_FromLong(modifiers);
226 static PyObject *t_Method_getReturnType(t_Method *self)
228 Class cls((jobject) NULL);
230 OBJ_CALL(cls = self->object.getReturnType());
231 return t_Class::wrap_Object(cls);
234 static PyObject *t_Method_getName(t_Method *self)
236 String name((jobject) NULL);
238 OBJ_CALL(name = self->object.getName());
242 static PyObject *t_Method_getParameterTypes(t_Method *self)
244 JArray<Class> types((jobject) NULL);
246 OBJ_CALL(types = self->object.getParameterTypes());
247 return types.toSequence(t_Class::wrap_Object);
250 static PyObject *t_Method_getExceptionTypes(t_Method *self)
252 JArray<Class> types((jobject) NULL);
254 OBJ_CALL(types = self->object.getExceptionTypes());
255 return types.toSequence(t_Class::wrap_Object);
258 static PyObject *t_Method_getDeclaringClass(t_Method *self)
260 Class cls((jobject) NULL);
262 OBJ_CALL(cls = self->object.getDeclaringClass());
263 return t_Class::wrap_Object(cls);
266 #ifdef _java_generics
267 static PyObject *t_Method_getTypeParameters(t_Method *self)
269 JArray<TypeVariable> result((jobject) NULL);
270 OBJ_CALL(result = self->object.getTypeParameters());
272 return result.toSequence(t_TypeVariable::wrap_Object);
275 static PyObject *t_Method_getGenericExceptionTypes(t_Method *self)
277 JArray<Type> result((jobject) NULL);
278 OBJ_CALL(result = self->object.getGenericExceptionTypes());
280 return result.toSequence(t_Type::wrap_Object);
283 static PyObject *t_Method_getGenericParameterTypes(t_Method *self)
285 JArray<Type> result((jobject) NULL);
286 OBJ_CALL(result = self->object.getGenericParameterTypes());
288 return result.toSequence(t_Type::wrap_Object);
291 static PyObject *t_Method_getGenericReturnType(t_Method *self)
293 Type result((jobject) NULL);
294 OBJ_CALL(result = self->object.getGenericReturnType());
296 return t_Type::wrap_Object(result);